Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

this project is very important for me so i decided to post it here

.. with hopes it'll enable me to Draw some Experienced developers attention,

as it start to get a little too complex for my skills .

for those of you C# Asp.net web Developers, who are willing to spend some time on a really interesting project, this might be interesting for you ...

although if the above description fits your profile, and you have some free time on your hands, you might already have some solution that is close to my idea.

this project is interesting & commonly usable in almost every application that is :

  • performing CRUD operations
  • generates reports
  • and uses a Web-Based Interface

so what is it all about ?, let me summarize the key features of the project:

by implementing the following development technologies / tools :

  • client side : JavaScript / Jquery / Ajax,

  • server side : C#

  • Framework : Asp.net 4.0

  • technology: Web-forms

this application main actions are :

accessing a given SQL Server Database , while letting you choose which tables to query (mostly by using Stored Procedures)

mainly it performs CRUD operations, so as data is at first retrieved from the SQL DataBase Server, as a developer of that WebSite-application, you can control /filter and decide :

  • what control will be attached to specific data item
  • what style and other common properties will be applied to the control that will host the specified data item and more ...

and all options are being set in a practical and easy to manage interface .

as for the User Experience aspect:

  • Design
  • Performance / speed
  • reliability

all those key features was taken into account while i was at the logical design stage

the technique i'm using for posting HTTP request, when there's a need to communicate with the server is done while avoiding full page post backs ... letting the user feel as if it was a desktop aplication experience .

about the code , i think it is a problem as it is my first real project to be presented in Stack Exchange CR and my code spreads upon few files having said that, i will be more than happy to reply to your requests and suggestions , as to what sections of the code i should post here ? .

update

as i was asking about what sections of the code i didn't specify the options

there's a file i'm using to store every new feature/ idea i come up with

that way, every helper method is stored in classes that are within namespace, that is related to the subject namespaces are

DB :

Database Related Methods commonly used ..

for example a helper for assignment of an int fetched from database

    public static class GetTableData
    {


        // the main entrance  to database - serves the next 5 methods for that class
        public static int ExecSQLint(string TblintSQL)
        {

            int value;
            SqlConnection Conn = new SqlConnection("server=(local);Initial Catalog=****DatabaseName***;Integrated Security=True");
            SqlCommand TblintCMD = new SqlCommand(TblintSQL, Conn);

            try
            {
                Conn.Open();
                value = Convert.ToInt32(TblintCMD.ExecuteScalar());

            }
            finally
            {

                Conn.Close();
            }


            return value;

        }

        // 3 ways to query an int as the retured value
        public static int AsInt(string FieldToSearch, string tblName, string WhereFldName, string WhereFLdValue)
        {

            string TblintSQL = "SELECT " + FieldToSearch + " FROM " + tblName + " WHERE " + WhereFldName + " ='" + WhereFLdValue + "'";
            return ExecSQLint(TblintSQL);
        }

        public static int AsInt(string FieldToSearch, string tblName, string LedermanWhereStr)
        {

            string TblintSQL = "SELECT " + FieldToSearch + " FROM " + tblName + " WHERE " + LedermanWhereStr;
            return ExecSQLint(TblintSQL);

        }

        public static int AsInt(string FieldToSearch, string tblName, string WhereFldName, int WhereFLdValue)
        {

            string TblintSQL = "SELECT " + FieldToSearch + " FROM " + tblName + " WHERE " + WhereFldName + " =" + WhereFLdValue;
            return ExecSQLint(TblintSQL);
        }

        // 2 ways to get a count of total rows 
        public static int CountTotalRows(string FieldToCount, string tblName)
        {
            string CountSQLRows = string.Format("SELECT COUNT({0}) AS TotalRowsIN{0} FROM {1}", FieldToCount, tblName);
            return ExecSQLint(CountSQLRows);
        }
        public static int CountTotalRows(string FieldToCount, string tblName, string whereFieldName, string HasValue)
        {

            string CountSQLRows = string.Format("SELECT COUNT({0}) FROM {1} where {2} = '{3}'", FieldToCount, tblName, whereFieldName, HasValue);
            return ExecSQLint(CountSQLRows);
        }
}

Tests/debug :

Session, Query-strings and Form Requests-variables

and also performance testing methods.

custom extensions :

