Exemple #1
0
        private void uc_InInvenCreate_Load(object sender, EventArgs e)
        {
            try
            {
                PhieuNhapClient client = new PhieuNhapClient();
                DataTable       dtb    = new DataTable();
                dtb.Columns.Add("MaSanPham");
                dtb.Columns.Add("SoLuong");
                dtb.Columns.Add("DonGia");
                if (string.IsNullOrEmpty(pn.MaPhieuNhap))//Insert
                {
                    txt_MaPhieuNhap.Text    = client.PhieuNhap_GetNewID(DateTime.Today.Year, DateTime.Today.Month);
                    txt_MaPhieuNhap.Enabled = false;
                    txt_TongTien.Text       = "0";
                    txt_TongTien.Enabled    = false;
                    LoadMaNhanVien();
                    LoadSanPham();
                    dgv_DanhSachChiTiet.DataSource = dtb;
                }
                else//Update or Detail
                {
                    txt_MaPhieuNhap.Text    = pn.MaPhieuNhap;
                    txt_MaPhieuNhap.Enabled = false;
                    msk_NgayNhap.Text       = pn.NgayNhap.ToString("dd/MM/yyyy");
                    txt_NhanVien.Text       = pn.MaNhanVien.ToString();
                    txt_TongTien.Text       = pn.TongTien.ToString("#,##");
                    txt_TongTien.Enabled    = false;
                    foreach (PhieuNhapCT ct in pn.DSChiTiet)
                    {
                        DataRow row = dtb.NewRow();
                        row["MaSanPham"] = ct.MaSanPham;
                        row["SoLuong"]   = ct.SoLuong;
                        row["DonGia"]    = ct.DonGia.ToString("#,##");
                        dtb.Rows.Add(row);
                    }
                    dgv_DanhSachChiTiet.DataSource = dtb;
                    if (IsInsertOrUpdate)
                    {
                        msk_NgayNhap.Enabled   = false;
                        txt_NhanVien.Enabled   = false;
                        btn_AddProduct.Visible = false;
                        btn_Luu.Visible        = false;

                        txt_MaSanPham.Enabled  = false;
                        txt_TenSanPham.Enabled = false;
                        txt_DonGia.Enabled     = false;
                        txt_SoLuong.Enabled    = false;
                        dgv_DanhSachChiTiet.Columns["Delete"].Visible = false;
                    }
                    LoadMaNhanVien();
                    LoadSanPham();
                    FormatGrid();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
 //Nút lưu
 private void btn_Luu_Click(object sender, EventArgs e)
 {
     try
     {
         PhieuNhapClient client = new PhieuNhapClient();
         PhieuNhap       pn     = new PhieuNhap();
         pn.MaPhieuNhap = txt_MaPhieuNhap.Text;
         pn.NgayNhap    = Convert.ToDateTime(msk_NgayNhap.Text);
         pn.MaNhanVien  = txt_NhanVien.Text;
         pn.TongTien    = Convert.ToDecimal(txt_TongTien.Text);
         List <PhieuNhapCT> dsct = new List <PhieuNhapCT>();
         foreach (DataGridViewRow row in dgv_DanhSachChiTiet.Rows)
         {
             PhieuNhapCT ct = new PhieuNhapCT();
             ct.MaPhieuNhap = txt_MaPhieuNhap.Text;
             ct.MaSanPham   = row.Cells["MaSanPham"].Value.ToString();
             ct.SoLuong     = Convert.ToInt32(row.Cells["SoLuong"].Value);
             ct.DonGia      = Convert.ToDecimal(row.Cells["DonGia"].Value);
             dsct.Add(ct);
         }
         pn.DSChiTiet = dsct.ToArray();
         if (IsInsertOrUpdate && !Checknull())
         {
             if (client.PhieuNhap_Insert(pn))
             {
                 MessageBox.Show("Thêm phiếu nhập thành công");
                 DataTable dtb = new DataTable();
                 dtb.Columns.Add("MaSanPham");
                 dtb.Columns.Add("SoLuong");
                 dtb.Columns.Add("DonGia");
                 txt_MaPhieuNhap.Text    = client.PhieuNhap_GetNewID(DateTime.Today.Year, DateTime.Today.Month);
                 txt_MaPhieuNhap.Enabled = false;
                 txt_NhanVien.Text       = "";
                 msk_NgayNhap.Text       = "";
                 txt_TongTien.Text       = "0";
                 txt_TongTien.Enabled    = false;
                 txt_MaSanPham.Text      = "";
                 txt_TenSanPham.Text     = "";
                 txt_SoLuong.Text        = "";
                 txt_DonGia.Text         = "";
                 LoadMaNhanVien();
                 LoadSanPham();
                 dgv_DanhSachChiTiet.DataSource = dtb;
             }
             else
             {
                 MessageBox.Show("Thêm phiếu nhập thất bại");
             }
         }
         else if (!IsInsertOrUpdate && !Checknull())
         {
             if (client.PhieuNhap_Update(pn))
             {
                 MessageBox.Show("Cập nhật phiếu nhập thành công");
             }
             else
             {
                 MessageBox.Show("Cập nhật phiếu nhập thất bại");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }