private void SaveJobAction() { DataTable souceJobData = null; DataTable gridJobData = null; List <Job> jobs = null; try { int rowCount = jobGridView.RowCount; string jobxmlfileFullPath = Miscellaneous.GetJobXMLFullPath(); //MessageBox.Show(jobxmlfileFullPath); souceJobData = XMLHelper.GetJobsDataTable(); gridJobData = DatagridviewHelper.ConvertDataGridViewToTable(jobGridView); bool isSame = DatagridviewHelper.CompareDataTable(souceJobData, gridJobData, "JobName"); if (!isSame) { jobs = DataInit.CovertJobTableToLists(gridJobData); XMLHelper.UpdateJobNodes(jobxmlfileFullPath, jobs); //for (int index = 0; index < rowCount - 1; index++) //{ // string jobTitle = jobGridView.Rows[index].Cells[0].Value.ToString(); // string jobRating = jobGridView.Rows[index].Cells[1].Value.ToString(); // string id = jobGridView.Rows[index].Cells[2].Value.ToString(); // if (!string.IsNullOrEmpty(jobTitle) && !string.IsNullOrEmpty(jobRating)) // { // Job job = new Job(); // job.JobName = jobTitle; // job.JobIndex = jobRating; // //it's a new row if empty // if (string.IsNullOrEmpty(id)) // { // DataInit.AddJobNode(jobxmlfileFullPath, job); // } // else // { // job.Id = id; // DataInit.UpdateJobNode(jobxmlfileFullPath, "Jobs", job); // } // } // else // { // MessageBox.Show("岗位名称或者岗位系数不能为空", "保存失败"); // } //} } } catch (Exception ex) { MessageBox.Show("数据保存错误:" + ex.Message, "系统错误提示"); } finally { souceJobData = null; gridJobData = null; jobs = null; } }
void btnPrint_Click(object sender, EventArgs e) { try { lable_message.Visible = true; lable_message.Text = "正在保存,请稍等...."; DateTime dtMonthCal = monthCalendarMain.SelectionStart; DateTime startWeek = dtMonthCal.AddDays(1 - Convert.ToInt16(dtMonthCal.DayOfWeek.ToString("d"))); List <string> weekdays = Miscellaneous.GenerateWeekDaysList(startWeek); //PrintHelper print = new PrintHelper(); //DataSet ds = new DataSet(); DataTable dt = DatagridviewHelper.ConvertDataGridViewToTable(dataGridView_home); //is updated? //DateTime dt_month = monthCalendarMain.SelectionStart; //DateTime startWeek = dt_month.AddDays(1 - Convert.ToInt16(dt_month.DayOfWeek.ToString("d"))); string fileXmlFullPath = Miscellaneous.GetSchedulerXMLFullPath(startWeek.ToString("yyyyMMdd")); DataTable sourceTable = LoadHomeSchedules(fileXmlFullPath); //比较两个datatable, 如果不相同则先保存再打印 bool isSame = DatagridviewHelper.CompareDataTable(dt, sourceTable, "姓名"); if (!isSame) { ScheduleSaveAction(); } //ds.Tables.Add(dt); string tempExcelPath = Miscellaneous.GetScheduleTempExcelFile(); if (String.IsNullOrEmpty(tempExcelPath)) { MessageBox.Show("排班模板Excel文件不存在,请指定正确路径再保存为Excel", "文件检查失败"); } else { ExcelHelper.DataTableToExcelForSchedule(Miscellaneous.GetScheduleTempExcelFile(), dt, weekdays); //NPOIHelper.DataTableToExcelForSchedule_NPOI(tempExcelPath, dt, weekdays); MessageBox.Show("保存Excel文件成功", "文件保存成功"); } } catch (Exception ex) { MessageBox.Show("保存文件出错:" + ex.Message, "文件检查失败"); } finally { lable_message.Text = string.Empty; lable_message.Visible = false; } }
void btnExportReport_Click(object sender, EventArgs e) { try { lable_message.Text = "正在导出,请稍等..."; lable_message.Visible = true; DateTime datetime = datePickerReporing.Value; //string filePath = Miscellaneous.GetExcelsFileFullPath(string.Format("绩效统计-{0}.xlsx", datetime.ToString("yyyy-MM"))); string filePath = Miscellaneous.GetExcelsFileFullPath(string.Format("绩效统计-{0}.xls", datetime.ToString("yyyy-MM"))); DataTable dt = DatagridviewHelper.ConvertDataGridViewToTable(dataGridReporting); ExcelHelper.WriteExcel(filePath, this.dataGridReporting); MessageBox.Show("导出成功", "提示消息"); } catch (Exception ex) { MessageBox.Show("导出失败:" + ex.Message, "操作失败"); } finally { lable_message.Text = string.Empty; lable_message.Visible = false; } }