lately... as i learned how to write my own custom extension methods i started to move some of my static methods here, not all of them, only those who i see fit to the approach.

util :

a Generic-purpose namespace for

converters (int to string and such )

code behind javascript injection helper class

and most important one, for the project in subject :

controlsInteraction class, which is responsible for data extraction such as DataTable , DropDownList etc' and also contains the key element for the project:

DBMetaDetails:

this class is dealing with the management of the SQL Database interaction,

it has the contractors that are helping me to put a kinda template-struct that is a set of variables which Is needed to be assigned by * required-values for current(and every new)project

(these are crucial items of the project)

...so that way i will be more oriented with the projects base settings, and requirements.

so in short, it brings management and mostly ORDER into the projects data, and variables.

style

hides /shows, and also modify style of html controls (using css style properties)

ajax

( mainly used for TextBox autoComplete methods) at least for now-it has both datasources: custom List<string> & sql database - web methods

dates

anything to do with Dates , iteration on a collection of months , printing your localized dayInWeek and more...of that kind.

i am trying to add more tools into that file, with every new trick/method/small inovation etc' so this file is related to this project

though as it is not intayerly related, it has some irrelevant classes .

another separated cs file i was almost forgeting to mention, is holding :

database table-names

column names

stored procedure names and it's parameters.

(for each of the stored procedure there's a class that stores it's parameters(names) as constant strings so does every sql databse table.

(i call its content DbMetaData- as my vocablery is not the reachest that you can have...)

so those are few namespaces that holds some commonly used classes to help in future projects

so i guess i should upload only those classes that i'm currently using with this project

ok then , i will filter the file from un related code

but still this is a 2-3 k lines file so i guess i could reduce the size to ~1k lines...

Last but not least

the current project -code behind main projects classes and methods .

sections i think of copying over here as i start upload code: and also this is how it is formed from first to last by appearance 1) session variables management:

stores the related information about the current session, so it could be saved if needed, and to pass data to next session .. obvious, though i did not really implement it so far.

the idea was there mostly because i had plans to work with data to be be cached -locally, only... the key idea was to do it gradually

as some advanced server controls software company implements same idea and they call it - "on demand").

how it should work ?

for every online-database request, i will save extracted data, and monitor further data requests...

so if the user repeats his queries, next time i will be extracted from the session variables, one of them being a DataSet - that is responsible for storing the current project -DataTables... as a set - into memory.

eventually... because there was no time to play around with this (at least not for now)

i haven't used it so far besides the testing and management of the idea to put it into control via a struct , so it's kinda ready to be used!.

2)

then , how to categorize and devide the project :

theres a section that is responsible for the

1)data retrival

2)generating html according to database information e.g. # of rows to render

what contols to put in every column (+ ) or button after last column so this is for the row in each content of column do- for example a text box

<input type="text" id={0} attribut3={1} attribute4={2}... etc'

for now i will show the first code which is easy to copy and past over here and would not look bad

starting from the client side code

the main function to be invoked upon user interaction with the controls

    function UbpdateTblCPA(TBX, TableID) {

        var TBX_ID = TBX.id; var TBX_ID_PARTS = TBX_ID.split("_");
        var CurrentColumn = TBX_ID_PARTS[0]; var recNumSplited = TBX_ID_PARTS[1];
        var newValue = TBX.value;
        var oldValue = TBX.defaultValue;
        if (recNumSplited == "") {
            alert("this entry does not exist ther for could not be edited"); // tell the client that this field neded to be created first than it could be edited
// could be = should be replaced with better notification approach than a simple alert (i am not at this stage yet...still buisy with the engins not the door knobs)
            TBX.value = oldValue;
            return;
        }
        var err = false;
        var containsDots = (newValue.indexOf(":") == -1);
        if (!containsDots || newValue.length < 0) err = true;

        if (err) {
            alert("wrong value the update will not take place");
            // actualy i already taken care of that , validation won't be  handled by this function
even not the next line cause i've changed the whole 'deal' with the validation part
            elm.value = oldValue;
        } else {

            CpaAjxUpdt(CurrentColumn, recNumSplited, newValue, TBX, "UpdateUserID", TableID);

        }
    }



    ////////////////////////////////////////////////
    /////////don't forget to Set POSTs - Url address !!!!!!!!!<<<<<<<<<<<<<<<<<
    ////////////////////////////////////////////////
                                                                  // columnName-Update
    function CpaAjxUpdt(CurrentColumn, recNumSplited, newValue, TBX, ActionRequest, TableID) {
        $.ajax({
              type: 'POST',
              url: 'Default.aspx',
              data: {
                  'PostSentByAjax': "true",
                  'TargetTableId': TableID,
                  'CurrentColumn': CurrentColumn,
                  'recNumSplited': recNumSplited,
                  'value': newValue,
                  'ActionRequest': ActionRequest
             },
             success: function (data) {
                //alert(data);
                  var FinesID = "Fines_" + recNumSplited.toString();
                  var finsTBX = document.getElementById(FinesID);
                  if (ActionRequest == "UpdateUserID") {
                      //TBX.setAttribute("defaultValue", newValue);
                      alert(finsTBX.defaultValue);
                      finsTBX.defaultValue += newValue;
                  }
             }

        });
    }
    function onlN(evt) {

        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
            return false;
        return true;
    }

