private void btnLuu_Click(object sender, EventArgs e) { DM_CANLAMSAN t = LayTTCLS(); if (dieukien) { if (daoCLS.InsertCLS(t)) { MessageBox.Show("Thêm thành công"); loadCLS(); xuLyControl(false); //txtMa.Enabled = true; frm.Visible = false; resetText(); } } else { if (daoCLS.UpdateCLS(t)) { MessageBox.Show("Sửa thành công"); loadCLS(); xuLyControl(false); //txtMa.Enabled = true; frm.Visible = false; resetText(); //sua(true); } } }
public bool UpdateCLS(DM_CANLAMSAN t) { if (KiemTraNhapLieu(t)) { SqlConnection conn = new SqlConnection(connecDB.connectionStr); SqlCommand cmd = new SqlCommand("suaDM_CANLAMSAN", conn); cmd.CommandType = CommandType.StoredProcedure; //cmd.Parameters.Add("@mathuoc", SqlDbType.NVarChar, 20); //cmd.Parameters["@mathuoc"].Value = mt; cmd.Parameters.Add("@CLS_ID", SqlDbType.NVarChar, 5); cmd.Parameters.Add("@CLS_TEN", SqlDbType.NVarChar, 30); cmd.Parameters.Add("@CLS_MOTA", SqlDbType.NVarChar, 30); cmd.Parameters.Add("@CLS_DONGIA", SqlDbType.Float); cmd.Parameters["@CLS_ID"].Value = t.Id_cls; cmd.Parameters["@CLS_TEN"].Value = t.Cls_ten; cmd.Parameters["@CLS_MOTA"].Value = t.Cls_mota; cmd.Parameters["@CLS_DONGIA"].Value = t.Cls_dongia; conn.Open(); int result = cmd.ExecuteNonQuery(); conn.Close(); return(result > 0); } return(true); }
public DataTable KiemTraTrungTenThuoc(DM_CANLAMSAN t) { string query = "select * from DM_CANLAMSAN where CLS_TEN = '" + t.Cls_ten + "'"; DataTable dt = connecDB.ExecuteQuery(query); return(dt); }
public bool InsertCLS(DM_CANLAMSAN t) { if (KiemTraNhapLieu(t)) { try { SqlConnection conn = new SqlConnection(connecDB.connectionStr); SqlCommand cmd = new SqlCommand("themDM_CANLAMSAN", conn); cmd.CommandType = CommandType.StoredProcedure; //cmd.Parameters.Add("@mathuoc", SqlDbType.NVarChar, 20); //cmd.Parameters["@mathuoc"].Value = mt; cmd.Parameters.Add("@CLS_ID", SqlDbType.NVarChar, 5); cmd.Parameters.Add("@CLS_TEN", SqlDbType.NVarChar, 30); cmd.Parameters.Add("@CLS_MOTA", SqlDbType.NVarChar, 30); cmd.Parameters.Add("@CLS_DONGIA", SqlDbType.Float); cmd.Parameters["@CLS_ID"].Value = t.Id_cls; cmd.Parameters["@CLS_TEN"].Value = t.Cls_ten; cmd.Parameters["@CLS_MOTA"].Value = t.Cls_mota; cmd.Parameters["@CLS_DONGIA"].Value = t.Cls_dongia; conn.Open(); int result = cmd.ExecuteNonQuery(); conn.Close(); return(result > 0); /*string query = string.Format("Insert DM_THUOC (THUOC_ID, LT_ID, THUOC_TEN, THUOC_HDSD, THUOC_DVT, THUOC_CONGDUNG, THUOC_GIA, THUOC_TRANGTHAI) values ('{0}', '{1}', N'{2}', N'{3}', N'{4}', N'{5}', '{6}', '{7}')", * t.Id_thuoc, t.Id_lt, t.Thuoc_ten, t.Thuoc_hdsd, t.Thuoc_dvt, t.Thuoc_congdung, t.Thuoc_gia, t.Thuoc_trangthai); * int result = connecDB.ExecuteNonQuery(query); * return result > 0;*/ } catch { if (KiemTraTrungTenThuoc(t).Rows.Count == 0) { MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm không thành công do tên loại bệnh lý đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } /*if(KiemTraTrungSDT(nv).Rows.Count == 0) * { * MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); * } * else * { * MessageBox.Show("Thêm không thành công do Số điện thoại của giáo viên đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); * }*/ } } return(false); }
private DM_CANLAMSAN LayTTCLS() { string ma = txtMa.Text; string ten = txtTen.Text; string mota = txtMota.Text; float gia = float.Parse(txtGia.Text); int tt = 1; DM_CANLAMSAN cls = new DM_CANLAMSAN(ma, ten, mota, gia, tt); return(cls); }
public bool KiemTraNhapLieu(DM_CANLAMSAN t) { if (t.Id_cls.Equals("")) { MessageBox.Show("Mã cận lâm sàn không được trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } else if (t.Cls_ten.Equals("")) { MessageBox.Show("Tên cận lâm sàn không được trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } return(true); }