private void XuatHang_Load(object sender, EventArgs e) { var i2nKHO = new Id2Name(textBoxMAKHO, comboBoxKho); var i2nKH = new Id2Name(textBoxKHACHHANG, comboBoxKHACH_HANG); var i2nHH = new Id2Name(textBoxHANGHOA, comboBoxHANGHOA); if (MKho.Get(MKho.KHO_HANG).Count() == 0 || MHangHoa.Get().Count() == 0) { MessageBox.Show("CẦN TẠO KHO VÀ HÀNG HÓA TRƯỚC KHI XUẤT HÀNG"); this.Close(); return; } comboBoxKho.DataSource = MKho.Get(MKho.KHO_HANG).OrderBy(u => u.NAME); comboBoxKho.DisplayMember = "NAME"; comboBoxKho.ValueMember = "ID"; comboBoxKHACH_HANG.DataSource = dbContext.KHACH_HANG.OrderBy(u => u.NAME); comboBoxKHACH_HANG.DisplayMember = "NAME"; comboBoxKHACH_HANG.ValueMember = "ID"; comboBoxHANGHOA.DataSource = dbContext.HANG_HOA.OrderBy(u => u.NAME); comboBoxHANGHOA.DisplayMember = "NAME"; comboBoxHANGHOA.ValueMember = "ID"; dataGridView1.DataSource = bs; comboBoxHANGHOA_SelectedIndexChanged(sender, e); dataGridView1.AutoResizeColumns(); dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; textBoxMAKHO.Select(); textBoxMAKHO.SelectAll(); }
private void buttonIMPORT_Click(object sender, EventArgs e) { MyApp = new Excel.Application(); MyApp.Visible = false; MyBook = MyApp.Workbooks.Open(textBox1.Text); hhSheet = (Excel.Worksheet)MyBook.Sheets[1]; tonSheet = (Excel.Worksheet)MyBook.Sheets[2]; long hhCount = hhSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row; long khoCount = tonSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Column; DataInstance.Instance().DBContext(); // HANG HOA for (int index = 2; index <= hhCount; index++) { System.Array MyValues = (System.Array)hhSheet.get_Range("A" + index.ToString(), "B" + index.ToString()).Cells.Value; DataInstance.Instance().DBContext().AddToHANG_HOA(new HANG_HOA { NAME = MyValues.GetValue(1, 1).ToString(), UNIT = MyValues.GetValue(1, 2).ToString(), }); } // KHO for (int index = 2; index <= khoCount; index++) { string MyValues = tonSheet.Cells[1, index].Value; DataInstance.Instance().DBContext().AddToKHOes(new KHO { NAME = MyValues, TYPE = MKho.KHO_HANG }); DataInstance.Instance().DBContext().SaveChanges(); for (int i = 2; i <= hhCount; i++) { long sl = long.Parse(tonSheet.Cells[i, index].Value.ToString()); long dongia = long.Parse(hhSheet.Cells[i, 3].Value.ToString()); DataInstance.Instance().DBContext().AddToNHAP_HANG(new NHAP_HANG { MAKHO = MKho.GetIDbyName(tonSheet.Cells[1, index].Value.ToString()), MANCC = -1, MAHH = MHangHoa.GetIDbyName(hhSheet.Cells[i, 1].Value.ToString()), SO_LUONG = sl, SL_CON_LAI = sl, DON_GIA_MUA = dongia, NGAY_NHAP = DateTime.Now.Date, CREATED_AT = DateTime.Now }); } } DataInstance.Instance().DBContext().SaveChanges(); MessageBox.Show("Cập nhật dữ liệu thành công\nVui lòng khởi động lại chương trình"); MyBook.Close(); MyApp.Quit(); MHeTHong.Set(MHeTHong.DATE, DateTime.Now.ToLongDateString()); Application.Exit(); }
private void NhapHang_Load(object sender, EventArgs e) { if (MKho.Get(MKho.KHO_HANG).Count() == 0 || MHangHoa.Get().Count() == 0 || MNcc.Get().Count() == 0) { MessageBox.Show("CẦN TẠO KHO, HÀNG HÓA VÀ NHÀ CUNG CẤP TRƯỚC KHI NHẬP HÀNG"); this.Close(); return; } var i2nKHO = new Id2Name(textBoxMAKHO, comboBoxKho); var i2nKH = new Id2Name(textBoxNCC, comboBoxNCC); var i2nHH = new Id2Name(textBoxHANGHOA, comboBoxHANGHOA); comboBoxKho.DataSource = T_Manager.Modal.MKho.Get(MKho.KHO_HANG).OrderBy(u => u.NAME);//dbContext.KHOes.Where(u => u.TYPE == 0); comboBoxKho.DisplayMember = "NAME"; comboBoxKho.ValueMember = "ID"; comboBoxNCC.DataSource = T_Manager.Modal.MNcc.Get().OrderBy(u => u.NAME);//dbContext.NHA_CUNG_CAP; comboBoxNCC.DisplayMember = "NAME"; comboBoxNCC.ValueMember = "ID"; comboBoxHANGHOA.DataSource = dbContext.HANG_HOA.OrderBy(u => u.NAME); comboBoxHANGHOA.DisplayMember = "NAME"; comboBoxHANGHOA.ValueMember = "ID"; dataGridView1.DataSource = bs; comboBoxHANGHOA_SelectedIndexChanged(sender, e); dataGridView1.AutoResizeColumns(); dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; textBoxMAKHO.Select(); textBoxMAKHO.SelectAll(); }
private void button1_Click(object sender, EventArgs e) { long xe = long.Parse(comboBox1.SelectedValue.ToString()); DateTime from = dateTimePickerFROM.Value.Date; DateTime to = dateTimePickerTO.Value.Date; var lst = DataInstance.Instance().DBContext().CHI_TIEU_DUNG_NOI_BO.Where(u => u.MAXE == xe) .Where(u => u.NGAY_CHI >= from && u.NGAY_CHI <= to) .OrderBy(u => u.NGAY_CHI); List <object> list = new List <object>(); foreach (CHI_TIEU_DUNG_NOI_BO nb in lst) { list.Add(new { NGAY = nb.NGAY_CHI, KHO = MKho.GetNamebyID(nb.MAKHO), NOIDUNG = nb.NOI_DUNG, HANGHOA = nb.MAHH == -1 ? "" : MHangHoa.GetNameByID(nb.MAHH), SOLUONG = nb.SO_LUONG, DONGIA = nb.DON_GIA_BAN, THANHTIEN = nb.TONG_TIEN, }); } CrystalReportCHIDUNGCHOXE rpt = new CrystalReportCHIDUNGCHOXE(); rpt.SetDataSource(list); rpt.SetParameterValue("FROM", dateTimePickerFROM.Value); rpt.SetParameterValue("TO", dateTimePickerTO.Value); rpt.SetParameterValue("COMP", ConstClass.COMPANY_NAME); rpt.SetParameterValue("KH", comboBox1.Text); crystalReportViewer1.ReportSource = rpt; crystalReportViewer1.Zoom(150); }
private void FTonKho_Load(object sender, EventArgs e) { if (MKho.Get(MKho.KHO_HANG).Count() == 0 || MHangHoa.Get().Count() == 0) { MessageBox.Show("CẦN TẠO KHO, HÀNG HÓA TRƯỚC KHI NHẬP"); this.Close(); return; } Reload(); }
private void buttonSAVE_Click(object sender, EventArgs e) { List <long> KHOes = db.KHOes.OrderBy(u => u.NAME).Select(u => u.ID).ToList(); bool wrong_input = false; foreach (DataGridViewRow row in dataGridViewIMPORT.Rows) { long MAHH = MHangHoa.GetIDbyName(row.Cells[0].Value.ToString()); for (int i = 1; i < row.Cells.Count - 1; i += 2) { long soluong = long.Parse(row.Cells[i].Value.ToString()); long dongia = long.Parse(row.Cells[i + 1].Value.ToString()); long MAKHO = KHOes[i / 2]; if (soluong > 0 && dongia > 0) { db.AddToNHAP_HANG(new NHAP_HANG { MAKHO = MAKHO, MANCC = -1, MAHH = MAHH, SO_LUONG = soluong, SL_CON_LAI = soluong, DON_GIA_MUA = dongia, NGAY_NHAP = DateTime.Now.Date, CREATED_AT = DateTime.Now }); } else { if (!(soluong == 0 && dongia == 0)) { wrong_input = true; } } } } if (wrong_input == false) { db.SaveChanges(); MessageBox.Show("ĐÃ NHẬP TỒN KHO"); this.Close(); return; } else { MessageBox.Show("DỮ LIỆU NHẬP KHÔNG PHÙ HỢP\nNẾU CÓ SỐ LƯỢNG, PHẢI CÓ ĐƠN GIÁ"); } }
private void FBanHang_Load(object sender, EventArgs e) { comboBoxKHO.DataSource = MKho.Get(MKho.KHO_HANG); comboBoxKHO.DisplayMember = "NAME"; comboBoxKHO.ValueMember = "ID"; comboBoxHANGHOA.DataSource = MHangHoa.Get(); comboBoxHANGHOA.DisplayMember = "NAME"; comboBoxHANGHOA.ValueMember = "ID"; DateTime now = DateTime.Now.Date; comboBoxKHO_SelectedIndexChanged(sender, e); textBoxDONGIABAN.Select(); textBoxDONGIABAN.SelectAll(); }
private void comboBoxNBXE_SelectedIndexChanged(object sender, EventArgs e) { try { var xe = Int32.Parse(comboBoxNBXE.SelectedValue.ToString()); var kho = Int32.Parse(comboBoxKHO.SelectedValue.ToString()); DateTime now = dateTimePickerdATE.Value.Date; var lst = dbContext.CHI_TIEU_DUNG_NOI_BO.Where(u => u.MAXE == xe) .Where(u => u.MAKHO == kho) .Where(u => u.NGAY_CHI == now); List <object> list = new List <object>(); foreach (CHI_TIEU_DUNG_NOI_BO nb in lst) { list.Add(new { NGAY = nb.NGAY_CHI, NOIDUNG = nb.NOI_DUNG, HANGHOA = nb.MAHH == -1 ? "" : MHangHoa.GetNameByID(nb.MAHH), SOLUONG = nb.SO_LUONG, DONGIA = nb.DON_GIA_BAN, THANHTIEN = nb.TONG_TIEN, }); } bs_noibo.DataSource = list; dataGridViewXE.DataSource = bs_noibo; dataGridViewXE.Columns[0].HeaderText = "NGÀY"; dataGridViewXE.Columns[1].HeaderText = "NỘI DUNG CHI"; dataGridViewXE.Columns[2].HeaderText = "HÀNG HÓA"; dataGridViewXE.Columns[3].HeaderText = "SỐ LƯỢNG"; dataGridViewXE.Columns[4].HeaderText = "ĐƠN GIÁ"; dataGridViewXE.Columns[5].HeaderText = "THÀNH TIỀN"; } catch (Exception ex) { } }
private void buttonVIEW_Click(object sender, EventArgs e) { var _ncc = long.Parse(comboBoxNCC.SelectedValue.ToString()); var _from = dateTimePickerFROM.Value; var _to = dateTimePickerTO.Value; string note = ""; BindingSource bs = new BindingSource(); if (checkBoxTRANO.Checked == false) { bs.DataSource = (from nh in DataInstance.Instance().DBContext().NHAP_HANG join kho in DataInstance.Instance().DBContext().KHOes on nh.MAKHO equals kho.ID join ncc in DataInstance.Instance().DBContext().NHA_CUNG_CAP on nh.MANCC equals ncc.ID join hh in DataInstance.Instance().DBContext().HANG_HOA on nh.MAHH equals hh.ID where nh.MANCC == _ncc where nh.NGAY_NHAP >= _from where nh.NGAY_NHAP <= _to select new { NGAY = nh.NGAY_NHAP, KHO = kho.NAME, HANGHOA = hh.NAME, SOLUONG = nh.SO_LUONG, DONGIA = nh.DON_GIA_MUA, THANHTIEN = nh.SO_LUONG * nh.DON_GIA_MUA }); CrystalReportCHITIETNONCC rpt = new CrystalReportCHITIETNONCC(); rpt.SetDataSource(bs); rpt.SetParameterValue("NCC", comboBoxNCC.Text); rpt.SetParameterValue("FROM", _from); rpt.SetParameterValue("TO", _to); rpt.SetParameterValue("COMP", ConstClass.COMPANY_NAME); crystalReportViewer1.ReportSource = rpt; } else { List <CThanhToanNCC> lst = new List <CThanhToanNCC>(); foreach (NHAP_HANG nh in DataInstance.Instance().DBContext().NHAP_HANG .Where(u => u.MANCC == _ncc && u.NGAY_NHAP >= _from && u.NGAY_NHAP <= _to)) { lst.Add(new CThanhToanNCC { NGAY = nh.NGAY_NHAP, KHO = MKho.GetNamebyID(nh.MAKHO), HANGHOA = MHangHoa.GetNameByID(nh.MAHH), DONGIA = nh.DON_GIA_MUA, SOLUONG = nh.SO_LUONG, THANHTIEN = nh.SO_LUONG * nh.DON_GIA_MUA, TIENTHANHTOAN = 0, CONNO = 0, THANHTOAN = "-", }); } foreach (TRA_NO_NCC tn in DataInstance.Instance().DBContext().TRA_NO_NCC .Where(u => u.MANCC == _ncc && u.NGAY_TRA >= _from && u.NGAY_TRA <= _to)) { lst.Add(new CThanhToanNCC { NGAY = tn.NGAY_TRA, KHO = MKho.GetNamebyID(tn.MAKHO), HANGHOA = "-", DONGIA = 0, SOLUONG = 0, TIENTHANHTOAN = tn.TONG_TIEN, CONNO = 0, THANHTOAN = "TRẢ NỢ NCC", }); } var datasource = lst.OrderBy(u => u.NGAY); long nodauki = MNcc.NoTO(_ncc, _from) - MNcc.TraNoTO(_ncc, _from); long _nodauki = nodauki; foreach (CThanhToanNCC c in datasource) { c.CONNO = nodauki - c.TIENTHANHTOAN + c.THANHTIEN; nodauki = c.CONNO; } bs.DataSource = lst; CrystalReportTHANHTOANNCC rpt = new CrystalReportTHANHTOANNCC(); rpt.SetDataSource(bs); rpt.SetParameterValue("NCC", comboBoxNCC.Text); rpt.SetParameterValue("FROM", _from); rpt.SetParameterValue("TO", _to); rpt.SetParameterValue("COMP", ConstClass.COMPANY_NAME); rpt.SetParameterValue("NODAUKI", _nodauki); crystalReportViewer1.ReportSource = rpt; } }
private void button1_Click(object sender, EventArgs e) { List <CCongNoNew> _datasource = new List <CCongNoNew>(); string note = ""; BindingSource bs = new BindingSource(); long MAKH = long.Parse(comboBox1.SelectedValue.ToString()); DateTime FROM = dateTimePickerFROM.Value.Date; DateTime TO = dateTimePickerTO.Value.Date; var xuat_hang = db.XUAT_HANG.Where(u => u.MAKH == MAKH && u.NGAY_XUAT >= FROM && u.NGAY_XUAT <= TO); var thu_no = db.THU_NO.Where(u => u.MAKH == MAKH && u.NGAY_TRA >= FROM && u.NGAY_TRA <= TO); foreach (XUAT_HANG xh in xuat_hang) { HANG_HOA _hh = MHangHoa.GetByID(xh.MAHH); string unit = _hh == null ? "" : _hh.UNIT; long dongia = _hh == null ? 0 : xh.DON_GIA_BAN; long soluong = _hh == null ? 0 : xh.SO_LUONG; _datasource.Add(new CCongNoNew { NGAY = xh.NGAY_XUAT.Value, TRANO = soluong < 0 ? "Nhập bù" : "", TRATRUOC = xh.TRA_TRUOC, HANGHOA = MHangHoa.GetNameByID(xh.MAHH), SOLUONG = soluong, DONVITINH = unit, DONGIA = dongia, THANHTIEN = xh.THANH_TIEN, TRAGOC = 0, TRALAI = 0, CONNO = 0 }); } foreach (THU_NO xh in thu_no) { _datasource.Add(new CCongNoNew { NGAY = xh.NGAY_TRA, TRATRUOC = 0, TRANO = "Trả nợ", HANGHOA = "", SOLUONG = 0, DONVITINH = "", DONGIA = 0, THANHTIEN = 0, TRAGOC = xh.TIEN_GOC, TRALAI = xh.TIEN_LAI, CONNO = 0 }); } var datasource = _datasource.OrderBy(u => u.NGAY); long no = checkBoxNODAUKI.Checked == true?MXuatHang.TongNoDauKi(MAKH, FROM) - MThuNo.TongGocDauKi(MAKH, FROM) : 0; long nodauki = no; foreach (CCongNoNew c in datasource) { c.CONNO = no + c.THANHTIEN - c.TRATRUOC - c.TRAGOC; no = c.CONNO; } bs.DataSource = datasource; CrystalReportCONGNOKHACHHANG rpt = new CrystalReportCONGNOKHACHHANG(); rpt.SetDataSource(bs); rpt.SetParameterValue("KH", comboBox1.Text); rpt.SetParameterValue("FROM", dateTimePickerFROM.Value); rpt.SetParameterValue("TO", dateTimePickerTO.Value); rpt.SetParameterValue("COMP", ConstClass.COMPANY_NAME); rpt.SetParameterValue("NODAUKI", nodauki); crystalReportViewer1.ReportSource = rpt; crystalReportViewer1.Zoom(150); }
private void comboBoxDULIEU_SelectedIndexChanged(object sender, EventArgs e) { try { long l = long.Parse(comboBoxDULIEU.SelectedValue.ToString()); List <object> ls = new List <object>(); IQueryable lst; switch (l) { case 0: lst = MKho.Get(MKho.KHO_HANG).OrderBy(u => u.ID); foreach (KHO k in lst) { ls.Add(new { ID = k.ID, NAME = k.ID.ToString() + " - " + k.NAME }); } break; case 1: lst = MKho.Get(MKho.KHO_TK_NGANHANG); foreach (KHO k in lst) { ls.Add(new { ID = k.ID, NAME = k.ID.ToString() + " - " + k.NAME }); } break; case 2: lst = MHangHoa.Get(); foreach (HANG_HOA k in lst) { ls.Add(new { ID = k.ID, NAME = k.ID.ToString() + " - " + k.NAME }); } break; case 3: lst = MNcc.Get(); foreach (NHA_CUNG_CAP k in lst) { ls.Add(new { ID = k.ID, NAME = k.ID.ToString() + " - " + k.NAME }); } break; case 4: lst = db.NHAN_VIEN; foreach (NHAN_VIEN k in lst) { ls.Add(new { ID = k.ID, NAME = k.ID.ToString() + " - " + k.NAME }); } break; case 5: lst = db.XEs; foreach (XE k in lst) { ls.Add(new { ID = k.ID, NAME = k.ID.ToString() + " - " + k.BIEN_SO }); } break; case 6: lst = db.NGUON_VAY; foreach (NGUON_VAY k in lst) { ls.Add(new { ID = k.ID, NAME = k.ID.ToString() + " - " + k.NAME }); } break; case 7: lst = db.KHACH_HANG; foreach (KHACH_HANG k in lst) { ls.Add(new { ID = k.ID, NAME = k.ID.ToString() + " - " + k.NAME }); } break; } listBoxKHO.DataSource = ls; listBoxKHO.DisplayMember = "NAME"; listBoxKHO.ValueMember = "ID"; } catch (Exception ex) { } }
private void button1_Click(object sender, EventArgs e) { List <CCongNoKhachHang> _datasource = new List <CCongNoKhachHang>(); string note = ""; BindingSource bs = new BindingSource(); long MAKH = long.Parse(comboBox1.SelectedValue.ToString()); DateTime FROM = dateTimePickerFROM.Value.Date; DateTime TO = dateTimePickerTO.Value.Date; /* Lấy tất cả dữ liệu xuất hàng cho khách hàng này */ /* Từ ngày đến ngày */ IQueryable <CCongNoKhachHang> xuat_hang = (from _xh in DataInstance.Instance().DBContext().XUAT_HANG join _kho in DataInstance.Instance().DBContext().KHOes on _xh.MAKHO equals _kho.ID //join _hh in DataInstance.Instance().DBContext().HANG_HOA on _xh.MAHH equals _hh.ID where _xh.MAKH == MAKH where _xh.NGAY_XUAT >= FROM && _xh.NGAY_XUAT <= TO orderby _xh.NGAY_XUAT ascending select new CCongNoKhachHang { ID = (int)_xh.ID, NGAY = _xh.NGAY_XUAT.Value, KHO = _kho.NAME, HANGHOAID = _xh.MAHH, //HANGHOA = _hh.NAME, SOLUONG = _xh.SO_LUONG, DONGIABAN = _xh.DON_GIA_BAN, THANHTIEN = _xh.THANH_TIEN, TRATRUOC = _xh.TRA_TRUOC, LAISUAT = _xh.LAI_SUAT, LAI = 0, TRAGOC = 0, TRALAI = 0, CONNO = 0 }); note = "CHI TIẾT LÃI KHÁCH HÀNG"; DateTime now = dateTimePickerTO.Value.Date; /* Không sử dụng dữ liệu từ thu nợ */ foreach (CCongNoKhachHang row in xuat_hang) { //double lai = Utility.Lai(row.NGAY, now, row.LAISUAT, row.THANHTIEN - row.TRATRUOC); double lai = MXuatHang.GetLai(row.ID, now); string HangHoa = MHangHoa.GetNameByID(row.HANGHOAID); _datasource.Add(new CCongNoKhachHang() { NGAY = row.NGAY, KHO = row.KHO, HANGHOA = HangHoa, SOLUONG = row.SOLUONG, DONGIABAN = row.DONGIABAN, THANHTIEN = row.THANHTIEN, TRATRUOC = row.TRATRUOC, LAISUAT = row.LAISUAT * 100, /* Cần tính lãi */ LAI = lai, TRAGOC = 0, TRALAI = 0, CONNO = row.THANHTIEN + (long)lai - row.TRATRUOC }); } //} bs.DataSource = _datasource; CrystalReportCHITIETLAIKHACHHANG rpt = new CrystalReportCHITIETLAIKHACHHANG(); rpt.SetDataSource(bs); rpt.SetParameterValue("KH", comboBox1.Text); rpt.SetParameterValue("FROM", dateTimePickerFROM.Value); rpt.SetParameterValue("TO", dateTimePickerTO.Value); rpt.SetParameterValue("COMP", ConstClass.COMPANY_NAME); rpt.SetParameterValue("NOTE", note); crystalReportViewer1.ReportSource = rpt; crystalReportViewer1.Zoom(150); }