/// <summary> /// 保存报表 /// </summary> private void SaveReport() { HIS.MZ_BLL.StatDateType statDateType = HIS.MZ_BLL.StatDateType.自然时间; foreach (object item in Enum.GetValues(typeof(HIS.MZ_BLL.StatDateType))) { if (item.ToString() == cboStatDateType.Text) { statDateType = (HIS.MZ_BLL.StatDateType)item; break; } } if (dgvReport.DataSource == null) { return; } if (dgvReport.Rows.Count == 0) { return; } //从明细统计数据 short month = Convert.ToInt16(cboMonth.Text); short year = Convert.ToInt16(cboYear.Text); DateTime dateBegin, dateEnd; GetStatDate(statDateType, month, out dateBegin, out dateEnd); //判断当前日期是否在统计日期之后。之前业务数据还在发生改变,不让保存 DateTime currentDate = HIS.SYSTEM.PubicBaseClasses.XcDate.ServerDateTime; if (currentDate < dateEnd) { MessageBox.Show("当前时间还未到统计截止日,业务数据可能会发生改变,报表不能保存!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } DataTable tbData = (DataTable)dgvReport.DataSource; if (HIS.MZ_BLL.ReportClass.ReportExists(year, month, statType, reportType, statDateType)) { if (MessageBox.Show("当前报表已存在,是否覆盖现有报表?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } try { HIS.MZ_BLL.ReportClass.SaveReport(year, month, dateBegin, dateEnd, reportType, statType, statDateType, tbData, currentUser.Name); } catch (Exception err) { MessageBox.Show(err.Message, "保存", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 按指定年份和月份获取报表数据(从现有报表数据获取) /// </summary> /// <param name="dateBegin"></param> /// <param name="dateEnd"></param> /// <param name="byDetailData"></param> /// <returns></returns> private System.Data.DataTable GetReportData(int year, int month, HIS.MZ_BLL.StatDateType statDateType) { HIS.MZ_BLL.ReportClass report = null; DataTable tbData = null; report = new HIS.MZ_BLL.ReportClass(year, month, reportType, statType, statDateType); tbData = report.GetReportData(false); return(tbData); }
private void toolBar_ButtonClick(object sender, EventArgs e) { HIS.MZ_BLL.StatDateType statDateType = HIS.MZ_BLL.StatDateType.自然时间; foreach (object item in Enum.GetValues(typeof(HIS.MZ_BLL.StatDateType))) { if (item.ToString() == cboStatDateType.Text) { statDateType = (HIS.MZ_BLL.StatDateType)item; break; } } ToolStripButton ctrl = (ToolStripButton)sender; if (ctrl.Name == this.btnCreateReport.Name) { #region ... //从明细统计数据 short month = Convert.ToInt16(cboMonth.Text); DateTime dateBegin, dateEnd; GetStatDate(statDateType, month, out dateBegin, out dateEnd); try { DataTable dataReportData = GetReportData(dateBegin, dateEnd, statDateType); if (dataReportData == null) { return; } dgvReport.DataSource = FormatDataTable(dataReportData); SetGridDisplayStyle(); } catch (Exception err) { MessageBox.Show(err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion } if (ctrl.Name == btnClose.Name) { this.Close(); } if (ctrl.Name == btnView.Name) { ReportPrint(true); } if (ctrl.Name == btnPrint.Name) { ReportPrint(false); } if (ctrl.Name == btnSetting.Name) { string[] fixColumn = new string[] { "收费员", "合计" }; if (reportType == HIS.MZ_BLL.ReportType.医生科室收入月报表) { fixColumn = new string[] { "医生姓名", "科室名称", "合计" } } ; FrmReportSetting fSetting = new FrmReportSetting(this.FormTitle, fixColumn, statType, currentUser); fSetting.ShowDialog(); } } }
private void ShowReport( ) { HIS.MZ_BLL.StatDateType statDateType = HIS.MZ_BLL.StatDateType.自然时间; foreach (object item in Enum.GetValues(typeof(HIS.MZ_BLL.StatDateType))) { if (item.ToString( ) == cboStatDateType.Text) { statDateType = (HIS.MZ_BLL.StatDateType)item; break; } } short month = Convert.ToInt16(cboMonth.Text); short year = Convert.ToInt16(cboYear.Text); DateTime dateBegin, dateEnd; GetStatDate(statDateType, month, out dateBegin, out dateEnd); //判断当前报表是否存在 DataTable dataReportData = null; if (HIS.MZ_BLL.ReportClass.ReportExists(year, month, statType, reportType, statDateType)) { //获取并显示 dataReportData = GetReportData(year, month, statDateType); if (dataReportData == null) { MessageBox.Show(year.ToString( ) + "年" + month.ToString( ) + "月的" + this.FormTitle + "(" + statDateType.ToString() + ")不存在,请从明细获取数据", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (dgvReport.DataSource != null) { ((DataTable)dgvReport.DataSource).Rows.Clear( ); } return; } else { dgvReport.DataSource = FormatDataTable(dataReportData); SetGridDisplayStyle( ); } } else { //string msg = year.ToString( ) + "年" + month.ToString( ) + "月的" + this.FormTitle + "("+statDateType.ToString()+")不存在,请从明细获取数据" ; //如果报表没有汇总处理,则从明细统计数据 month = Convert.ToInt16(cboMonth.Text); GetStatDate(statDateType, month, out dateBegin, out dateEnd); try { dataReportData = GetReportData(dateBegin, dateEnd, statDateType); if (dataReportData == null) { return; } dgvReport.DataSource = FormatDataTable(dataReportData); SetGridDisplayStyle(); } catch (Exception err) { MessageBox.Show(err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } }
/// <summary> /// 获取统计时间 /// </summary> /// <param name="month"></param> /// <param name="dateBegin"></param> /// <param name="dateEnd"></param> private void GetStatDate(HIS.MZ_BLL.StatDateType statDateType, short month, out DateTime dateBegin, out DateTime dateEnd) { short year = Convert.ToInt16(cboYear.Text); short day = 0; string strEnd = ""; string strBegin = ""; dateBegin = DateTime.Now; dateEnd = DateTime.Now; try { switch (statDateType) { case HIS.MZ_BLL.StatDateType.统计日: day = Convert.ToInt16(txtDay.Text); strEnd = year.ToString( ) + "-" + month.ToString( ) + "-" + day.ToString( ) + " 23:59:59"; dateEnd = Convert.ToDateTime(strEnd); dateBegin = dateEnd.AddMonths(-1).AddDays(1); strBegin = dateBegin.ToString(strDateDateFormat) + " 00:00:00"; dateBegin = Convert.ToDateTime(strBegin); lblDate.Text = dateBegin.ToString(strDateFullFormat) + " — " + dateEnd.ToString(strDateFullFormat); break; case HIS.MZ_BLL.StatDateType.自然时间: day = 31; strBegin = year.ToString( ) + "-" + month.ToString( ) + "-01 00:00:00"; while (true) { try { strEnd = year.ToString( ) + "-" + month.ToString( ) + "-" + day.ToString( ) + " 23:59:59"; DateTime dtm = Convert.ToDateTime(strEnd); break; } catch { day--; } } dateBegin = Convert.ToDateTime(strBegin); dateEnd = Convert.ToDateTime(strEnd); lblDate.Text = dateBegin.ToString(strDateFullFormat) + " — " + dateEnd.ToString(strDateFullFormat); break; case HIS.MZ_BLL.StatDateType.交账时间: //获取本月交账起始时间 DateTime accBeginDate; DateTime accEndDate; HIS.MZ_BLL.ReportClass.GetAccountBeginAndEndDatebyMonth_MZ(year, month, out accBeginDate, out accEndDate); //由交账起始时间获取明细数据时间 HIS.MZ_BLL.ReportClass.GetDetailBeginAndEndDatebyAccount_MZ(accBeginDate, accEndDate, out dateBegin, out dateEnd); lblDate.Text = accBeginDate.ToString(strDateFullFormat) + " — " + accEndDate.ToString(strDateFullFormat); break; case HIS.MZ_BLL.StatDateType.自定义时间: dateBegin = dtpFrom.Value; dateEnd = dtpTo.Value; lblDate.Text = dateBegin.ToString(strDateFullFormat) + " — " + dateEnd.ToString(strDateFullFormat); break; default: throw new Exception("错误的统计时间类型"); return; } } catch (Exception err) { MessageBox.Show(err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 按指定时间获取报表数据(从明细数据获取) /// </summary> /// <param name="dateBegin"></param> /// <param name="dateEnd"></param> /// <returns></returns> private System.Data.DataTable GetReportData(DateTime dateBegin, DateTime dateEnd, HIS.MZ_BLL.StatDateType statDateType) { HIS.MZ_BLL.ReportClass report = null; DataTable tbData = null; report = new HIS.MZ_BLL.ReportClass(dateBegin, dateEnd, reportType, statType, statDateType); tbData = report.GetReportData(true); return(tbData); }