Пример #1
0
        //Lấy chi tiết báo giá
        public List <BaoGiaCT> LoadChiTiet(string mabg)
        {
            List <Model.BaoGia_CT> dsct = (from bgct in db.BaoGia_CT
                                           where bgct.MaBaoGia == mabg
                                           select bgct).ToList();
            List <BaoGiaCT> kq = new List <BaoGiaCT>();

            foreach (Model.BaoGia_CT ct in dsct)
            {
                BaoGiaCT kqct = new BaoGiaCT();
                kqct.MaBaoGia  = ct.MaBaoGia;
                kqct.MaSanPham = ct.MaSanPham;
                kqct.DonGia    = ct.DonGia.Value;
                kqct.SoLuong   = ct.SoLuong;
                kq.Add(kqct);
            }
            return(kq);
        }
Пример #2
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);
     }
 }