private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) { try { var result = _iReportService.GetProductivity(new DateTime(start.Year, start.Month, start.Day, 0, 0, 0), new DateTime(end.Year, end.Month, end.Day, 23, 59, 59)); var quantityViewModel = new List<SaleViewModel>(); foreach (var productivity in result) { var temp = new SaleViewModel(); temp.Sales = _iSaleService.GetQuantity(new DateTime(start.Year, start.Month, start.Day, 0, 0, 0), new DateTime(end.Year, end.Month, end.Day, 23, 59, 59), productivity.Code); temp.Code = productivity.Code; quantityViewModel.Add(temp); } string name = saveFileDialog1.FileName; var wb = new XSSFWorkbook(); // tab name ISheet sheet = wb.CreateSheet("Bao cao SL ban ra hang ngay"); // header IRow row = sheet.CreateRow(0); ICell cell = row.CreateCell(0); cell.SetCellValue("BÁO CÁO SẢN PHẨM HÀNG NGÀY CÔNG TY ATZ"); NPOI.SS.Util.CellRangeAddress cra = new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 2); sheet.AddMergedRegion(cra); // column header IRow row3 = sheet.CreateRow(2); ICell cell0 = row3.CreateCell(0); cell0.SetCellValue("STT"); ICell cell1 = row3.CreateCell(1); cell1.SetCellValue("MÃ CHƯƠNG TRÌNH"); ICell cell2 = row3.CreateCell(2); cell2.SetCellValue("CHƯƠNG TRÌNH"); //ICell cell3 = row3.CreateCell(3); //cell3.SetCellValue("DURATION"); ICell cell4 = row3.CreateCell(3); cell4.SetCellValue("CATEGORY"); //ICell cell5 = row3.CreateCell(5); //cell5.SetCellValue("GIÁ SẢN PHẨM"); ICell cell6 = row3.CreateCell(4); cell6.SetCellValue("Ghi chú"); var tempStart = start; var k = 5; while (DateTime.Compare(tempStart, end) <= 0) { ICell cellk = row3.CreateCell(k); cellk.SetCellValue(tempStart.ToString("dd/MM/yyyy")); tempStart = tempStart.AddDays(1); k++; } // add Program Code int i = 3; foreach (var item in result) { var time = Convert.ToDateTime(item.Duration); if (time.Minute > 4) { IRow row_temp = sheet.CreateRow(i); ICell cell_temp0 = row_temp.CreateCell(0); cell_temp0.SetCellValue(i - 2); ICell cell_temp1 = row_temp.CreateCell(1); cell_temp1.SetCellValue(item.Code); ICell cell_temp2 = row_temp.CreateCell(2); cell_temp2.SetCellValue(item.Name); //ICell cell_temp3 = row_temp.CreateCell(3); //DateTime time1 = DateTime.Today; //time1 = time1.AddMinutes(time.Minute).AddSeconds(time.Second); //cell_temp3.SetCellValue(time1); //ICellStyle style = wb.CreateCellStyle(); //cell_temp3.CellStyle = style; //IDataFormat dataFormatCustom = wb.CreateDataFormat(); //cell_temp3.CellStyle.DataFormat = dataFormatCustom.GetFormat("mm:ss"); ICell cell_temp4 = row_temp.CreateCell(3); cell_temp4.SetCellValue(item.Category); //ICell cell_temp5 = row_temp.CreateCell(5); //cell_temp5.SetCellValue(item.Price); ICell cell_temp6 = row_temp.CreateCell(4); cell_temp6.SetCellValue(item.Note); var tempStart1 = start; var k1 = 5; var sales = quantityViewModel.Where(x=> x.Code == item.Code).FirstOrDefault(); while (DateTime.Compare(tempStart1, end) <= 0) { ICell cellk = row_temp.CreateCell(k1); if (sales != null) { var q = sales.Sales.Where(y => y.Date.Year == tempStart1.Year && y.Date.Month == tempStart1.Month && y.Date.Day == tempStart1.Day).FirstOrDefault(); if (q != null) { cellk.SetCellValue(q.Quantity); } else { cellk.SetCellValue(0); } } else { cellk.SetCellValue(0); } tempStart1 = tempStart1.AddDays(1); k1++; } i++; } } for (int l = 0; l < row3.LastCellNum; l++) { sheet.AutoSizeColumn(l); } using (FileStream stream = new FileStream(name, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) { wb.Write(stream); stream.Close(); } var successForm = new SuccessForm(); successForm.ShowDialog(); } catch (Exception ex) { var errorForm = new ErrorForm(ex.Message); errorForm.ShowDialog(); } }
private void button9_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(textBox2.Text) && !string.IsNullOrWhiteSpace(textBox2.Text)) { try { ReadSchedule(_iWorkbook); var successForm = new SuccessForm(); successForm.ShowDialog(); } catch (Exception ex) { var errorForm = new ErrorForm(ex.Message); errorForm.ShowDialog(); } } }
private void button6_Click(object sender, EventArgs e) { try { var levelList = _iLevelService.GetAll().ToList(); var a = new Level(); a.Name = "A"; a.UpdateDate = DateTime.Now; a.Begin = (int)Convert.ToDouble(textBox4.Text); a.End = (int)Convert.ToDouble(textBox7.Text); var b = new Level(); b.Name = "B"; b.UpdateDate = DateTime.Now; b.Begin = (int)Convert.ToDouble(textBox5.Text); b.End = (int)Convert.ToDouble(textBox8.Text); _iLevelService.Create(b); var c = new Level(); c.Name = "C"; c.UpdateDate = DateTime.Now; c.Begin = (int)Convert.ToDouble(textBox6.Text); c.End = (int)Convert.ToDouble(textBox9.Text); _iLevelService.Create(c); _iLevelService.Save(); var successForm = new SuccessForm(); successForm.ShowDialog(); } catch (Exception ex) { var errorForm = new ErrorForm(ex.Message); errorForm.ShowDialog(); } }
private void button7_Click(object sender, EventArgs e) { try { var timesetting = _iTimeSettingService.GetAll().OrderByDescending(x => x.UpdateDate).FirstOrDefault(); if (timesetting != null) { timesetting.time = dateTimePicker5.Value; timesetting.UpdateDate = DateTime.Now; _iTimeSettingService.Update(timesetting); } else { timesetting = new TimeSetting(); timesetting.UpdateDate = DateTime.Now; timesetting.time = dateTimePicker5.Value; _iTimeSettingService.Create(timesetting); } _iTimeSettingService.Save(); var successForm = new SuccessForm(); successForm.ShowDialog(); } catch (Exception ex) { var errorForm = new ErrorForm(ex.Message); errorForm.ShowDialog(); } }
private void saveFileDialog2_FileOk(object sender, CancelEventArgs e) { try { string name = saveFileDialog2.FileName; var wb = new XSSFWorkbook(); using (FileStream stream = new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TemplateEfficiency.xlsx"), FileMode.Open, FileAccess.Read)) { wb = new XSSFWorkbook(stream); stream.Close(); } ISheet itemListSheet = wb.GetSheetAt(1); createItemList(itemListSheet, reportStart, reportEnd); ISheet timeTableSheet = wb.GetSheetAt(0); createTimeTable(timeTableSheet, reportStart, reportEnd); using (FileStream stream = new FileStream(name, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) { wb.Write(stream); stream.Close(); } var successForm = new SuccessForm(); successForm.ShowDialog(); } catch (Exception ex) { var errorForm = new ErrorForm(ex.Message); errorForm.ShowDialog(); } }