Click here to Skip to main content
15,899,937 members
Home / Discussions / C#
   

C#

 
AnswerRe: Return Dataset to Business Layer & SHOW in datagrid in Presentation Layer Pin
shahramkeyboard20-Feb-10 21:07
shahramkeyboard20-Feb-10 21:07 
GeneralRe: Return Dataset to Business Layer & SHOW in datagrid in Presentation Layer Pin
Dan Mos20-Feb-10 21:23
Dan Mos20-Feb-10 21:23 
GeneralRe: Return Dataset to Business Layer & SHOW in datagrid in Presentation Layer Pin
shahramkeyboard20-Feb-10 21:55
shahramkeyboard20-Feb-10 21:55 
GeneralDoes this help? Pin
Dan Mos20-Feb-10 22:25
Dan Mos20-Feb-10 22:25 
GeneralRe: Does this help? Pin
shahramkeyboard21-Feb-10 1:46
shahramkeyboard21-Feb-10 1:46 
GeneralRe: Does this help? [modified] Pin
Dan Mos21-Feb-10 16:27
Dan Mos21-Feb-10 16:27 
AnswerRe: Return Dataset to Business Layer & SHOW in datagrid in Presentation Layer Pin
dan!sh 20-Feb-10 23:33
professional dan!sh 20-Feb-10 23:33 
GeneralRe: Return Dataset to Business Layer & SHOW in datagrid in Presentation Layer [modified] Pin
shahramkeyboard21-Feb-10 2:30
shahramkeyboard21-Feb-10 2:30 
My Business Lyaer Is:
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Text;
using System.Data;

namespace Library_Project
{
    class memberBL
    {
                    //Book properties
            private String membercode;
            private String name;
            private String family;
            private String shsh;
            private String melicode;
            private String tavalod;
            private String shoghl;
            private String tel;
            private String mobile;
            private String adr;
            private String trkhozv;

            private memberDA memberData;

       // BUSINESS LOGIC Member 
       public memberBL()            
       {
         
           //Data access layer!
     
           memberData = new memberDA();

       }
       /// <SUMMARY>
       /// Property BookCode (String)
       /// </SUMMARY>
       public String Membercode
       {
           get
           {
               return this.membercode;
           }
           set
           {
               this.membercode = value;


           }
       }
 
            /// <SUMMARY>
            /// Property BooktName (String)
            /// </SUMMARY>
            public String Name 
            {
      
                  get
                  {
                      return this.name;
                  }
                  set
                  {
                        try
                        {
                            this.name = value;

                            if (this.name == "")
                              {
                                    throw new Exception(
                                      "لطفا نام عضو را وارد نمایید");
                              }
                        }
                        catch(Exception e)
                        {
                              throw new Exception(e.Message.ToString());
                        }
                  }
            }
 
            /// <SUMMARY>
            /// Property ISBN (String)
            /// </SUMMARY>
            public String Familly
            {
                  get
                  {
                        return this.family;
                  }
                  set
                  {
                        //could be more checkings here eg revmove ' chars
                        //change to proper case
                        //blah blah
                        this.family = value;
                        if (this.family == "")
                        {
                              throw new Exception("لطفا نام خانوادگی عضو رو وارد نمایید");
                        }
 
                  }
            }

            /// <SUMMARY>
            /// Property Nasher (String)
            /// </SUMMARY>
            public String Shsh
            {
                  get
                  {
                      return this.shsh;
                  }
                  set
                  {
                      this.shsh = value;

                      if (this.shsh == "")
                        {
                              throw new Exception("لطفا شماره شناسنامه را وارد نمایید");
                        }
                  }
            }
            /// <SUMMARY>
            /// Property ISBN (String)
            /// </SUMMARY>
            public String Melicode
            {
                  get
                  {
                        return this.melicode;
                  }
                  set
                  {
                        //could be more checkings here eg revmove ' chars
                        //change to proper case
                        //blah blah
                        this.melicode = value;
                        if (this.melicode == "")
                        {
                              throw new Exception("لطفا کد ملی عضو رو وارد نمایید");
                        }
 
                  }
            }
            /// <SUMMARY>
            /// Property Nasher (String)
            /// </SUMMARY>
            public String Tavalod
            {
                  get
                  {
                      return this.tavalod;
                  }
                  set
                  {
                      this.tavalod = value;

                      if (this.tavalod == "")
                        {
                              throw new Exception("لطفا تاریخ تولد رو وارد نمایید");
                        }
                  }
            }

 
            /// <SUMMARY>
            /// Property Mozoe Ketab (String)
            /// </SUMMARY>
            public String Shoghl
            {
                  get
                  {
                      return this.shoghl;
                  }
                  set
                  {
                      this.shoghl = value;
                      if (this.shoghl == "")
                        {
                              throw new Exception("لطفا شغل رو انتخاب کنید");
                        }
 
                  }
            }
            /// <SUMMARY>
            /// Property Mozoe Ketab (String)
            /// </SUMMARY>
            public String Tel
            {
                  get
                  {
                      return this.tel;
                  }
                  set
                  {
                      this.tel = value;
                      if (this.tel == "")
                        {
                            throw new Exception("لطفا شماره  تلفن را وارد نمایید ");
                        }
 
                  }
            }
            /// <SUMMARY>
            /// Property Mozoe Ketab (String)
            /// </SUMMARY>
            public String Mobile
            {
                  get
                  {
                      return this.mobile;
                  }
                  set
                  {
                      this.mobile = value;
                      if (this.mobile == "")
                        {
                            throw new Exception("لطفا شماره موبایل را وارد نمایید ");
                        }
 
                  }
            }
            /// <SUMMARY>
            /// Property Mozoe Ketab (String)
            /// </SUMMARY>
            public String Adr
            {
                  get
                  {
                      return this.adr;
                  }
                  set
                  {
                      this.adr = value;
                      if (this.adr == "")
                        {
                            throw new Exception("لطفا آدرس را وارد نمایید");
                        }
 
                  }
            }
            /// <SUMMARY>
            /// Property Mozoe Ketab (String)
            /// </SUMMARY>
            public String Trkhozv
            {
                get
                {
                    return this.trkhozv;
                }
                set
                {
                    this.trkhozv = value;


                }
            }
            /// <SUMMARY>
            /// Function Add new customer. Calls 
            /// the function in Data layer.
            /// </SUMMARY>
            public void Add()
            {
                  memberData.Add(this);
            }
 
 
            /// <SUMMARY>
            /// Function Update customer details. 
            /// Calls the function in Data layer.
            /// </SUMMARY>
            public void Update()
            {
                memberData.Update(this);
            }

