private void btnLuu_Click(object sender, EventArgs e)
        {
            string _MaPM = txtmapm.Text.Trim();
            string _MaDG = cbmadg.Text.Trim();

            string ngaymuon = datenm.Value.ToShortDateString();
            string hentra   = datent.Value.ToShortDateString();
            string _MaNV_GD = cbomanv.Text.Trim();

            MuonTra.MuonTra_BUS a = new MuonTra.MuonTra_BUS();
            a.MaPM = _MaPM;
            a.MaDG = _MaDG;

            a.Ngaymuon = ngaymuon;
            a.Hentra   = hentra;
            a.MaNV_GD  = _MaNV_GD;

            if (kt == true)
            {
                if (txtmapm.TextLength == 0)
                {
                    MessageBox.Show("Chưa điền mã phiếu mượn.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                else
                {
                    try
                    {
                        MuonTra.MuonTra_DAL n = new MuonTra.MuonTra_DAL();
                        n.them_pm(a);
                        showLsvMuonTra();
                        lockControl();
                        clearControl();
                    }
                    catch (SqlException loi)
                    {
                        if (loi.Message.Contains("Violation of PRIMARY KEY constraint 'PK_MuonTra_2725E7FFF7FDA83E'"))
                        {
                            MessageBox.Show("Mã phiếu mượn bị trùng.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            else if (kt == false)
            {
                if (txtmapm.TextLength == 0)
                {
                    MessageBox.Show("Chưa điền mã phiếu mượn.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                else
                {
                    MuonTra.MuonTra_DAL n = new MuonTra.MuonTra_DAL();
                    n.sua_pm(a);
                    showLsvMuonTra();
                    lockControl();
                    clearControl();
                }
            }
        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DialogResult check = MessageBox.Show("Bạn có muốn xóa không", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (check == DialogResult.Yes)
            {
                MuonTra.MuonTra_BUS n = new MuonTra.MuonTra_BUS();
                n.MaPM = txtmapm.Text.Trim();
                MuonTra.MuonTra_DAL a = new MuonTra.MuonTra_DAL();
                a.xoa_pm(n);
            }
            showLsvMuonTra();
            lockControl();
            clearControl();
        }
Example #3
0
 public void xoa_pm(MuonTra_BUS mt)
 {
     try
     {
         openConnection();
         SqlCommand cmd = new SqlCommand("Xoa_phieumuon", Conn);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@Mapm", mt.MaPM);
         cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         new Exception("Error: " + ex.Message);
     }
     finally
     {
         closeConnection();
     }
 }
Example #4
0
 public void them_pm(MuonTra_BUS mt)
 {
     try
     {
         openConnection();
         SqlCommand cmd = new SqlCommand("Them_phieumuon", Conn);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@Mapm", mt.MaPM);
         cmd.Parameters.AddWithValue("@Madg", mt.MaDG);
         cmd.Parameters.AddWithValue("@Ngaymuon", mt.Ngaymuon);
         cmd.Parameters.AddWithValue("@Hentra", mt.Hentra);
         cmd.Parameters.AddWithValue("@Manv", mt.MaNV_GD);
         cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         new Exception("Error: " + ex.Message);
     }
     finally
     {
         closeConnection();
     }
 }