public thongtinkho(int id, int luongyc, int commandID, datakho dtk1) { id_thucpham = id; luongyeucau = luongyc; count = 0; dtk = dtk1; check_satify = 0; //MessageBox.Show("Bat Dau " + id_thucpham + "/" + luongyeucau); if (commandID == 1) { DivisionThucpham(); } else { UpdateInformationThucpham(); } }
public modun_quanli_kho(int[] id_tp, int[] luongtp, int count) { this.count = count; ttk = new thongtinkho[count]; count_export = 0; for (int i = 0; i < count; i++) { this.id_tp[i] = id_tp[i]; this.luongthucpham[i] = luongtp[i]; ttk[i] = new thongtinkho(this.id_tp[i], this.luongthucpham[i], 1, dtk); for (int j = 0; j < ttk[i].count; j++) { IDTPexport[count_export] = ttk[i].id_thucpham; LuongTPExport[count_export] = ttk[i].luong_sd[j]; PriceTPExport[count_export] = ttk[i].gia_sd[j]; LuongTon[count_export] = ttk[i].luong_con[j]; NgayCapNhat[count_export] = ttk[i].ngay_cap_nhat[j]; count_export++; } dtk = ttk[i].dtk; if (ttk[i].check_satify == 1) check_satify = 1; } for (int i = 0; i < dtk.count; i++) { if (dtk.luongthucpham[i] != 0) { update_infor = update_infor + dtk.id_thucpham[i] + "/" + dtk.gia_thucpham[i] + "/" + dtk.luongthucpham[i] + "/" + dtk.ngay_cap_nhat[i] + "\n"; } } //MessageBox.Show(update_infor); }
public void xuathopdong() { FileInfo hopdong = new FileInfo("data/database/hopdong.dat"); if (hopdong.Exists == true) { string newfilename = "data/database/hopdong-" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".dat"; hopdong.CopyTo(newfilename, true); } string str_hopdong = null; datakho dkt1 = new datakho(); modun_quanli_thucdon_dinhduong md1 = new modun_quanli_thucdon_dinhduong(); md1.query_thucpham(); for (int i = 0; i < quanli_HDTP.count_TP_hn; i++) { for (int j = 0; j < md1.count_TP; j++) { if (quanli_HDTP.ID_TP_hn[i] == Convert.ToInt32(md1.ID_TP[j])) { md1.dongia_TP_kho_new[j] = Convert.ToInt32(quanli_HDTP.dongia_TP_kho_new_hn[i]); } } // Dung str_hopdong += quanli_HDTP.ID_TP_hn[i] + "/"; str_hopdong += quanli_HDTP.name_TP_hn[i] + "/"; str_hopdong += quanli_HDTP.dongia_TP_kho_new_hn[i] + "/"; str_hopdong += quanli_HDTP.nhaphanphoi_hn[i] + "/"; quanli_HDTP.ngaybatdau_hn[i] = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year; str_hopdong += quanli_HDTP.ngaybatdau_hn[i] + "/"; str_hopdong += quanli_HDTP.ngayketthuc_hn[i]; str_hopdong += "\n"; } File.WriteAllText("data/database/hopdong.dat", str_hopdong); string result_tp = ""; for (int i = 0; i < md1.count_TP; i++) { result_tp = result_tp + md1.ID_TP[i] + "/" + md1.name_TP[i] + "/" + md1.type_TP[i] + "/" + md1.unit_TP[i] + "/" + md1.luong_TP_kho_new[i] + "/" + md1.dongia_TP_kho_new[i] + "/" + md1.luong_TP_kho_old[i] + "/" + md1.dongia_TP_kho_old[i] + "\n"; } dkt1.updateDataTP(result_tp); }
private void bt_submit_Click(object sender, EventArgs e) { int day = DateTime.Now.Day; int month = DateTime.Now.Month; int year = DateTime.Now.Year; dtkho = new datakho(); string s = ""; for (int i = 0; i < dtkho.count; i++) { s = s + dtkho.buffer[i] + "\n"; } for (int i = 0; i < (this.num_item + 1); i++) { int ID = import.findIDThucPham(cb_name_thucpham[i].SelectedItem.ToString()); int Price = Int32.Parse(tb_price_thucpham[i].Text); int Quanlity = Int32.Parse(tb_num_thucpham[i].Text); for (int j = 0; j < import.count_TP; j++) { if (ID == import.ID_TP[j]) { import.dongia_TP_kho_new[j] = Price; import.luong_TP_kho_new[j] = Quanlity; } } s = dtkho.reload(s, ID, Price, Quanlity); } if (s != "")dtkho.updateData(s); string update_tp = ""; for (int i = 0; i < import.count_TP; i++) { update_tp = update_tp + "" + import.ID_TP[i] + "/" + import.name_TP[i] + "/" + import.type_TP[i] + "/" + import.unit_TP[i] + "/" + import.luong_TP_kho_new[i] + "/" + import.dongia_TP_kho_new[i] + "/" + import.luong_TP_kho_old[i] + "/" + import.dongia_TP_kho_old[i] + "\n"; } if (update_tp != "") dtkho.updateDataTP(update_tp); this.Close(); Program.count_info_kho++; Program.th_infor_kho[Program.count_info_kho].Start(); }
private void bt_comp_Click(object sender, EventArgs e) { int day = DateTime.Now.Day; int month = DateTime.Now.Month; int year = DateTime.Now.Year; string file_name = "" + day + "-" + month + "-" + year; FileInfo f1 = new FileInfo("C:\\DailyReport\\Report\\phieu_tong_mua_hang_trong_ngay(" + file_name + ").xls"); if (f1.Exists) { f1.CopyTo("C:\\DailyReport\\Report\\phieu_tong_mua_hang_trong_ngay(" + file_name + ")_nhaptruoc.xls", true); // modun_quanli_thucdon_dinhduong md1 = new modun_quanli_thucdon_dinhduong(); md1.query_thucpham(); string filename = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year; //--cho xuất kho thêm // Khởi động chtr Excell COMExcel.Application exAppxt = new COMExcel.Application(); string workbookPathxt = "C:/DailyReport/TemplateDailyReport/tpl_bcxuatthemhangngay.xls"; COMExcel.Workbook exBookxt = exAppxt.Workbooks.Open(workbookPathxt, 0, false, 5, "", "", false, COMExcel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); // Lấy sheet 1. COMExcel.Worksheet exSheetxt = (COMExcel.Worksheet)exBookxt.Worksheets[1]; // Range là ô [1,1] (A1) //COMExcel.Range r; exSheetxt.Name = "Phiếu xuất kho thêm trong ngày"; for (int i = 1; i < md2.count_thieu + 1; i++) { COMExcel.Range r_stt_kho = (COMExcel.Range)exSheetxt.Cells[i + 6, 1]; // Ghi dữ liệu r_stt_kho.Value2 = "" + i; //r_stt_buy.ColumnWidth = 299; // Giãn cột //r_stt_kho.Columns.AutoFit(); COMExcel.Range r_name_kho = (COMExcel.Range)exSheetxt.Cells[i + 6, 2]; // Ghi dữ liệu r_name_kho.Value2 = md1.findNameThucPham(md2.id_thieu[i - 1]); // Giãn cột r_name_kho.Columns.AutoFit(); COMExcel.Range r_name_type = (COMExcel.Range)exSheetxt.Cells[i + 6, 4]; // Ghi dữ liệu r_name_type.Value2 = "Thực phẩm kho"; // Giãn cột r_name_kho.Columns.AutoFit(); COMExcel.Range r_donvi_kho = (COMExcel.Range)exSheetxt.Cells[i + 6, 6]; // Ghi dữ liệu r_donvi_kho.Value2 = "kg"; COMExcel.Range r_soluong_kho = (COMExcel.Range)exSheetxt.Cells[i + 6, 8]; // Ghi dữ liệu r_soluong_kho.Value2 = md2.tp_thieu[i - 1]; // Giãn cột //r_soluong_buy.Columns.AutoFit(); COMExcel.Range r_gia_kho = (COMExcel.Range)exSheetxt.Cells[i + 6, 7]; // Ghi dữ liệu r_gia_kho.Value2 = md1.findPriceThucPham(md2.id_thieu[i - 1]); // Giãn cột //r_gia_buy.Columns.AutoFit(); // Giãn cột //r_donvi_buy.Columns.AutoFit(); COMExcel.Range r_thanhtien_kho = (COMExcel.Range)exSheetxt.Cells[i + 6, 9]; // Ghi dữ liệu r_thanhtien_kho.Value2 = md1.findPriceThucPham(md2.id_thieu[i - 1]) * md2.tp_thieu[i - 1]; // Giãn cột //r_donvi_buy.Columns.AutoFit(); COMExcel.Range r_tonkho = (COMExcel.Range)exSheetxt.Cells[i + 6, 10]; r_tonkho.Value2 = ""; } // --hết xuất kho // Hiển thị chương trình excel exAppxt.Visible = false; // Đóng chương trình excel //r = (COMExcel.Range)exSheet.get_Range("A1", "A4"); // Save file exBookxt.SaveAs("C:\\DailyReport\\Report\\phieu_tong_xuat_hang_them_trong_ngay(" + filename + ").xls", COMExcel.XlFileFormat.xlWorkbookNormal, null, null, false, false, COMExcel.XlSaveAsAccessMode.xlExclusive, true, true, true, true, true); exBookxt.Close(false, false, false); exAppxt.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(exBookxt); System.Runtime.InteropServices.Marshal.ReleaseComObject(exAppxt); //--cho xuất trả lại kho // Khởi động chtr Excell COMExcel.Application exApptk = new COMExcel.Application(); string workbookPathtk = "C:/DailyReport/TemplateDailyReport/tpl_bctrakhohangngay.xls"; COMExcel.Workbook exBooktk = exApptk.Workbooks.Open(workbookPathtk, 0, false, 5, "", "", false, COMExcel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); // Lấy sheet 1. COMExcel.Worksheet exSheettk = (COMExcel.Worksheet)exBooktk.Worksheets[1]; // Range là ô [1,1] (A1) //COMExcel.Range r; exSheettk.Name = "Phiếu trả lại kho trong ngày"; for (int i = 1; i < md2.count_thua + 1; i++) { COMExcel.Range r_stt_kho = (COMExcel.Range)exSheettk.Cells[i + 6, 1]; // Ghi dữ liệu r_stt_kho.Value2 = "" + i; //r_stt_buy.ColumnWidth = 299; // Giãn cột //r_stt_kho.Columns.AutoFit(); COMExcel.Range r_name_kho = (COMExcel.Range)exSheettk.Cells[i + 6, 2]; // Ghi dữ liệu r_name_kho.Value2 = md1.findNameThucPham(md2.id_thua[i - 1]); // Giãn cột r_name_kho.Columns.AutoFit(); COMExcel.Range r_name_type = (COMExcel.Range)exSheettk.Cells[i + 6, 4]; // Ghi dữ liệu r_name_type.Value2 = "Thực phẩm kho"; // Giãn cột r_name_kho.Columns.AutoFit(); COMExcel.Range r_donvi_kho = (COMExcel.Range)exSheettk.Cells[i + 6, 6]; // Ghi dữ liệu r_donvi_kho.Value2 = "kg"; COMExcel.Range r_soluong_kho = (COMExcel.Range)exSheettk.Cells[i + 6, 8]; // Ghi dữ liệu r_soluong_kho.Value2 = md2.tp_thieu[i - 1]; // Giãn cột //r_soluong_buy.Columns.AutoFit(); COMExcel.Range r_gia_kho = (COMExcel.Range)exSheettk.Cells[i + 6, 7]; // Ghi dữ liệu r_gia_kho.Value2 = md1.findPriceThucPham(md2.id_thua[i - 1]); // Giãn cột //r_gia_buy.Columns.AutoFit(); // Giãn cột //r_donvi_buy.Columns.AutoFit(); COMExcel.Range r_thanhtien_kho = (COMExcel.Range)exSheettk.Cells[i + 6, 9]; // Ghi dữ liệu r_thanhtien_kho.Value2 = md1.findPriceThucPham(md2.id_thieu[i - 1]) * md2.tp_thua[i - 1]; // Giãn cột //r_donvi_buy.Columns.AutoFit(); COMExcel.Range r_tonkho = (COMExcel.Range)exSheettk.Cells[i + 6, 10]; r_tonkho.Value2 = ""; } // --hết xuất kho // Hiển thị chương trình excel exApptk.Visible = false; // Đóng chương trình excel //r = (COMExcel.Range)exSheet.get_Range("A1", "A4"); // Save file exBooktk.SaveAs("C:\\DailyReport\\Report\\phieu_tong_tra_kho_trong_ngay(" + filename + ").xls", COMExcel.XlFileFormat.xlWorkbookNormal, null, null, false, false, COMExcel.XlSaveAsAccessMode.xlExclusive, true, true, true, true, true); exBooktk.Close(false, false, false); exApptk.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(exBooktk); System.Runtime.InteropServices.Marshal.ReleaseComObject(exApptk); MessageBox.Show("ĐÃ XUẤT PHIẾU CHỈNH SỬA."); //MessageBox.Show("tronghoa"); } // Khởi động chtr Excell COMExcel.Application exApp = new COMExcel.Application(); exApp.StandardFont = "Times New Roman"; exApp.StandardFontSize = 12; string workbookPath = "C:/DailyReport/TemplateDailyReport/tpl_bcmuahangngay.xls"; COMExcel.Workbook exBook = exApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, COMExcel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); // Lấy sheet 1. COMExcel.Worksheet exSheet1 = (COMExcel.Worksheet)exBook.Worksheets[1]; // Range là ô [1,1] (A1) //COMExcel.Range r; exSheet1.Name = "Phiếu mua hàng trong ngày"; COMExcel.Range r_name_buy1 = (COMExcel.Range)exSheet1.Cells[6, 1]; for (int i = 1; i < this.count_tp_buy + 1; i++) { COMExcel.Range r_stt_buy = (COMExcel.Range)exSheet1.Cells[i + 6, 1]; // Ghi dữ liệu r_stt_buy.Value2 = "" + i; //r_stt_buy.ColumnWidth = 299; // Giãn cột //r_stt_buy.Columns.AutoFit(); COMExcel.Range r_name_buy = (COMExcel.Range)exSheet1.Cells[i + 6, 2]; // Ghi dữ liệu r_name_buy.Value2 = tb_name_tp_cp[i - 1].Text; // Giãn cột r_name_buy.Columns.AutoFit(); COMExcel.Range r_type = (COMExcel.Range)exSheet1.Cells[i + 6, 4]; r_type.Value2 = "Mua hàng ngày"; COMExcel.Range r_donvi_buy = (COMExcel.Range)exSheet1.Cells[i + 6, 6]; // Ghi dữ liệu r_donvi_buy.Value2 = tb_donvi_dongia_cp[i - 1].Text; // Giãn cột //r_donvi_buy.Columns.AutoFit(); COMExcel.Range r_soluong_buy = (COMExcel.Range)exSheet1.Cells[i + 6, 8]; // Ghi dữ liệu r_soluong_buy.Value2 = tb_luong_tp_cp[i - 1].Text; // Giãn cột //r_soluong_buy.Columns.AutoFit(); COMExcel.Range r_gia_buy = (COMExcel.Range)exSheet1.Cells[i + 6, 7]; // Ghi dữ liệu r_gia_buy.Value2 = tb_price_tp_cp[i - 1].Text; // Giãn cột //r_gia_buy.Columns.AutoFit(); COMExcel.Range r_thanhtien_buy = (COMExcel.Range)exSheet1.Cells[i + 6, 9]; // Ghi dữ liệu r_thanhtien_buy.Value2 = tb_comp_tp_cp[i - 1].Text; // Giãn cột //r_donvi_buy.Columns.AutoFit(); } //--cho xuất kho // Khởi động chtr Excell COMExcel.Application exApp1 = new COMExcel.Application(); // thiết lập font exApp1.StandardFont = "Times New Roman"; exApp1.StandardFontSize = 12; string workbookPath1 = "C:/DailyReport/TemplateDailyReport/tpl_bcxuathangngay.xls"; COMExcel.Workbook exBook1 = exApp.Workbooks.Open(workbookPath1, 0, false, 5, "", "", false, COMExcel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); // Lấy sheet 1. COMExcel.Worksheet exSheet2 = (COMExcel.Worksheet)exBook1.Worksheets[1]; //COMExcel.Application exApp1 = new COMExcel.Application(); // Thêm file temp xls //COMExcel.Workbook exBook1 = exApp1.Workbooks.Add(COMExcel.XlWBATemplate.xlWBATWorksheet); // Lấy sheet 1. //COMExcel.Worksheet exSheet2 = (COMExcel.Worksheet)exBook1.Worksheets[1]; // Range là ô [1,1] (A1) //COMExcel.Range r; exSheet2.Name = "Phiếu xuất kho trong ngày"; COMExcel.Range r_name_kho1 = (COMExcel.Range)exSheet2.Cells[6, 1]; // Ghi dữ liệu r_name_kho1.Value2 = "STT"; COMExcel.Range r_name_kho2 = (COMExcel.Range)exSheet2.Cells[6, 2]; for (int i = 1; i < this.MD_qlk.count_export + 1; i++) { COMExcel.Range r_stt_kho = (COMExcel.Range)exSheet2.Cells[i + 6, 1]; // Ghi dữ liệu r_stt_kho.Value2 = "" + i; //r_stt_buy.ColumnWidth = 299; // Giãn cột //r_stt_kho.Columns.AutoFit(); COMExcel.Range r_name_kho = (COMExcel.Range)exSheet2.Cells[i + 6, 2]; // Ghi dữ liệu r_name_kho.Value2 = tb_name_tp_cp[i - 1 + this.count_tp_buy].Text; // Giãn cột r_name_kho.Columns.AutoFit(); COMExcel.Range r_name_type = (COMExcel.Range)exSheet2.Cells[i + 6, 4]; // Ghi dữ liệu r_name_type.Value2 = "Thực phẩm kho"; // Giãn cột r_name_kho.Columns.AutoFit(); COMExcel.Range r_donvi_kho = (COMExcel.Range)exSheet2.Cells[i + 6, 6]; // Ghi dữ liệu r_donvi_kho.Value2 = tb_donvi_dongia_cp[i - 1 + this.count_tp_buy].Text; COMExcel.Range r_soluong_kho = (COMExcel.Range)exSheet2.Cells[i + 6, 7]; // Ghi dữ liệu r_soluong_kho.Value2 = tb_luong_tp_cp[i - 1 + this.count_tp_buy].Text; // Giãn cột //r_soluong_buy.Columns.AutoFit(); COMExcel.Range r_gia_kho = (COMExcel.Range)exSheet2.Cells[i + 6, 8]; // Ghi dữ liệu r_gia_kho.Value2 = tb_price_tp_cp[i - 1 + this.count_tp_buy].Text; // Giãn cột //r_gia_buy.Columns.AutoFit(); // Giãn cột //r_donvi_buy.Columns.AutoFit(); COMExcel.Range r_thanhtien_kho = (COMExcel.Range)exSheet2.Cells[i + 6, 9]; // Ghi dữ liệu r_thanhtien_kho.Value2 = tb_comp_tp_cp[i - 1 + this.count_tp_buy].Text; // Giãn cột //r_donvi_buy.Columns.AutoFit(); COMExcel.Range r_tonkho = (COMExcel.Range)exSheet2.Cells[i + 6, 10]; r_tonkho.Value2 = ""; } // đặt mặc định là ngang exSheet1.PageSetup.Orientation = COMExcel.XlPageOrientation.xlLandscape; exSheet2.PageSetup.Orientation = COMExcel.XlPageOrientation.xlLandscape; // cỡ giấy A4 exSheet1.PageSetup.PaperSize = COMExcel.XlPaperSize.xlPaperA4; exSheet2.PageSetup.PaperSize = COMExcel.XlPaperSize.xlPaperA4; // --hết xuất kho // Hiển thị chương trình excel exApp.Visible = false; exApp1.Visible = false; // Đóng chương trình excel // Save file exBook.SaveAs("C:\\DailyReport\\Report\\phieu_tong_mua_hang_trong_ngay(" + file_name + ").xls", COMExcel.XlFileFormat.xlWorkbookNormal, null, null, false, false, COMExcel.XlSaveAsAccessMode.xlExclusive, true, true, true, true, true); exBook1.SaveAs("C:\\DailyReport\\Report\\phieu_tong_xuat_hang_trong_ngay(" + file_name + ").xls", COMExcel.XlFileFormat.xlWorkbookNormal, null, null, false, false, COMExcel.XlSaveAsAccessMode.xlExclusive, true, true, true, true, true); exBook.Close(false, false, false); exBook1.Close(false, false, false); exApp.Quit(); exApp1.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(exBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(exApp); System.Runtime.InteropServices.Marshal.ReleaseComObject(exBook1); System.Runtime.InteropServices.Marshal.ReleaseComObject(exApp1); datakho dtk = new datakho(); dtk.updateData(MD_qlk.update_infor); MessageBox.Show("ĐÃ XUẤT PHIẾU XUẤT KHO VÀ PHIẾU MUA HÀNG"); }