Click here to Skip to main content
15,889,315 members
Home / Discussions / C#
   

C#

 
GeneralRe: windows mobile mouse hook Pin
umutumsu14-Mar-10 12:06
umutumsu14-Mar-10 12:06 
GeneralRe: windows mobile mouse hook Pin
#realJSOP15-Mar-10 0:13
mve#realJSOP15-Mar-10 0:13 
QuestionAccessing another application's Controls Pin
cdpace14-Mar-10 2:20
cdpace14-Mar-10 2:20 
AnswerRe: Accessing another application's Controls Pin
#realJSOP14-Mar-10 3:46
mve#realJSOP14-Mar-10 3:46 
AnswerRe: Accessing another application's Controls Pin
Ravi Bhavnani14-Mar-10 18:24
professionalRavi Bhavnani14-Mar-10 18:24 
QuestionProblem In bind DATAGRIED Pin
shahramkeyboard13-Mar-10 23:54
shahramkeyboard13-Mar-10 23:54 
AnswerRe: Problem In bind DATAGRIED PinPopular
OriginalGriff14-Mar-10 0:31
mveOriginalGriff14-Mar-10 0:31 
GeneralRe: Problem In bind DATAGRIED Pin
shahramkeyboard14-Mar-10 1:41
shahramkeyboard14-Mar-10 1:41 
My Book Business logic Layer is:
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

namespace Library_Project
{
    public class bookBL
    {
            //Book properties
            private String bookcode;
            private String bookname;
            private String shabok;
            private String nasher;
            private String motarjem;
            private String mozo;

            private bookDA bookData;

       // BUSINESS LOGIC BOOK 
       public bookBL()            
       {
         
           //Data access layer!
     
           bookData = new bookDA();

       }

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


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

                            if (this.bookname == "")
                              {
                                    throw new Exception(
                                      "لطفا نام کتاب را وارد نمایید");
                              }
                        }
                        catch(Exception e)
                        {
                              throw new Exception(e.Message.ToString());
                        }
                  }
            }
 
            /// <SUMMARY>
            /// Property ISBN (String)
            /// </SUMMARY>
            public String Shabok
            {
                  get
                  {
                        return this.shabok;
                  }
                  set
                  {
                        //could be more checkings here eg revmove ' chars
                        //change to proper case
                        //blah blah
                        this.shabok = value;
                        if (this.shabok == "")
                        {
                              throw new Exception("لطفا شابک کتاب رو وارد نمایید");
                        }
 
                  }
            }
            /// <SUMMARY>
            /// Property Nasher (String)
            /// </SUMMARY>
            public String Nasher
            {
                  get
                  {
                      return this.nasher;
                  }
                  set
                  {
                      this.nasher = value;

                      if (this.nasher == "")
                        {
                              throw new Exception("لطفا نام ناشر را وارد نمایید");
                        }
                  }
            }
            /// <SUMMARY>
            /// Property Motarjem (String)
            /// </SUMMARY>
            public String Motarjem
            {
                get
                {
                    return this.motarjem;
                }
                set
                {
                    this.motarjem = value;


                }
            }
 
            /// <SUMMARY>
            /// Property Mozoe Ketab (String)
            /// </SUMMARY>
            public String Mozo
            {
                  get
                  {
                      return this.mozo;
                  }
                  set
                  {
                      this.mozo = value;
                      if (this.mozo == "")
                        {
                              throw new Exception("لطفا موضوع کتب رو انتخاب کنید");
                        }
 
                  }
            }
 
            /// <SUMMARY>
            /// Function Add new customer. Calls 
            /// the function in Data layer.
            /// </SUMMARY>
            public void Add()
            {
                  bookData.Add(this);
            }
 
 
            /// <SUMMARY>
            /// Function Update customer details. 
            /// Calls the function in Data layer.
            /// </SUMMARY>
            public void Update() 
            {
                  bookData.Update(this);
            }
        //------------------------------------------
            public DataSet View()
            {
                DataSet dsData = null;

                dsData = bookData.View();

                return dsData;

            }

    }
}

