Esempio n. 1
0
        private void uc_SellingInvoiceCreate_Load(object sender, EventArgs e)
        {
            try
            {
                HoaDonClient client = new HoaDonClient();
                DataTable    dtb    = new DataTable();
                dtb.Columns.Add("MaSanPham");
                dtb.Columns.Add("SoLuong");
                dtb.Columns.Add("DonGia");
                if (string.IsNullOrEmpty(hd.MaHoaDon))//Insert
                {
                    txt_MaHoaDon.Text    = client.HoaDon_GetNewID(DateTime.Today.Year, DateTime.Today.Month);
                    txt_MaHoaDon.Enabled = false;
                    txt_TongTien.Text    = "0";
                    txt_TongTien.Enabled = false;
                    LoadMaNhanVien();
                    LoadMaKhachHang();
                    LoadSanPham();
                    LoadDonHang();
                    dgv_DanhSachChiTiet.DataSource = dtb;
                }
                else//Update or Detail
                {
                    txt_MaHoaDon.Text    = hd.MaHoaDon;
                    txt_MaHoaDon.Enabled = false;
                    msk_NgayXuat.Text    = hd.NgayXuat.ToString("dd/MM/yyyy");
                    txt_NhanVien.Text    = hd.NhanVien.ToString();
                    txt_KhachHang.Text   = hd.KhachHang.ToString();
                    txt_DonHang.Text     = hd.DonDatHang.ToString();
                    txt_TongTien.Text    = hd.TongTien.ToString("#,##");
                    txt_TongTien.Enabled = false;
                    txt_DaThanhToan.Text = hd.DaThanhToan.ToString("#,##");
                    txt_ConLai.Text      = hd.ConLai.ToString("#,##");
                    txt_ConLai.Enabled   = false;
                    foreach (HoaDonCT ct in hd.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_NgayXuat.Enabled   = false;
                        txt_NhanVien.Enabled   = false;
                        txt_KhachHang.Enabled  = false;
                        txt_DonHang.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();
                    LoadMaKhachHang();
                    LoadSanPham();
                    LoadDonHang();
                    FormatGrid();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
 //Nút lưu
 private void btn_Luu_Click(object sender, EventArgs e)
 {
     try
     {
         HoaDonClient client = new HoaDonClient();
         HoaDon       hd     = new HoaDon();
         hd.MaHoaDon    = txt_MaHoaDon.Text;
         hd.NgayXuat    = Convert.ToDateTime(msk_NgayXuat.Text);
         hd.NhanVien    = txt_NhanVien.Text;
         hd.KhachHang   = txt_KhachHang.Text;
         hd.DonDatHang  = txt_DonHang.Text;
         hd.TongTien    = Convert.ToDecimal(txt_TongTien.Text);
         hd.DaThanhToan = Convert.ToDecimal(txt_DaThanhToan.Text);
         hd.ConLai      = Convert.ToDecimal(txt_ConLai.Text);
         List <HoaDonCT> dsct = new List <HoaDonCT>();
         foreach (DataGridViewRow row in dgv_DanhSachChiTiet.Rows)
         {
             HoaDonCT ct = new HoaDonCT();
             ct.MaHoaDon  = txt_MaHoaDon.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);
         }
         hd.DSChiTiet = dsct.ToArray();
         if (IsInsertOrUpdate && !Checknull())
         {
             if (client.HoaDon_Insert(hd))
             {
                 MessageBox.Show("Thêm hoá đơn thành công");
                 DataTable dtb = new DataTable();
                 dtb.Columns.Add("MaSanPham");
                 dtb.Columns.Add("SoLuong");
                 dtb.Columns.Add("DonGia");
                 txt_MaHoaDon.Text    = client.HoaDon_GetNewID(DateTime.Today.Year, DateTime.Today.Month);
                 txt_MaHoaDon.Enabled = false;
                 txt_NhanVien.Text    = "";
                 txt_KhachHang.Text   = "";
                 txt_DonHang.Text     = "";
                 msk_NgayXuat.Text    = "";
                 txt_TongTien.Text    = "0";
                 txt_TongTien.Enabled = false;
                 txt_DaThanhToan.Text = "0";
                 txt_ConLai.Text      = "0";
                 txt_MaSanPham.Text   = "";
                 txt_TenSanPham.Text  = "";
                 txt_SoLuong.Text     = "";
                 txt_DonGia.Text      = "";
                 LoadMaNhanVien();
                 LoadMaKhachHang();
                 LoadSanPham();
                 LoadDonHang();
                 dgv_DanhSachChiTiet.DataSource = dtb;
             }
             else
             {
                 MessageBox.Show("Thêm hoá đơn thất bại");
             }
         }
         else if (!IsInsertOrUpdate && !Checknull())
         {
             if (client.HoaDon_Update(hd))
             {
                 MessageBox.Show("Cập nhật hoá đơn thành công");
             }
             else
             {
                 MessageBox.Show("Cập nhật hoá đơn thất bại");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }