Ejemplo n.º 1
0
        private void updateDB(bool isNewQT)
        {
            QuyTrinhBT quytrinh = new QuyTrinhBT();

            quytrinh.maQTBT       = txtMaQT.Text;
            quytrinh.tenQTBT      = txtTenQT.Text;
            quytrinh.noidungQT    = rtbNoidung.Text;
            quytrinh.tennguoiviet = cbNguoiViet.GetItemText(cbNguoiViet.SelectedItem);

            if ((txtMaQT.Text == "") || (txtTenQT.Text == "") || (cbNguoiViet.Text == ""))
            {
                MessageBox.Show(this, "Vui Long Dien Ma, TenQT Va Ten Nguoi Viet", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            DBQuyTrinhBT dbquytrinh = new DBQuyTrinhBT();

            if (isNewQT)
            {
                dbquytrinh.addnewQuyTrinh(quytrinh, false);
            }
            else
            {
                dbquytrinh.addnewQuyTrinh(quytrinh, true);
            }
            dbquytrinh.updateGridData(dataGridQuyTrinh);
        }
Ejemplo n.º 2
0
        public int addnewQuyTrinh(QuyTrinhBT quytrinh, bool isUpdate)
        {
            DataBaseManager.initializeInstance();
            DataBaseManager dbmg = DataBaseManager.getInstance();
            SqlConnection   con  = dbmg.openDatabase();

            string insertNewCmd = "INSERT QUYTRINHBAOTRI (Id, TenQuyTrinh, NguoiVietQuyTrinh, NoiDungQT) "
                                  + " VALUES (@Id,@TenQuyTrinh,@NguoiVietQuyTrinh,@NoiDungQT)";
            string updateCmd = "UPDATE QUYTRINHBAOTRI SET Id = @Id, TenQuyTrinh = @TenQuyTrinh, NguoiVietQuyTrinh = @NguoiVietQuyTrinh,"
                               + " NoiDungQT = @NoiDungQT";


            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = con;
            cmd.CommandType = CommandType.Text;
            if (!isUpdate)
            {
                cmd.CommandText = insertNewCmd;
            }
            else
            {
                cmd.CommandText = updateCmd;
            }
            //cmd.CommandText = "INSERT QUYTRINHBAOTRI (Id, TenQuyTrinh) VALUES (@maQTBT,@tenQTBT,@tennguoiviet)";
            cmd.Parameters.AddWithValue("@ID", quytrinh.maQTBT);
            cmd.Parameters.AddWithValue("@TenQuyTrinh", quytrinh.tenQTBT);
            cmd.Parameters.AddWithValue("@NguoiVietQuyTrinh", quytrinh.tennguoiviet);
            cmd.Parameters.AddWithValue("@NoiDungQT", quytrinh.noidungQT);

            int ret = -1;

            try
            {
                ret = cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Debug.WriteLine("The product name is " + e.Message);
            }

            dbmg.closeDatabase();

            return((ret > 0) ? ret : -1);
        }