some more i would like to say :

i know it is not anything new, and i did not invent the wheel or the first flying machine , i assume existing websites already implementing those technologies.

i was working more on the server side section and i like to program in C#

i would like to emphasize what already said at the beginning of the post:

this project is going to be included almost in every application *database related, that i will create.

it only one of few reasons that i'm here, in stack exchange CR with hope it will teach me how to perfect / polish my development capabilities.

.. so i'd really like to say, that it's all up to you, and only with this community, and the good spirit of people (i have the opportunity to meet here... that wasn't an option a decade ago), who are willing to offer their help with their experience so i really appreciate that fact.

share|improve this question
1  
Have you ever considered a career in marketing? – MattDavey May 7 at 18:19

1 Answer

In last year i working with similiar project. Our team used other way: we returned all query results as xml and applied xslt to them for getting html markup (chart, silverlight table or simple html). We used 3 entities:

1)query

2)xslt for prepare xml query result for render(make json ,specific xml for chart or javascript control)

3)xslt for render prepared query result as html block

Now some fixes to your code:

I recomend you working with interfaces instead of static classes. When you working with interfaces you can simply change class with interface implementaion( more info http://en.wikipedia.org/wiki/Dependency_injection).

Example:

interface IDBRepository
{
    int ExecuteScalar(string sql);
}

class SQLRepositry : IDBRepository
{
    private string _connStr;

    public SQLRepositry(string connStr)
    {
        _connStr = connStr;
    }

    public int ExecuteScalar(string sql)
    {
        int value;

        using(SqlConnection conn=new SqlConnection(_connStr))
        {
            SqlCommand command = new SqlCommand(sql, conn);
            conn.Open();
            value = Convert.ToInt32(command.ExecuteScalar());

        }


        return value;
    }
}

When you generate sql statments from user input important to use SqlCommand.Parameters (more info http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx ) or you can get sql injection (more info http://msdn.microsoft.com/en-us/library/ms161953%28v=sql.100%29.aspx).

And easy for edit storing sql quries into xml file or database and create method to get them by aliases.

share|improve this answer
hey frank , i moved to using statment in general.. (this is some un polished example the move was not so long ago as.. i was questioning difference tryCatch Vs using .so this is my main helper Db namespace codes ..while in my project, right now its done via using.. though main issue here is parameters - also that was changed ( with parameters and stored procedures)dedicated classes from DbSchema (my database-meta dedicated namespace), so what i do need to lear to your suggestion , is the inteface which is unfamiliar zone for me – LoneXcoder Dec 8 '12 at 16:46
1  
Although I agree using interfaces is a good approach I don't think your example gives the benefit you describe. The fact you have to pass in raw SQL to the ExecuteScalar method immediately ties that interface to the command query language of the database of choice. – dreza Dec 9 '12 at 1:18
@dreza as this is getting to large as one subject , in my profile you will sew that i am still working hard (: , to perfect it , see my next post – LoneXcoder Dec 9 '12 at 17:48
It would be more useful to expose your operations on the interface as taking in just the parameters and returning expected value types. The SQL used would then be encapsulated within your repository implementations, where you already have specific knowledge about which database engine you are going to use. You would have the added benefit of using method names that tell you what is happening. For example you could use int GetEmployeeID(string name) rather than int ExecuteSQL(string sql). – Dan Lyons Feb 6 at 18:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.