Exemple #1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     Model.Producer u = new Model.Producer(txtID.Text, txtName.Text, txtAdd.Text, txtPhone.Text);
     if (Controller.Connector.updateProducer(u))
     {
         MessageBox.Show("Sửa thành công nhà cung cấp " + txtID.Text, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         MessageBox.Show("Sửa lỗi " + txtID.Text, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     this.Close();
 }
        public static bool updateProducer(Model.Producer _p)
        {
            try {
                openConnection();


                // Them don vi
                string        strCmd   = string.Format("UPDATE NSX set TENNSX = N'{0}', DIACHI = N'{1}', SDT = '{2}' where MANSX = '{3}'", _p.Name, _p.Add, _p.Phone, _p.IdString);
                SqlCommand    myCmd    = new SqlCommand(strCmd, conn);
                SqlDataReader myReader = myCmd.ExecuteReader();

                conn.Close();
                conn.Dispose();
                return(true);
            }
            catch (Exception ex) {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                conn.Close();
                conn.Dispose();
                return(false);
            }
        }
        public static bool insertProducer(Model.Producer _p)
        {
            try {
                openConnection();


                // Them don vi
                string        strCmd   = string.Format("INSERT INTO NSX VALUES('{0}', N'{1}', N'{2}', '{3}')", _p.IdString, _p.Name, _p.Add, _p.Phone);
                SqlCommand    myCmd    = new SqlCommand(strCmd, conn);
                SqlDataReader myReader = myCmd.ExecuteReader();

                conn.Close();
                conn.Dispose();
                return(true);
            }
            catch (Exception ex) {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                conn.Close();
                conn.Dispose();
                return(false);
            }
        }