My Data Access Layer Is :
using System;
using System.Data.SqlClient;
using System.Data;
using System.Text;

namespace Library_Project
{
    class bookDA
    {
        private SqlConnection cnn;
        //change connection string as per the 
        //folder you unzip the files
        private const string CnnStr = "Data Source=(local);Initial Catalog=Library;Integrated Security=SSPI;";
 
        //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 = "tblbooks";
        private const String book_code = "codebook";
        private const String book_name = "bookname";
        private const String book_nasher = "nasher";
        private const String book_motarjem = "motarjem";
        private const String book_shabok = "shabok";
        private const String book_mozo = "mozo";
        

        public bookDA()
        {

        }
       
        public bookDA(bookBL book)
       
        {
            // A reference of the business object class
        }
        
        //standard dataset function that adds a new customer

        public void Add(bookBL book)
        {

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

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


            //execute connection
            cmd.ExecuteNonQuery();
            
            // close connection
            CloseCnn();
            
        }
        
        //standard dataset function that updates 
        //details of a customer based on ID
        public void Update(bookBL book)
        {
            OpenCnn();
            
            String selectStr = "UPDATE " + thisTable +
                " set " + book_name + " = '" + book.Bookname + "'" +
                ", " + book_nasher + " = '" + book.Nasher + "'" +
                ", " + book_motarjem + " = '" + book.Motarjem + "'" +
                ", " + book_shabok + " = '" + book.Shabok + "'" +
                ", " + book_mozo + " = '" + book.Mozo + "'" +
                " where book_code = '" + book.Bookcode + "'";

            SqlCommand cmd = new SqlCommand(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 code_book = '" + argStr + "'";
                SqlDataAdapter da = new SqlDataAdapter(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 + "'";

                SqlDataAdapter da = new SqlDataAdapter(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 SqlConnection(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(bookBL book)
        {
            // these are the constants as 
            // set in the top of this module.
            strTable="Insert into " + thisTable;
            strFields = " (" + book_code +
            "," + book_name +
            "," + book_nasher +
            "," + book_motarjem +
            "," + book_shabok +
            "," + book_mozo + ")";
            
            //these are the attributes of the 
            //customer business object.
            strValues = " Values ( '" + book.Bookcode +
            "' , '" + book.Bookname +
            "' , '" + book.Nasher +
            "' , '" + book.Motarjem +
            "' , '" + book.Shabok +
            "' , '" + book.Mozo + "' )";

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


    }
}

I want Show Table IN datagrid
My Interface Layer is:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Rendering;

namespace Library_Project
{
    public partial class ViewInfo : Form
    {
        Boolean StatusUser;
        public ViewInfo()
        {
            InitializeComponent();
        }

        private void ViewInfo_Load(object sender, EventArgs e)
        {
            //StatusUser=false;
            if (StatusUser == false)
            {
                addbook.Enabled = false;
            }

            //----------DataGrid Book Header  & View
            //---------------------------------------
            DataSet dsDataBook = null;
            bookBL thisBook = new bookBL();
            dsDataBook = thisBook.View();
            if (dsDataBook == null)
            {
            }
            else
            {
                dataGridViewX2.DataBindings.Add(new Binding("DataSource", dsDataBook, "tblbooks"));
                dataGridViewX2.Columns[0].HeaderText = "کد کتاب";
                dataGridViewX2.Columns[1].HeaderText = "نام کتاب";
                dataGridViewX2.Columns[2].HeaderText = "ناشر";
                dataGridViewX2.Columns[3].HeaderText = "مترجم";
                dataGridViewX2.Columns[4].HeaderText = "شابک";
                dataGridViewX2.Columns[5].HeaderText = "موضوع";
                //---------TextBox Books Information
                //--------------------------------------
                try
                {
                    textBox12.DataBindings.Add(new Binding("Text", dsDataBook, "tblbooks.codebook"));
                    textBox13.DataBindings.Add(new Binding("Text", dsDataBook, "tblbooks.bookname"));
                    textBox14.DataBindings.Add(new Binding("Text", dsDataBook, "tblbooks.nasher"));
                    textBox15.DataBindings.Add(new Binding("Text", dsDataBook, "tblbooks.motarjem"));
                    textBox16.DataBindings.Add(new Binding("Text", dsDataBook, "tblbooks.shabok"));
                    textBox17.DataBindings.Add(new Binding("Text", dsDataBook, "tblbooks.mozo"));
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message.ToString());

                }
            }



        }

        private void dataGridViewX1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            textBox1.Text = dataGridViewX1.CurrentRow.Cells[0].Value.ToString();
            textBox2.Text = dataGridViewX1.CurrentRow.Cells[1].Value.ToString();
            textBox3.Text = dataGridViewX1.CurrentRow.Cells[2].Value.ToString();
            textBox4.Text = dataGridViewX1.CurrentRow.Cells[3].Value.ToString();
            textBox5.Text = dataGridViewX1.CurrentRow.Cells[4].Value.ToString();
            textBox6.Text = dataGridViewX1.CurrentRow.Cells[5].Value.ToString();
            textBox7.Text = dataGridViewX1.CurrentRow.Cells[6].Value.ToString();
            textBox8.Text = dataGridViewX1.CurrentRow.Cells[7].Value.ToString();
            textBox9.Text = dataGridViewX1.CurrentRow.Cells[8].Value.ToString();
            textBox10.Text = dataGridViewX1.CurrentRow.Cells[9].Value.ToString();

        }
    }
}

AnswerRe: Problem In bind DATAGRIED Pin
OriginalGriff14-Mar-10 2:12
mveOriginalGriff14-Mar-10 2:12 
GeneralRe: Problem In bind DATAGRIED Pin
shahramkeyboard14-Mar-10 2:56
shahramkeyboard14-Mar-10 2:56 
GeneralRe: Problem In bind DATAGRIED Pin
OriginalGriff14-Mar-10 3:05
mveOriginalGriff14-Mar-10 3:05 
GeneralRe: Problem In bind DATAGRIED Pin
Luc Pattyn14-Mar-10 3:24
sitebuilderLuc Pattyn14-Mar-10 3:24 
GeneralMessage Closed Pin
14-Mar-10 3:44
stancrm14-Mar-10 3:44 
GeneralRe: Problem In bind DATAGRIED Pin
shahramkeyboard14-Mar-10 4:31
shahramkeyboard14-Mar-10 4:31 
GeneralRe: Problem In bind DATAGRIED Pin
OriginalGriff14-Mar-10 4:51
mveOriginalGriff14-Mar-10 4:51 
GeneralRe: Problem In bind DATAGRIED Pin
shahramkeyboard14-Mar-10 7:15
shahramkeyboard14-Mar-10 7:15 
GeneralRe: Problem In bind DATAGRIED Pin
0x3c014-Mar-10 11:31
0x3c014-Mar-10 11:31 
QuestionCan You Import 1 Finished C# Project Into Another C# Project Pin
Pmarten813-Mar-10 21:26
Pmarten813-Mar-10 21:26 
AnswerRe: Can You Import 1 Finished C# Project Into Another C# Project Pin
Sandeep Mewara13-Mar-10 21:36
mveSandeep Mewara13-Mar-10 21:36 
AnswerRe: Can You Import 1 Finished C# Project Into Another C# Project Pin
OriginalGriff13-Mar-10 22:48
mveOriginalGriff13-Mar-10 22:48 
QuestionForm Header Pin
jojoba201113-Mar-10 19:30
jojoba201113-Mar-10 19:30 
AnswerRe: Form Header Pin
Kristian Sixhøj14-Mar-10 1:25
Kristian Sixhøj14-Mar-10 1:25 
Questionto draw a line parallel to the existing line Pin
v17.poornima13-Mar-10 17:56
v17.poornima13-Mar-10 17:56 
AnswerRe: to draw a line parallel to the existing line Pin
Saksida Bojan13-Mar-10 18:58
Saksida Bojan13-Mar-10 18:58 
GeneralRe: to draw a line parallel to the existing line Pin
v17.poornima14-Mar-10 18:42
v17.poornima14-Mar-10 18:42 

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.