示例#1
0
        private void btnsave_Click(object sender, EventArgs e)
        {
            if (txtsankayname.Text == "")
            {
                MessageBox.Show("Null Value Not Allowed");
            }

            else
            {//c.datasave("tbl_school", c.myconn, this);
                if (add_edit == true)
                {
                    c.returnconn(c.myconn);
                    SqlCommand command = new SqlCommand("select max(publishcode) from tbl_publisher", c.myconn);
                    command.CommandTimeout = 120;
                    Int32 mstudentno;
                    mstudentno = 1001;
                    if (command.ExecuteScalar() != System.DBNull.Value)
                    {
                        mstudentno = Convert.ToInt32(command.ExecuteScalar()) + 1;
                    }
                    DataSet ds = Connection.GetDataSet("select count(* ) from tbl_publisher where publishar='" + txtsankayname.Text + "'");
                    int     i  = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                    if (i == 0)
                    {
                        txtsankaycode.Text = mstudentno.ToString();
                        c.insertdata("tbl_publisher", c.myconn, this);
                        c.FillListBox("select * from tbl_publisher", "publishar", "publishcode", ref listBox1);
                    }
                    else
                    {
                        MessageBox.Show("Duplicate data not allowed");
                    }
                }
                if (add_edit == false)
                {
                    c.updatedata("tbl_publisher", c.myconn, this, "publishcode", txtsankaycode.Text);
                    c.FillListBox("select * from tbl_publisher", "publishar", "publishcode", ref listBox1);
                }
                MessageBox.Show("Record Saved...", "School");
                c.btnenable(btnnew, btnedit, btndelete, btnsave, btncancel, btnprint, btnexit);
                btnnew.Focus();
            }
        }