public void ActiveTabIndividualQuery(string ybh) { string tabPageText = string.Empty; if (!string.IsNullOrEmpty(ybh)) { PMS.BLL.MedicarePerson bll_person = new PMS.BLL.MedicarePerson(); PMS.Model.MedicarePerson person = bll_person.GetMedicarePerson(ybh); tabPageText = person.Name + ybh; } else { tabPageText = "个人报销记录查询"; } bool hasYbh = false; foreach (TabPage tabPage in tabWorkSpace.TabPages) { if (tabPage.Text == tabPageText) { tabWorkSpace.SelectedTab = tabPage; hasYbh = true; } } if (hasYbh == false) { TabPage tabPage = new TabPage(tabPageText); UC.IndividualQuery iq = new UC.IndividualQuery(); iq.SetYbh(this.ybh); tabPage.Controls.Clear(); tabPage.Controls.Add(iq as Control); tabPage.ToolTipText = "双击可关闭选项卡"; iq.Dock = DockStyle.Fill; tabWorkSpace.TabPages.Add(tabPage); tabWorkSpace.SelectedTab = tabPage; } }
private void btnExportExcel_Click(object sender, EventArgs e) { if (gvPaymentList.Rows.Count > 0) { beginDate = dtpBeginDate.Value.Date; endDate = dtpEndDate.Value.AddDays(1).Date; IList <MRS.Model.AccountBook> accountBooks = new List <MRS.Model.AccountBook>(); accountBooks = bllAccountBook.Select_AccountBook_PaymentList(beginDate, endDate); System.Text.StringBuilder fileName = new StringBuilder(); fileName.Append("医保报销帐单 "); fileName.Append(DateTime.Now.Year.ToString()); fileName.Append(DateTime.Now.Month.ToString().PadLeft(2, '0')); fileName.Append(DateTime.Now.Day.ToString().PadLeft(2, '0')); fileName.Append(".xls"); XlsDocument xlsDoc = new XlsDocument(); xlsDoc.FileName = fileName.ToString(); //定义Excel文档属性. xlsDoc.SummaryInformation.Author = "Cobe lee"; xlsDoc.SummaryInformation.Title = "医保报销帐单"; xlsDoc.SummaryInformation.Comments = "This workbook generated by ZPITC! http://www.tiyi.biz"; xlsDoc.SummaryInformation.Subject = "医保报销帐单"; xlsDoc.DocumentSummaryInformation.Company = "镇海石化工业贸易有限责任公司"; Worksheet sheet = xlsDoc.Workbook.Worksheets.Add("Sheet1"); xlsDoc.Workbook.Worksheets.Add("Sheet2"); xlsDoc.Workbook.Worksheets.Add("Sheet3"); Cells cells = sheet.Cells; //以下定义 银行帐号 及 身份证号 的列宽. ColumnInfo col0 = new ColumnInfo(xlsDoc, sheet); col0.ColumnIndexEnd = 0; col0.ColumnIndexStart = 0; col0.Width = 21 * 269; sheet.AddColumnInfo(col0); ColumnInfo col3 = new ColumnInfo(xlsDoc, sheet); col3.ColumnIndexEnd = 3; col3.ColumnIndexStart = 3; col3.Width = 21 * 269; sheet.AddColumnInfo(col3); //以下定义文档标题 副标题 int rint = 1; cells.Merge(rint, rint, 1, 5); Cell cell = cells.Add(rint, 1, "医保报销帐单"); cell.Font.Height = 16 * 20; cell.HorizontalAlignment = HorizontalAlignments.Centered; rint++; cells.Merge(rint, rint, 1, 5); Cell cell2 = cells.Add(rint, 1, "( " + beginDate.ToShortDateString() + "至" + dtpEndDate.Value.ToShortDateString() + " )"); cell2.Font.Height = 12 * 20; cell2.Font.FontName = "宋体"; cell2.HorizontalAlignment = HorizontalAlignments.Centered; rint++; FormatHead(cells.Add(rint, 1, "银行帐号")); FormatHead(cells.Add(rint, 2, "金额")); FormatHead(cells.Add(rint, 3, "姓名")); FormatHead(cells.Add(rint, 4, "身份证号")); FormatHead(cells.Add(rint, 5, "备注")); foreach (MRS.Model.AccountBook account in accountBooks) { rint++; PMS.BLL.MedicarePerson bll_mp = new PMS.BLL.MedicarePerson(); string bankAccount = bll_mp.GetMedicarePerson(account.YBH).BankAccount; if (bankAccount != null) { FormatCellNumber(cells.Add(rint, 1, bankAccount)); FormatCellAmount(cells.Add(rint, 2, Convert.ToDouble(account.BXJE))); FormatCellName(cells.Add(rint, 3, account.Name)); FormatCellNumber(cells.Add(rint, 4, account.IdentityCard)); FormatCellName(cells.Add(rint, 5, "报销")); } } rint++; FormatCellButtom(cells.Add(rint, 1, "")); FormatCellButtom(cells.Add(rint, 2, "")); FormatCellButtom(cells.Add(rint, 3, "")); FormatCellButtom(cells.Add(rint, 4, "")); FormatCellButtom(cells.Add(rint, 5, "")); saveFileDialog1.DefaultExt = "xls"; saveFileDialog1.FileName = fileName.ToString(); saveFileDialog1.Filter = "Excel 97-2003 工作簿(*.xls)|*.xls"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { string path = System.IO.Path.GetDirectoryName(saveFileDialog1.FileName); try { xlsDoc.Save(path, true); } catch { MessageBox.Show("文件 \"" + System.IO.Path.GetFileName(saveFileDialog1.FileName) + "\" 正被其它程序打开,\n请关闭该文件,并重试!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("无医保报销帐单!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }