protected void btnExcels_Click(object sender, EventArgs e) { try { if (gvDetail.Rows.Count <= 0) { return; } int currentrowindex = (int)ViewState["currentrowindex"]; string billheadid = gvList.Rows[currentrowindex].Values[0].ToString(); List <Billdetail> detailprintList = billdetailService.SelectBilldetailInfoList(billheadid).ToList(); //设置导出excel列头内容 SortedList sortedList = new SortedList(new MySort()); sortedList.Add("Status", "状态"); sortedList.Add("Enterdate", "接收日期"); sortedList.Add("Ordernum", "体检流水号"); sortedList.Add("Realname", "病人姓名"); sortedList.Add("Testcount", "项目数量"); sortedList.Add("Testname", "项目清单"); sortedList.Add("Standardprice", "标准收费"); sortedList.Add("Groupprice", "分点收费"); sortedList.Add("Contractprice", "应收金额"); sortedList.Add("Finalprice", "实收金额"); sortedList.Add("Selfremark", "财务说明"); sortedList.Add("Remark", "财务备注"); string filename = "已接收明细信息" + DateTime.Now.Date.ToString("yyyyMMdd"); ExcelOperation <Billdetail> .ExportListToExcel(detailprintList, sortedList, filename, "sheet1"); } catch (Exception ex) { MessageBoxShow(ex.Message, MessageBoxIcon.Error); } }
/// <summary> /// 财务打印 /// </summary> /// <param name="htinfo">报告单明细信息</param> /// <param name="flag">报告单数据来源标示:团检、现金接收</param> /// <param name="strwhere">获得打印明细信息的查询条件</param> /// <param name="checkbillid">财务清单核对人编号</param> /// <param name="dictlabid">分点编号</param> /// <returns>dataset:报告单数据集</returns> public DataSet ConvertToDataSet(Hashtable htinfo, string strwhere, string flag, double?checkbillid, double?dictlabid, string sendout) { try { LoginService loginService = new LoginService(); BilldetailService detailservice = new BilldetailService(); BillheadService headservice = new BillheadService(); IList <Billhead> headlist = null; IList <Billdetail> detailList = null; DataSet ds = new DataSet(); //获得打印明细信息 if (flag == "billdetail") //团检 { if (sendout == "nosendout") { detailList = detailservice.SelectBilldetailInfoList(strwhere); } else if (sendout == "sendout") { detailList = detailservice.SelectSendOutBillDetailInfoPrint(strwhere); } } else //现金接收 { headlist = headservice.SelectBillHeadListForPrintByids(strwhere); } #region 设置报告单中间明细信息 //生成财务账单详细信息 DataTable dt = new DataTable("tbdetail"); DataColumn column; DataRow dr = dt.NewRow(); column = new DataColumn("Orderenterdate"); dt.Columns.Add(column); column = new DataColumn("Ordernum"); dt.Columns.Add(column); column = new DataColumn("Realname"); dt.Columns.Add(column); column = new DataColumn("Productname"); dt.Columns.Add(column); column = new DataColumn("Standardprice"); dt.Columns.Add(column); column = new DataColumn("Finalprice"); dt.Columns.Add(column); column = new DataColumn("Remark"); dt.Columns.Add(column); if (detailList != null) { foreach (Billdetail detail in detailList) { dr = dt.NewRow(); dr["Orderenterdate"] = detail.Orderenterdate.Value.ToString("yyyy-MM-dd"); dr["Ordernum"] = detail.Ordernum; dr["Realname"] = detail.Realname; dr["Productname"] = detail.Productname; dr["Standardprice"] = detail.Standardprice; dr["Finalprice"] = detail.Finalprice; dr["Remark"] = detail.Remark; dt.Rows.Add(dr); } } else if (headlist != null) { foreach (Billhead head in headlist) { dr = dt.NewRow(); dr["Orderenterdate"] = head.Orderenterdate.Value.ToString("yyyy-MM-dd"); dr["Ordernum"] = head.Ordernum; dr["Realname"] = head.Realname; dr["Productname"] = head.Productname; dr["Standardprice"] = head.Totalstandardprice; dr["Finalprice"] = head.Totalfinalprice; dr["Remark"] = head.Remark; dt.Rows.Add(dr); } } ds.Tables.Add(dt); #endregion //获得销售人员、清单核对人、分点信息 List <Dictuser> userlist = new List <Dictuser>(); List <Dictlab> labList = new List <Dictlab>(); List <Dictuser> usercheck = new List <Dictuser>(); List <Dictuser> usersale = new List <Dictuser>(); List <Dictcustomer> customer = new List <Dictcustomer>(); userlist = loginService.GetDictuser(); labList = loginService.GetLoginDictlab(); List <Dictlab> dictLabList = (from a in labList where a.Dictlabid == dictlabid select a).ToList <Dictlab>(); if (flag == "billdetail") { usercheck = (from a in userlist where a.Dictuserid == checkbillid select a).ToList <Dictuser>(); } else { //获取"个人客户"基本信息 List <Dictcustomer> customerList = loginService.GetDictcustomer(); int customercode = (int)ParamStatus.PersonalCustomerID.SingleCustomerCode; customer = (from a in customerList where a.Customercode == customercode.ToString() select a).ToList(); if (customer.Count > 0) { usercheck = (from a in userlist where a.Dictuserid == customer[0].Dictcheckbillid select a).ToList(); usersale = (from a in userlist where a.Dictuserid == customer[0].Dictsalemanid select a).ToList(); } } #region 设置报告单头尾信息 //生成财务账单头尾信息 DataTable dtinfo = new DataTable("headinfo"); DataColumn headcolumn; DataRow headrow = dtinfo.NewRow(); headcolumn = new DataColumn("customername"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("salename"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("checkbillname"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("phone"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("fax"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("website"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("totalstandardprice"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("totalfinalprice"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("begindate"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("enddate"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("customertype"); dtinfo.Columns.Add(headcolumn); headcolumn = new DataColumn("ordernumcount"); dtinfo.Columns.Add(headcolumn); if (flag == "billdetail") { headrow["customername"] = htinfo["customername"]; headrow["salename"] = htinfo["salename"]; headrow["totalstandardprice"] = detailList.Sum(c => c.Standardprice); headrow["totalfinalprice"] = detailList.Sum(c => c.Finalprice); headrow["ordernumcount"] = detailList.Count; } else { headrow["customername"] = customer.Count > 0 ? customer[0].Customername : ""; headrow["salename"] = usersale.Count > 0 ? usersale[0].Username : ""; headrow["totalstandardprice"] = headlist.Sum(c => c.Totalstandardprice); headrow["totalfinalprice"] = headlist.Sum(c => c.Totalfinalprice); headrow["ordernumcount"] = headlist.Count; } headrow["phone"] = ""; headrow["fax"] = ""; if (dictLabList.Count > 0) { if (!string.IsNullOrEmpty(dictLabList[0].Phone)) { headrow["phone"] = "Tel:" + dictLabList[0].Phone; } if (!string.IsNullOrEmpty(dictLabList[0].Fax)) { headrow["fax"] = "Fax:" + dictLabList[0].Fax; } } headrow["website"] = dictLabList.Count > 0 ? dictLabList[0].Website : ""; headrow["checkbillname"] = usercheck.Count > 0 ? usercheck[0].Username : ""; headrow["begindate"] = htinfo["begindate"]; headrow["enddate"] = htinfo["enddate"]; headrow["customertype"] = htinfo["customertype"]; dtinfo.Rows.Add(headrow); ds.Tables.Add(dtinfo); #endregion string titlename = htinfo["titleName"].ToString(); #region 设置标题 DataTable dtt = new DataTable("dtTitle"); DataRow dtr; DataColumn dtc; dtc = new DataColumn("titleName"); dtt.Columns.Add(dtc); dtr = dtt.NewRow(); dtr["titleName"] = titlename; dtt.Rows.Add(dtr); ds.Tables.Add(dtt); #endregion return(ds); } catch { return(null); } }