コード例 #1
0
 private void LoadData()
 {
     try
     {
         BaoGiaClient baogia_client = new BaoGiaClient();
         BaoGia       bg            = new BaoGia();
         dgv_DanhSachBaoGia.DataSource = baogia_client.BaoGia_GetBaoGia(bg, "").Tables[0];
         FormatGrid();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
        private void uc_QuoteCreate_Load(object sender, System.EventArgs e)
        {
            try
            {
                BaoGiaClient client = new BaoGiaClient();
                DataTable    dtb    = new DataTable();
                dtb.Columns.Add("MaSanPham");
                dtb.Columns.Add("SoLuong");
                dtb.Columns.Add("DonGia");
                if (string.IsNullOrEmpty(bg.MaBaoGia))//Insert
                {
                    txt_MaBaoGia.Text    = client.BaoGia_GetNewID(DateTime.Today.Year, DateTime.Today.Month);
                    txt_MaBaoGia.Enabled = false;
                    txt_TongTien.Text    = "0";
                    txt_TongTien.Enabled = false;
                    LoadMaNhanVien();
                    LoadSanPham();
                    dgv_DanhSachChiTiet.DataSource = dtb;
                }
                else//Update or Detail
                {
                    txt_MaBaoGia.Text    = bg.MaBaoGia;
                    txt_MaBaoGia.Enabled = false;
                    msk_NgayLap.Text     = bg.NgayTao.ToString("dd/MM/yyyy");
                    msk_NgayHetHan.Text  = bg.NgayHetHan.ToString("dd/MM/yyyy");
                    txt_NhanVien.Text    = bg.MaNhanVien.ToString();
                    txt_ChietKhau.Text   = bg.ChietKhau.ToString("#,##");
                    txt_TongTien.Text    = bg.TongTien.ToString("#,##");
                    txt_TongTien.Enabled = false;
                    foreach (BaoGiaCT ct in bg.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_NgayLap.Enabled    = false;
                        msk_NgayHetHan.Enabled = false;
                        txt_NhanVien.Enabled   = false;
                        txt_ChietKhau.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);
            }
        }
コード例 #3
0
 //Nút lưu
 private void btn_Luu_Click(object sender, EventArgs e)
 {
     try
     {
         BaoGiaClient client = new BaoGiaClient();
         BaoGia       bg     = new BaoGia();
         bg.MaBaoGia   = txt_MaBaoGia.Text;
         bg.NgayTao    = Convert.ToDateTime(msk_NgayLap.Text);
         bg.NgayHetHan = Convert.ToDateTime(msk_NgayHetHan.Text);
         bg.MaNhanVien = txt_NhanVien.Text;
         bg.TongTien   = Convert.ToDecimal(txt_TongTien.Text);
         if (!string.IsNullOrEmpty(txt_ChietKhau.Text))
         {
             bg.ChietKhau = Convert.ToDecimal(txt_ChietKhau.Text);
         }
         else
         {
             bg.ChietKhau = 0;
         }
         List <BaoGiaCT> dsct = new List <BaoGiaCT>();
         foreach (DataGridViewRow row in dgv_DanhSachChiTiet.Rows)
         {
             BaoGiaCT ct = new BaoGiaCT();
             ct.MaBaoGia  = txt_MaBaoGia.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);
         }
         bg.DSChiTiet = dsct.ToArray();
         if (IsInsertOrUpdate && !Checknull())
         {
             if (client.BaoGia_Insert(bg))
             {
                 MessageBox.Show("Thêm báo giá thành công");
                 DataTable dtb = new DataTable();
                 dtb.Columns.Add("MaSanPham");
                 dtb.Columns.Add("SoLuong");
                 dtb.Columns.Add("DonGia");
                 txt_MaBaoGia.Text    = client.BaoGia_GetNewID(DateTime.Today.Year, DateTime.Today.Month);
                 txt_MaBaoGia.Enabled = false;
                 txt_NhanVien.Text    = "";
                 msk_NgayLap.Text     = "";
                 msk_NgayHetHan.Text  = "";
                 txt_TongTien.Text    = "0";
                 txt_TongTien.Enabled = false;
                 txt_ChietKhau.Text   = "0";
                 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.BaoGia_Update(bg))
             {
                 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);
     }
 }