Esempio n. 1
0
        public void Load_Data_HangNCC(string id)
        {
            HangNCCBLL capBLL = new HangNCCBLL();

            grvHangNCC.DataSource = capBLL.GetData(id);
            txtHang.Enabled       = false;
            txtDonGiaMua.Enabled  = false;
            txtIDNcc.Enabled      = false;
            txtTenMH.Enabled      = false;
        }
Esempio n. 2
0
        private void Excute_HangNCC(string query)
        {
            if (query == "insert")
            {
                try
                {
                    HangTon ht  = new HangTon();
                    HangNCC hcc = new HangNCC();
                    //mã tự động tăng
                    int count = 0;
                    count = grvHangNCC.Rows.Count; //đếm tất cả các dòng của data grv rồi gán cho count
                    string str  = "";
                    int    str2 = 0;
                    //str = Convert.ToString(grvHangTon.Rows[count - 2].Cells[0].Value);
                    str2 = Convert.ToInt32((str.Remove(0, 1)));
                    if (str2 + 1 < 10)
                    {
                        ht.IDHANG = txtHang.Text = "H00" + (str2 + 1).ToString();
                    }
                    else if (str2 + 1 < 100)
                    {
                        ht.IDHANG = txtHang.Text = "H0" + (str2 + 1).ToString();
                    }
                    //
                    ////
                    hcc.DonGiaMua = int.Parse(txtDonGiaMua.Text.Trim());
                    HangNCCBLL hangBLL = new HangNCCBLL();
                    //
                    //check xem co trung hay khong
                    if (!(hangBLL.CheckID(txtHang.Text.Trim())))
                    {
                        hangBLL.Insert(hcc);
                        MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK);
                    }
                    else
                    {
                        MessageBox.Show("Mã " + txtHang.Text.Trim() + " đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Thêm bị lỗi: " + ex.Message.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            if (query == "update")
            {
                try
                {
                    HangNCC hcc = new HangNCC();
                    hcc.DonGiaMua = int.Parse(txtDonGiaMua.Text.Trim());

                    //
                    //

                    HangNCCBLL capBLL = new HangNCCBLL();
                    capBLL.Update(hcc);

                    MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Sửa bị lỗi: " + ex.Message.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            if (query == "delete")
            {
                try
                {
                    string     id     = txtHang.Text.Trim();
                    HangNCCBLL capBLL = new HangNCCBLL();
                    capBLL.Delete(id);
                    MessageBox.Show("Đã xóa thành công:");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Không thể xóa: " + ex.Message.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }