コード例 #1
0
 private void LoadData()
 {
     try
     {
         DonDatHangClient donhang_client = new DonDatHangClient();
         DonDatHang       dh             = new DonDatHang();
         dgv_DanhSachDonHang.DataSource = donhang_client.DonDatHang_GetDonHang(dh, "").Tables[0];
         FormatGrid();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
 private void LoadDonHang()
 {
     try
     {
         DonDatHangClient             ddhclient = new DonDatHangClient();
         DonDatHang                   ddh       = new DonDatHang();
         DataTable                    dtb       = ddhclient.DonDatHang_GetDonHang(ddh, "").Tables[0];
         AutoCompleteStringCollection DsDonHang = new AutoCompleteStringCollection();
         foreach (DataRow row in dtb.Rows)
         {
             DsDonHang.Add(row["MaDonHang"].ToString());
         }
         txt_DonHang.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
         txt_DonHang.AutoCompleteSource       = AutoCompleteSource.CustomSource;
         txt_DonHang.AutoCompleteCustomSource = DsDonHang;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #3
0
        private void uc_OrderCreate_Load(object sender, EventArgs e)
        {
            try
            {
                DonDatHangClient client = new DonDatHangClient();
                DataTable        dtb    = new DataTable();
                dtb.Columns.Add("MaSanPham");
                dtb.Columns.Add("SoLuong");
                dtb.Columns.Add("DonGia");
                if (string.IsNullOrEmpty(dh.MaDonHang))//Insert
                {
                    txt_MaDonHang.Text    = client.DonDatHang_GetNewID(DateTime.Today.Year, DateTime.Today.Month);
                    txt_MaDonHang.Enabled = false;
                    txt_TongTien.Text     = "0";
                    txt_TongTien.Enabled  = false;
                    LoadMaNhanVien();
                    LoadMaKhachHang();
                    LoadSanPham();
                    dgv_DanhSachChiTiet.DataSource = dtb;
                }
                else//Update or Detail
                {
                    txt_MaDonHang.Text    = dh.MaDonHang;
                    txt_MaDonHang.Enabled = false;
                    msk_NgayDat.Text      = dh.NgayTao.ToString("dd/MM/yyyy");
                    txt_NhanVien.Text     = dh.MaNhanVien.ToString();
                    txt_KhachHang.Text    = dh.MaKhachHang.ToString();
                    txt_TongTien.Text     = dh.TongTien.ToString("#,##");
                    txt_TongTien.Enabled  = false;
                    foreach (DonDatHangCT ct in dh.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_NgayDat.Enabled    = false;
                        txt_NhanVien.Enabled   = false;
                        txt_KhachHang.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();
                    FormatGrid();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #4
0
 //Nút lưu
 private void btn_Luu_Click(object sender, EventArgs e)
 {
     try
     {
         DonDatHangClient client = new DonDatHangClient();
         DonDatHang       dh     = new DonDatHang();
         dh.MaDonHang   = txt_MaDonHang.Text;
         dh.NgayTao     = Convert.ToDateTime(msk_NgayDat.Text);
         dh.MaNhanVien  = txt_NhanVien.Text;
         dh.MaKhachHang = txt_KhachHang.Text;
         dh.TongTien    = Convert.ToDecimal(txt_TongTien.Text);
         List <DonDatHangCT> dsct = new List <DonDatHangCT>();
         foreach (DataGridViewRow row in dgv_DanhSachChiTiet.Rows)
         {
             DonDatHangCT ct = new DonDatHangCT();
             ct.MaDonDatHang = txt_MaDonHang.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);
         }
         dh.DSChiTiet = dsct.ToArray();
         if (IsInsertOrUpdate && !Checknull())
         {
             if (client.DonDatHang_Insert(dh))
             {
                 MessageBox.Show("Thêm đơn hàng thành công");
                 DataTable dtb = new DataTable();
                 dtb.Columns.Add("MaSanPham");
                 dtb.Columns.Add("SoLuong");
                 dtb.Columns.Add("DonGia");
                 txt_MaDonHang.Text    = client.DonDatHang_GetNewID(DateTime.Today.Year, DateTime.Today.Month);
                 txt_MaDonHang.Enabled = false;
                 txt_NhanVien.Text     = "";
                 txt_KhachHang.Text    = "";
                 msk_NgayDat.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.DonDatHang_Update(dh))
             {
                 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);
     }
 }