            /// <SUMMARY>
            /// Function View Member details. 
            /// Calls the function in Data layer.
            /// </SUMMARY>
            ///  
         
    }
}

& My Data Layer Is:
using System;
using System.Data.OleDb;
using System.Data;
using System.Text;

namespace Library_Project
{
    class memberDA
    {
        private OleDbConnection cnn;
        //change connection string as per the 
        //folder you unzip the files
        private const string CnnStr = 
          "Provider=Microsoft.Jet.OLEDB.4.0;Data " +
          "Source= D:\\Data\\Library.mdb;"; 
            
        //local variables
        private String strTable="";
        private String strFields="";
        private String strValues="";
        private String insertStr="";
        
        //this needs to be changed based on Books 
        //table fields' Name of the database!
        private const String thisTable = "tblmembers";
        private const String member_code = "membercode";
        private const String member_name = "name";
        private const String member_family = "family";
        private const String member_shsh = "shsh";
        private const String member_melicode = "melicode";
        private const String member_tavalod = "tavalod";
        private const String member_shoghl = "shoghl";
        private const String member_tel = "tel";
        private const String member_mobile = "mobile";
        private const String member_adr = "adr";
        private const String member_trkhozv = "trkhozv";
        private memberBL memberLogic;

        public memberDA()
        {
           
        }

        public memberDA(memberBL member)
       
        {
            // A reference of the business object class
            memberLogic = new memberBL();
        }
        
        //standard dataset function that adds a new customer

        public void Add(memberBL member)
        {

            String str = BuildAddString(member);
            
            OpenCnn();

            //Open command option - cnn parameter is imporant
            OleDbCommand cmd = new OleDbCommand(str,cnn);


            //execute connection
            cmd.ExecuteNonQuery();
            
            // close connection
            CloseCnn();
            
        }
        
        //standard dataset function that updates 
        //details of a customer based on ID
        public void Update(memberBL member)
        {
            OpenCnn();
            
            String selectStr = "UPDATE " + thisTable +
                " set " + member_name + " = '" + member.Name + "'" +
                ", " + member_family + " = '" + member.Familly + "'" +
                ", " + member_shsh + " = '" + member.Shsh + "'" +
                ", " + member_melicode + " = '" + member.Melicode + "'" +
                ", " + member_tavalod + " = '" + member.Tavalod + "'" +
                ", " + member_shoghl + " = '" + member.Shoghl + "'" +
                ", " + member_tel + " = '" + member.Tel + "'" +
                ", " + member_mobile + " = '" + member.Mobile + "'" +
                ", " + member_adr + " = '" + member.Adr + "'" +
                " where member_code = '" + member.Membercode  + "'";

            OleDbCommand cmd = new OleDbCommand(selectStr,cnn);

            cmd.ExecuteNonQuery();
            
            CloseCnn();
        }
        
        //standard dataset function that finds and 
        //return the detail of a customer in a dataset
        public DataSet Find(String argStr)
        {
            DataSet ds=null;

            try
            {
                OpenCnn();
            
                String selectStr = "select * from " + thisTable + 
                              " where member_code = '" + argStr + "'";
                OleDbDataAdapter da = 
                       new OleDbDataAdapter(selectStr,cnn);
                ds = new DataSet();
                da.Fill(ds,thisTable);
            
                CloseCnn();

                
            }
            catch(Exception e)
            {
                String Str = e.Message;
            }

            return ds;
        }

        //standard dataset function that finds and 
        //return the detail of a customer in a dataset
        public DataSet View()
        {
            DataSet ds = null;

            try
            {
                OpenCnn();
                
                String selectStr = "select * from " + thisTable + "'";
                
                OleDbDataAdapter da =new OleDbDataAdapter(selectStr, cnn);
                
                ds = new DataSet();
                
                da.Fill(ds, thisTable);
                
                CloseCnn();
            }
            catch (Exception e)
            {
                String Str = e.Message;
            }

            return ds;
        }

        private void OpenCnn()
        {
            // initialise connection
            String cnnStr = CnnStr;
            cnn = new OleDbConnection(cnnStr);
            // open connection
            cnn.Open();
        }

        private void CloseCnn()
        {
            // 5- step five
            cnn.Close();
        }
        
        // just a supporting function that builds 
        // and return the insert string for dataset.
        private String BuildAddString(memberBL member)
        {
            // these are the constants as 
            // set in the top of this module.
            strTable="Insert into " + thisTable;
            strFields = " (" + member_code +
            "," + member_name +
            "," + member_family +
            "," + member_shsh +
            "," + member_melicode +
            "," + member_tavalod +
            "," + member_shoghl +
            "," + member_tel +
            "," + member_mobile +
            "," + member_adr +
            "," + member_trkhozv + ")";
            
            //these are the attributes of the 
            //customer business object.
            strValues = " Values ( '" + member.Membercode +
            "' , '" + member.Name +
            "' , '" + member.Familly +
            "' , '" + member.Shsh +
            "' , '" + member.Melicode +
            "' , '" + member.Tavalod +
            "' , '" + member.Shoghl +
            "' , '" + member.Tel +
            "' , '" + member.Mobile +
            "' , '" + member.Adr +
            "' , '" + member.Trkhozv + "' )";

            insertStr = strTable + strFields + strValues;
            
            return insertStr;
            
        }

    }
}

How ds trasnsfer to Business Layer & Then View in form
modified on Sunday, February 21, 2010 9:44 AM

GeneralRe: Return Dataset to Business Layer & SHOW in datagrid in Presentation Layer Pin
shahramkeyboard21-Feb-10 6:32
shahramkeyboard21-Feb-10 6:32 
Questiona problem about "bool Exists(Predicate<T> match);" Pin
wjp_auhtm20-Feb-10 19:35
wjp_auhtm20-Feb-10 19:35 
AnswerRe: a problem about "bool Exists(Predicate match);" Pin
dan!sh 20-Feb-10 20:25
professional dan!sh 20-Feb-10 20:25 
GeneralRe: a problem about "bool Exists(Predicate match);" Pin
wjp_auhtm20-Feb-10 22:09
wjp_auhtm20-Feb-10 22:09 
GeneralRe: a problem about "bool Exists(Predicate match);" Pin
Abhinav S20-Feb-10 22:42
Abhinav S20-Feb-10 22:42 
GeneralRe: a problem about "bool Exists(Predicate match);" Pin
wjp_auhtm25-Feb-10 1:40
wjp_auhtm25-Feb-10 1:40 
GeneralRe: a problem about "bool Exists(Predicate match);" Pin
dan!sh 20-Feb-10 23:29
professional dan!sh 20-Feb-10 23:29 
GeneralRe: a problem about "bool Exists(Predicate match);" Pin
wjp_auhtm25-Feb-10 1:39
wjp_auhtm25-Feb-10 1:39 
GeneralRe: a problem about "bool Exists(Predicate match);" Pin
harold aptroot20-Feb-10 23:05
harold aptroot20-Feb-10 23:05 
GeneralRe: a problem about "bool Exists(Predicate match);" Pin
wjp_auhtm25-Feb-10 1:41
wjp_auhtm25-Feb-10 1:41 
AnswerRe: a problem about "bool Exists(Predicate match);" Pin
Daniel Grunwald21-Feb-10 1:37
Daniel Grunwald21-Feb-10 1:37 
GeneralRe: a problem about "bool Exists(Predicate match);" Pin
wjp_auhtm25-Feb-10 1:44
wjp_auhtm25-Feb-10 1:44 
QuestionInserting an image in Crystal Reports??? Pin
Muammar©20-Feb-10 19:12
Muammar©20-Feb-10 19:12 
QuestionC# tools. Pin
Subin Mavunkal20-Feb-10 18:58
Subin Mavunkal20-Feb-10 18:58 
AnswerRe: C# tools. Pin
Rutvik Dave20-Feb-10 20:02
professionalRutvik Dave20-Feb-10 20:02 
AnswerRe: C# tools. Pin
Eddy Vluggen21-Feb-10 1:50
professionalEddy Vluggen21-Feb-10 1:50 
Questionam I missing a setting here or what (DataGrid not showing but one row) Pin
tonyonlinux20-Feb-10 9:45
tonyonlinux20-Feb-10 9:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.