/// <summary> /// 删除处方 /// </summary> /// <param name="PrescriptionId">要删除的处方ID</param> /// <returns>被删除的处方数</returns> public int DeletePrescription(int PrescriptionId) { MZ_PresMaster mz_presmaster = BindEntity <MZ_PresMaster> .CreateInstanceDAL(oleDb).GetModel(PrescriptionId); if (mz_presmaster.Charge_Flag == 1) { throw new OperatorException("该处方已经收费,不能删除!"); } oleDb.BeginTransaction( ); try { int effectRow = 0; List <MZ_PresOrder> detail = BindEntity <MZ_PresOrder> .CreateInstanceDAL(oleDb).GetListArray("PRESMASTERID=" + PrescriptionId); for (int i = 0; i < detail.Count; i++) { BindEntity <MZ_PresOrder> .CreateInstanceDAL(oleDb).Delete(((MZ_PresOrder)detail[i]).PresOrderID); effectRow++; } BindEntity <MZ_PresMaster> .CreateInstanceDAL(oleDb).Delete(PrescriptionId); effectRow++; oleDb.CommitTransaction( ); return(effectRow); } catch (Exception err) { oleDb.RollbackTransaction( ); ErrorWriter.WriteLog(err.Message); return(0); } }
/// <summary> /// 删除处方明细 /// </summary> /// <param name="PrescriptionDetailId">要删除的明细ID</param> /// <returns>被删除的处方明细数</returns> public int DeletePrescriptionDetail(int PrescriptionDetailId) { MZ_PresOrder mz_presorder = BindEntity <MZ_PresOrder> .CreateInstanceDAL(oleDb).GetModel(PrescriptionDetailId); MZ_PresMaster mz_presmaster = BindEntity <MZ_PresMaster> .CreateInstanceDAL(oleDb).GetModel(mz_presorder.PresMasterID); if (mz_presmaster.Charge_Flag == 1) { throw new OperatorException("该处方已经收费,不能删除!"); } oleDb.BeginTransaction( ); try { int effectRow = 0; MZ_PresOrder detail = BindEntity <MZ_PresOrder> .CreateInstanceDAL(oleDb).GetModel(PrescriptionDetailId); BindEntity <MZ_PresOrder> .CreateInstanceDAL(oleDb).Delete(detail.PresOrderID); effectRow++; oleDb.CommitTransaction( ); return(effectRow); } catch (Exception err) { oleDb.RollbackTransaction( ); ErrorWriter.WriteLog(err.Message); return(0); } }
private static void update_mz_presmaster(MZ_PresMaster mz_presmaster) { string update = "update " + "MZ_PRESMASTER" + " set " + Tables.mz_presmaster.CHARGE_FLAG + "=" + "" + mz_presmaster.Charge_Flag + "" + "," + Tables.mz_presmaster.CHARGECODE + "=" + "'" + mz_presmaster.ChargeCode + "'" + "," + Tables.mz_presmaster.COSTMASTERID + "=" + "" + mz_presmaster.CostMasterID + "" + "," + Tables.mz_presmaster.DRUG_FLAG + "=" + "" + mz_presmaster.Drug_Flag + "" + "," + Tables.mz_presmaster.EXECDEPTCODE + "=" + "'" + mz_presmaster.ExecDeptCode + "'" + "," + Tables.mz_presmaster.EXECDOCCODE + "=" + "'" + mz_presmaster.ExecDocCode + "'" + "," + Tables.mz_presmaster.HAND_FLAG + "=" + "" + mz_presmaster.Hand_Flag + "" + "," + Tables.mz_presmaster.OLDID + "=" + "" + mz_presmaster.OldID + "" + "," + Tables.mz_presmaster.PATID + "=" + "" + mz_presmaster.PatID + "" + "," + Tables.mz_presmaster.PATLISTID + "=" + "" + mz_presmaster.PatListID + "" + "," + Tables.mz_presmaster.PRESAMOUNT + "=" + "" + mz_presmaster.PresAmount + "" + "," + Tables.mz_presmaster.PRESCOSTCODE + "=" + "'" + mz_presmaster.PresCostCode + "'" + "," + Tables.mz_presmaster.PRESDATE + "=" + "#" + mz_presmaster.PresDate + "#" + "," + Tables.mz_presmaster.PRESDEPTCODE + "=" + "'" + mz_presmaster.PresDeptCode + "'" + "," + Tables.mz_presmaster.PRESDOCCODE + "=" + "'" + mz_presmaster.PresDocCode + "'" + "," + Tables.mz_presmaster.PRESTYPE + "=" + "'" + mz_presmaster.PresType + "'" + "," + Tables.mz_presmaster.RECORD_FLAG + "=" + "" + mz_presmaster.Record_Flag + "" + "," + Tables.mz_presmaster.REDEEMCOST + "=" + "" + mz_presmaster.RedeemCost + "" + "," + Tables.mz_presmaster.ROUNGINGMONEY + "=" + "" + mz_presmaster.RoungingMoney + "" + "," + Tables.mz_presmaster.TICKETCODE + "=" + "'" + mz_presmaster.TicketCode + "'" + "," + Tables.mz_presmaster.TICKETNUM + "=" + "'" + mz_presmaster.TicketNum + "'" + "," + Tables.mz_presmaster.TOTAL_FEE + "=" + "" + mz_presmaster.Total_Fee + "" + " where " + Tables.mz_presmaster.PRESMASTERID + "=" + mz_presmaster.PresMasterID; Execute(update); }
/// <summary> /// 删除处方明细 /// </summary> /// <param name="PrescriptionDetailId">要删除的明细ID</param> /// <returns>被删除的处方明细数</returns> public int DeletePrescriptionDetail(int PrescriptionDetailId) { MZ_PresOrder mz_presorder = (MZ_PresOrder)MSAccessDb.GetModel("MZ_PRESORDER", Tables.mz_presorder.PRESORDERID + "=" + PrescriptionDetailId, typeof(MZ_PresOrder)); MZ_PresMaster mz_presmaster = (MZ_PresMaster)MSAccessDb.GetModel("MZ_PRESMASTER", Tables.mz_presmaster.PRESMASTERID + "=" + mz_presorder.PresMasterID, typeof(MZ_PresMaster)); if (mz_presmaster.Charge_Flag == 1) { throw new Exception("该处方已经收费,不能删除!"); } MSAccessDb.BeginTrans( ); try { int effectRow = 0; MZ_PresOrder detail = (MZ_PresOrder)MSAccessDb.GetModel("MZ_PRESORDER", Tables.mz_presorder.PRESORDERID + "=" + PrescriptionDetailId, typeof(MZ_PresOrder)); MSAccessDb.Execute("delete * from mz_presorder where presorderid=" + detail.PresOrderID); effectRow++; MSAccessDb.CommitTrans( ); return(effectRow); } catch (Exception err) { MSAccessDb.RollbackTrans( ); return(0); } }
/// <summary> /// 删除处方 /// </summary> /// <param name="PrescriptionId">要删除的处方ID</param> /// <returns>被删除的处方数</returns> public int DeletePrescription(int PrescriptionId) { //MZ_PresMaster mz_presmaster = BindEntity<MZ_PresMaster>.CreateInstanceDAL( oleDb ).GetModel( PrescriptionId ); MZ_PresMaster mz_presmaster = (MZ_PresMaster)MSAccessDb.GetModel("MZ_PRESMASTER", Tables.mz_presmaster.PRESMASTERID + "=" + PrescriptionId, typeof(MZ_PresMaster)); if (mz_presmaster.Charge_Flag == 1) { throw new Exception("该处方已经收费,不能删除!"); } MSAccessDb.BeginTrans( ); try { int effectRow = 0; List <HIS.Model.MZ_PresOrder> detail = MSAccessDb.GetListArray <MZ_PresOrder>("MZ_PRESORDER", "PRESMASTERID=" + PrescriptionId); for (int i = 0; i < detail.Count; i++) { MSAccessDb.Execute("delete * from mz_presorder where presorderid=" + ((HIS.Model.MZ_PresOrder)detail[i]).PresOrderID); effectRow++; } MSAccessDb.Execute("delete * from mz_presmaster where presmasterid = " + PrescriptionId); effectRow++; MSAccessDb.CommitTrans( ); return(effectRow); } catch { MSAccessDb.RollbackTrans( ); return(0); } }
/// <summary> /// 更新本次就诊登记信息 /// </summary> /// <returns>成功标识;true</returns> public bool UpdateRegister() { //HIS.SYSTEM.DatabaseAccessLayer.OleDB oleDB = new HIS.SYSTEM.DatabaseAccessLayer.OleDB( ); //oleDB.Initialize( ); try { //HIS.DAL.MZ_PatList mz_patList = new HIS.DAL.MZ_PatList( ); //mz_patList._OleDB = oleDB; HIS.Model.MZ_PatList register = (MZ_PatList)MSAccessDb.GetModel("MZ_PATLIST", Tables.mz_patlist.PATLISTID + "=" + this.PatListID, typeof(MZ_PatList)); register.CureDeptCode = _cureDeptCode; //就诊科室 register.CureEmpCode = _cureEmpCode; //就诊医生 register.DiseaseCode = _diseaseCode; //疾病代码 if (register.REG_DOC_CODE.Trim( ) == "") { //如果挂号医生为空,则将挂号医生更改为当前就诊医生 register.REG_DOC_CODE = _cureEmpCode; register.REG_DOC_NAME = DataReader.GetEmployeeNameById(Convert.ToInt32(_cureEmpCode)); register.REG_DEPT_CODE = _cureDeptCode; register.REG_DEPT_NAME = DataReader.GetDeptNameById(Convert.ToInt32(_cureDeptCode)); } register.DiseaseName = _diseaseName.Replace("|", "") + "|" + _diseaseMemo.Replace("|", ""); //疾病名称 register.HpCode = _hpCode; //就医机构代码 register.HpGrade = _hpGrade; //就医机构级别 register.MediCard = _mediCard; //医疗证卡号 register.MediType = _mediType; //就诊类型 register.PatCode = ""; //病人代码???? register.PatID = this.PatID; //病人ID,如果是普通病人,则为0;否则参见PatientInfo.PatID; register.PatListID = this.PatListID; //本次就诊号 register.PatName = this.PatientName; //病人姓名 register.PatSex = this.Sex; //性别 register.PYM = this.PYM; //拼音码 register.WBM = this.WBM; //五笔码 register.Age = this.Age; //年龄 register.VisitNo = this.VisitNo; //就诊号(门诊号) MSAccessDb.UpdateRecord(register); //将处方表中挂号的记录改为处方医生 string strWhere = Tables.mz_presmaster.PATLISTID + "=" + this.PatListID + " and " + Tables.mz_presmaster.HAND_FLAG + "= 0"; MZ_PresMaster mz_presmaster = (MZ_PresMaster)MSAccessDb.GetModel("MZ_PRESMASTER", strWhere, typeof(MZ_PresMaster)); if (mz_presmaster != null) { if (mz_presmaster.PresDocCode == null || mz_presmaster.PresDocCode.Trim( ) == "") { strWhere += " and " + Tables.mz_presmaster.PRESMASTERID + "=" + mz_presmaster.PresMasterID; MSAccessDb.UpdateRecord(new string[] { Tables.mz_presmaster.PRESDOCCODE + "=" + "'" + _cureEmpCode + "'", Tables.mz_presmaster.PRESDEPTCODE + "=" + "'" + _cureDeptCode + "'" }, strWhere, typeof(MZ_PresMaster)); } } return(true); } catch (Exception err) { throw new Exception("更新病人等级信息发生错误!"); } }
private static int insert_mz_presmaster(MZ_PresMaster mz_presmaster) { string insert = "insert into mz_presmaster(" + Tables.mz_presmaster.PRESMASTERID + "," + Tables.mz_presmaster.CHARGE_FLAG + "," + Tables.mz_presmaster.CHARGECODE + "," + Tables.mz_presmaster.DRUG_FLAG + "," + Tables.mz_presmaster.EXECDEPTCODE + "," + Tables.mz_presmaster.EXECDOCCODE + "," + Tables.mz_presmaster.HAND_FLAG + "," + Tables.mz_presmaster.PATID + "," + Tables.mz_presmaster.PATLISTID + "," + Tables.mz_presmaster.PRESAMOUNT + "," + Tables.mz_presmaster.PRESCOSTCODE + "," + Tables.mz_presmaster.PRESDATE + "," + Tables.mz_presmaster.PRESDEPTCODE + "," + Tables.mz_presmaster.PRESDOCCODE + "," + Tables.mz_presmaster.COSTMASTERID + "," + Tables.mz_presmaster.PRESTYPE + "," + Tables.mz_presmaster.RECORD_FLAG + "," + Tables.mz_presmaster.REDEEMCOST + "," + Tables.mz_presmaster.ROUNGINGMONEY + "," + Tables.mz_presmaster.TICKETCODE + "," + Tables.mz_presmaster.TICKETNUM + "," + Tables.mz_presmaster.TOTAL_FEE + ")"; string values = "values (" + mz_presmaster.PresMasterID + "," + "" + mz_presmaster.Charge_Flag + "," + "'" + mz_presmaster.ChargeCode + "'," + "" + mz_presmaster.Drug_Flag + "," + "'" + mz_presmaster.ExecDeptCode + "'," + "'" + mz_presmaster.ExecDocCode + "'," + "" + mz_presmaster.Hand_Flag + "," + "" + mz_presmaster.PatID + "," + "" + mz_presmaster.PatListID + "," + "" + mz_presmaster.PresAmount + "," + "'" + mz_presmaster.PresCostCode + "'," + "#" + mz_presmaster.PresDate + "#," + "'" + mz_presmaster.PresDeptCode + "'," + "'" + mz_presmaster.PresDocCode + "'," + "" + mz_presmaster.CostMasterID + "," + "'" + mz_presmaster.PresType + "'," + "" + mz_presmaster.Record_Flag + "," + "" + mz_presmaster.RedeemCost + "," + "" + mz_presmaster.RoungingMoney + "," + "'" + mz_presmaster.TicketCode + "'," + "'" + mz_presmaster.TicketNum + "'," + "" + mz_presmaster.Total_Fee + ")"; int effectrow = Execute(insert + " " + values); return(mz_presmaster.PresMasterID); }
/// <summary> /// 复制处方到指定的病人 /// </summary> /// <param name="PrescriptionId">目标处方ID</param> /// <param name="patient">目标病人</param> /// <returns></returns> public bool CopyPrescription(int PrescriptionId, BasePatient patient) { MZ_PresMaster mz_presmaster = BindEntity <MZ_PresMaster> .CreateInstanceDAL(oleDb).GetModel(PrescriptionId); if (mz_presmaster == null) { throw new Exception("没有找到处方,请确认处方是否存在!"); } List <MZ_PresOrder> lstPresOrder = BindEntity <MZ_PresOrder> .CreateInstanceDAL(oleDb).GetListArray(Tables.mz_presorder.PRESMASTERID + oleDb.EuqalTo( ) + PrescriptionId); if (lstPresOrder.Count == 0) { throw new Exception("该处方没有明细,不能复制!"); } try { mz_presmaster.Charge_Flag = 0; mz_presmaster.ChargeCode = ""; mz_presmaster.CostMasterID = 0; mz_presmaster.Drug_Flag = 0; mz_presmaster.OldID = 0; mz_presmaster.PresDate = HIS.SYSTEM.PubicBaseClasses.XcDate.ServerDateTime; mz_presmaster.Record_Flag = 0; mz_presmaster.TicketCode = ""; mz_presmaster.TicketNum = ""; if (patient != null) { mz_presmaster.PatID = patient.PatID; mz_presmaster.PatListID = patient.PatListID; } oleDb.BeginTransaction( ); BindEntity <MZ_PresMaster> .CreateInstanceDAL(oleDb).Add(mz_presmaster); foreach (MZ_PresOrder order in lstPresOrder) { order.PresMasterID = mz_presmaster.PresMasterID; BindEntity <MZ_PresOrder> .CreateInstanceDAL(oleDb).Add(order); } oleDb.CommitTransaction( ); return(true); } catch (Exception err) { oleDb.RollbackTransaction( ); ErrorWriter.WriteLog(err.Message + "\r\n" + err.StackTrace); throw new Exception("复制处方发生错误!详情请参考log日志!"); } }
/// <summary> /// 预算 /// </summary> /// <param name="prescriptions">要预算的处方</param> /// <returns>预算信息,供正式结算用</returns> public override ChargeInfo[] Budget(Prescription[] prescriptions) { //单张处方明细转化为大项目明细合并后累加在取舍。 //保存每张处方的大项目明细 List <List <Item> > lstStatItems = new List <List <Item> >( ); //本次结算总金额(等于每张处方舍入后的金额的合计) decimal chargeTotalCost = 0; #region 合并大类并计算舍入金额 try { for (int i = 0; i < prescriptions.Length; i++) { List <Item> lstTemp = new List <Item>( ); lstTemp = MergePrescriptionByStatItemCode(ref prescriptions[i]); chargeTotalCost = chargeTotalCost + prescriptions[i].Total_Fee; lstStatItems.Add(lstTemp); } } catch (Exception err) { throw new Exception("合并项目发生错误!"); } #endregion //保存合并后的所有大项目明细,类型MZ_CostOrder Hashtable htCostOrder = new Hashtable(); #region 合并所有结算明细(不需要再舍入) try { foreach (List <Item> lstTemp in lstStatItems) { foreach (object obj in lstTemp) { if (htCostOrder.ContainsKey(((Item)obj).Text.Trim( ))) { Item item = (Item)obj; MZ_CostOrder mz_costorder = (MZ_CostOrder)htCostOrder[item.Text.Trim( )]; mz_costorder.Total_Fee = mz_costorder.Total_Fee + Convert.ToDecimal(item.Value); } else { MZ_CostOrder mz_costorder = new HIS.Model.MZ_CostOrder( ); mz_costorder.ItemType = ((Item)obj).Text.Trim( ); mz_costorder.Total_Fee = Convert.ToDecimal(((Item)obj).Value); htCostOrder.Add(mz_costorder.ItemType, mz_costorder); } } } } catch (Exception err) { throw new Exception("合并明细大类发生错误!"); } #endregion int costmasterid = MSAccessDb.GetMaxID("MZ_COSTMASTER", Tables.mz_costmaster.COSTMASTERID); #region 数据库操作,得到结算号 try { MSAccessDb.BeginTrans(); #region 赋值结算头表并保存 HIS.Model.MZ_CostMaster mz_costmaster = new HIS.Model.MZ_CostMaster( ); mz_costmaster.PatID = Patient.PatID; mz_costmaster.PatListID = Patient.PatListID; mz_costmaster.PresMasterID = 0; mz_costmaster.TicketNum = ""; mz_costmaster.TicketCode = ""; mz_costmaster.ChargeCode = OperatorId.ToString( ); mz_costmaster.ChargeName = DataReader.GetEmployeeNameById(OperatorId); mz_costmaster.Total_Fee = chargeTotalCost;//结算表的总金额 mz_costmaster.Self_Fee = 0; mz_costmaster.Village_Fee = 0; mz_costmaster.Favor_Fee = 0; mz_costmaster.Pos_Fee = 0; mz_costmaster.Money_Fee = 0; mz_costmaster.Ticket_Flag = 0; mz_costmaster.Record_Flag = 9;//预结算记录状态置为9 mz_costmaster.OldID = 0; mz_costmaster.AccountID = 0; mz_costmaster.Hang_Flag = (int)OPDOperationType.门诊收费; mz_costmaster.Hurried_Flag = Patient.IsEmergency ? 1 : 0; mz_costmaster.CostMasterID = costmasterid; MSAccessDb.InsertRecord(mz_costmaster, Tables.mz_costorder.COSTORDERID); #endregion #region 更新处方表的结算号和总金额,舍入金额 for (int prescCount = 0; prescCount < prescriptions.Length; prescCount++) { string strWhere = Tables.mz_presmaster.PRESMASTERID + " = " + prescriptions[prescCount].PrescriptionID; MZ_PresMaster mz_presmaster = (MZ_PresMaster)MSAccessDb.GetModel("MZ_PRESMASTER", strWhere, typeof(MZ_PresMaster)); if (mz_presmaster.Charge_Flag == 1) { throw new Exception("处方已被别的收费员收费,请确认!"); } //更新处方表的结算号和总金额,舍入金额 //BindEntity<MZ_PresMaster>.CreateInstanceDAL( oleDb ).Update( strWhere , // Tables.mz_presmaster.COSTMASTERID + " = " + mz_costmaster.CostMasterID , // Tables.mz_presmaster.TOTAL_FEE + " = " + prescriptions[prescCount].Total_Fee , // Tables.mz_presmaster.ROUNGINGMONEY + " = " + prescriptions[prescCount].RoundingMoney ); MSAccessDb.UpdateRecord(new string[] { Tables.mz_presmaster.COSTMASTERID + " = " + mz_costmaster.CostMasterID, Tables.mz_presmaster.TOTAL_FEE + " = " + prescriptions[prescCount].Total_Fee, Tables.mz_presmaster.ROUNGINGMONEY + " = " + prescriptions[prescCount].RoundingMoney }, strWhere, typeof(MZ_PresMaster)); } #endregion #region 保存结算明细到数据库(按大项目保存) int costorderid = MSAccessDb.GetMaxID("MZ_COSTORDER", Tables.mz_costorder.COSTORDERID); foreach (object obj in htCostOrder) { HIS.Model.MZ_CostOrder mz_costorder = (HIS.Model.MZ_CostOrder)((System.Collections.DictionaryEntry)obj).Value; mz_costorder.CostID = mz_costmaster.CostMasterID; mz_costorder.CostOrderID = costorderid; //保存到数据库 //mz_costorder.CostOrderID = BindEntity<MZ_CostOrder>.CreateInstanceDAL( oleDb ).Add( mz_costorder ); MSAccessDb.InsertRecord(mz_costorder, Tables.mz_costorder.COSTORDERID); costorderid++; } #endregion MSAccessDb.CommitTrans( ); } catch (Exception err) { MSAccessDb.RollbackTrans( ); throw new Exception("保存预算结果到数据库发生错误!"); } #endregion //回填处方的结算号 for (int prescCount = 0; prescCount < prescriptions.Length; prescCount++) { prescriptions[prescCount].ChargeID = costmasterid; } #region 返回预算结果 try { Hashtable htInvoiceItem = new Hashtable( ); foreach (object obj in htCostOrder) { HIS.Model.MZ_CostOrder mz_costorder = (HIS.Model.MZ_CostOrder)((System.Collections.DictionaryEntry)obj).Value; InvoiceItem invoice = GetInvoiceByStatCode(mz_costorder.ItemType.Trim( )); invoice.Cost = mz_costorder.Total_Fee; if (htInvoiceItem.ContainsKey(invoice.ItemCode.Trim( ))) { InvoiceItem _invoice = (InvoiceItem)htInvoiceItem[invoice.ItemCode]; _invoice.Cost = _invoice.Cost + invoice.Cost; htInvoiceItem.Remove(invoice.ItemCode); htInvoiceItem.Add(_invoice.ItemCode, _invoice); } else { htInvoiceItem.Add(invoice.ItemCode, invoice); } } List <InvoiceItem> chargeItems = new List <InvoiceItem>( ); foreach (object item in htInvoiceItem) { chargeItems.Add((InvoiceItem)((DictionaryEntry)item).Value); } ChargeInfo chargeInfos = new ChargeInfo( ); chargeInfos.Items = chargeItems.ToArray( ); chargeInfos.ChargeID = costmasterid; chargeInfos.TotalFee = chargeTotalCost; ChargeInfo[] chargeInfo = new ChargeInfo[1]; chargeInfo[0].TotalFee = chargeTotalCost; chargeInfo[0] = chargeInfos; //计算本次的优惠金额 chargeInfo[0].FavorFee = GetFavorCost(Patient.MediType, chargeInfo[0], prescriptions); return(chargeInfo); } catch (Exception err) { throw new Exception("返回预算结果发生错误!"); } #endregion }
/// <summary> /// 上传单个病人费用信息 /// </summary> /// <param name="PatlistId"></param> public void UploadDataWithSinglePatient(int PatlistId) { if (_oleDb == null) { ConnectToRemoteDB( ); } DataTable tbPatList = MSAccessDb.GetDataTable("select * from mz_patlist where patlistid=" + PatlistId); DataTable tbPresMaster = MSAccessDb.GetDataTable("select * from mz_presmaster where upload_flag=0 and patlistid = " + PatlistId + " and record_flag in (0,1,2) and prescostcode='" + _employeeId + "'"); DataTable tbPresOrder = MSAccessDb.GetDataTable("select * from mz_presorder where upload_flag=0 and presmasterid in (select presmasterid from mz_presmaster where patlistid = " + PatlistId + " and record_flag in (0,1,2) and prescostcode='" + _employeeId + "')"); DataTable tbCostMaster = MSAccessDb.GetDataTable("select * from mz_costmaster where upload_flag=0 and patlistid = " + PatlistId + " and record_flag in (0,1,2) and chargecode='" + _employeeId + "'"); DataTable tbCostOrder = MSAccessDb.GetDataTable("select * from mz_costorder where upload_flag=0 and costid in (select costmasterid from mz_costmaster where patlistid = " + PatlistId + " and record_flag in (0,1,2) and chargecode='" + _employeeId + "')"); DataTable tbAccount = MSAccessDb.GetDataTable("select * from mz_account where accountcode='" + _employeeId + "' and upload_flag = 0 "); string patName = tbPatList.Rows[0]["patname"].ToString( ); int presMasterCount = tbPresMaster.Rows.Count; int presOrderCount = tbPresOrder.Rows.Count; int costMasterCount = tbCostMaster.Rows.Count; int costOrderCount = tbCostOrder.Rows.Count; int accountCount = tbAccount.Rows.Count; if (UpLoadingEvent != null) { UpLoadingEvent(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "开始上传病人【" + patName + "】的数据!\r\n"); } if (presMasterCount == 0 && presOrderCount == 0 && costMasterCount == 0 && costOrderCount == 0 && accountCount == 0) { if (UpLoadingEvent != null) { UpLoadingEvent("病人【" + patName + "】没有需要上传的数据!\r\n"); } return; } try { BeginTrans( ); MZ_PatList mz_patlist = new MZ_PatList( ); DataBind <MZ_PatList>(tbPatList.Rows[0], mz_patlist); BindEntity <MZ_PatList> .CreateInstanceDAL(_oleDb).Add(mz_patlist); int serverPatlistId = mz_patlist.PatListID; MSAccessDb.Execute("update mz_patlist set upload_flag =1 where patlistid=" + PatlistId); for (int accountIndex = 0; accountIndex < tbAccount.Rows.Count; accountIndex++) { //上传交款记录 int localAccountId = Convert.ToInt32(tbAccount.Rows[accountIndex][Tables.mz_account.ACCOUNTID]); MZ_Account mz_account = new MZ_Account( ); DataBind <MZ_Account>(tbAccount.Rows[accountIndex], mz_account); BindEntity <MZ_Account> .CreateInstanceDAL(_oleDb).Add(mz_account); MSAccessDb.Execute("update mz_account set upload_flag = 1 where accountid=" + localAccountId); //上传已交款的结算记录、结算明细,处方记录和处方明细(传完后从tbCostMaster中移除,剩下未交账的记录) #region ..... DataRow[] drsCostMaster = tbCostMaster.Select(Tables.mz_costmaster.ACCOUNTID + "=" + localAccountId); for (int costmasterIndex = 0; costmasterIndex < drsCostMaster.Length; costmasterIndex++) { //结算记录 int localCostMasterId = Convert.ToInt32(drsCostMaster[costmasterIndex][Tables.mz_costmaster.COSTMASTERID]); MZ_CostMaster mz_costmaster = new MZ_CostMaster( ); DataBind <MZ_CostMaster>(drsCostMaster[costmasterIndex], mz_costmaster); mz_costmaster.AccountID = mz_account.AccountID; mz_costmaster.PatListID = serverPatlistId; BindEntity <MZ_CostMaster> .CreateInstanceDAL(_oleDb).Add(mz_costmaster); MSAccessDb.Execute("update mz_costmaster set upload_flag =1 where costmasterid=" + localCostMasterId); //结算明细 DataRow[] drsCostOrder = tbCostOrder.Select(Tables.mz_costorder.COSTID + "=" + localCostMasterId); for (int costorderIndex = 0; costorderIndex < drsCostOrder.Length; costorderIndex++) { int loaclCostorderId = Convert.ToInt32(drsCostOrder[costorderIndex][Tables.mz_costorder.COSTORDERID]); MZ_CostOrder mz_costorder = new MZ_CostOrder( ); DataBind <MZ_CostOrder>(drsCostOrder[costorderIndex], mz_costorder); mz_costorder.CostID = mz_costmaster.CostMasterID; BindEntity <MZ_CostOrder> .CreateInstanceDAL(_oleDb).Add(mz_costorder); MSAccessDb.Execute("update mz_costorder set upload_flag =1 where costorderid=" + loaclCostorderId); } //处方记录 DataRow[] drsPresMaster = tbPresMaster.Select(Tables.mz_presmaster.COSTMASTERID + "=" + localCostMasterId); for (int presMasterIndex = 0; presMasterIndex < drsPresMaster.Length; presMasterIndex++) { int localPresMasterId = Convert.ToInt32(drsPresMaster[presMasterIndex][Tables.mz_presmaster.PRESMASTERID]); MZ_PresMaster mz_presmaster = new MZ_PresMaster( ); DataBind <MZ_PresMaster>(drsPresMaster[presMasterIndex], mz_presmaster); mz_presmaster.CostMasterID = mz_costmaster.CostMasterID; mz_presmaster.PatListID = serverPatlistId; BindEntity <MZ_PresMaster> .CreateInstanceDAL(_oleDb).Add(mz_presmaster); MSAccessDb.Execute("update mz_presmaster set upload_flag =1 where presmasterid=" + localPresMasterId); //处方明细 DataRow[] drsPresOrder = tbPresOrder.Select(Tables.mz_presorder.PRESMASTERID + "=" + localPresMasterId); for (int presorderIndex = 0; presorderIndex < drsPresOrder.Length; presorderIndex++) { int localPresOrderId = Convert.ToInt32(drsPresOrder[presorderIndex][Tables.mz_presorder.PRESORDERID]); MZ_PresOrder mz_presorder = new MZ_PresOrder( ); DataBind <MZ_PresOrder>(drsPresOrder[presorderIndex], mz_presorder); mz_presorder.PresMasterID = mz_presmaster.PresMasterID; BindEntity <MZ_PresOrder> .CreateInstanceDAL(_oleDb).Add(mz_presorder); MSAccessDb.Execute("update mz_presorder set upload_flag =1 where presorderid=" + localPresOrderId); } } tbCostMaster.Rows.Remove(drsCostMaster[costmasterIndex]); } #endregion } //上传未交账的结算记录 for (int costMasterIndex = 0; costMasterIndex < tbCostMaster.Rows.Count; costMasterIndex++) { #region ... //结算记录 int localCostMasterId = Convert.ToInt32(tbCostMaster.Rows[costMasterIndex][Tables.mz_costmaster.COSTMASTERID]); MZ_CostMaster mz_costmaster = new MZ_CostMaster( ); DataBind <MZ_CostMaster>(tbCostMaster.Rows[costMasterIndex], mz_costmaster); mz_costmaster.PatListID = serverPatlistId; BindEntity <MZ_CostMaster> .CreateInstanceDAL(_oleDb).Add(mz_costmaster); MSAccessDb.Execute("update mz_costmaster set upload_flag =1 where costmasterid=" + localCostMasterId); //结算明细 DataRow[] drsCostOrder = tbCostOrder.Select(Tables.mz_costorder.COSTID + "=" + localCostMasterId); for (int costorderIndex = 0; costorderIndex < drsCostOrder.Length; costorderIndex++) { int loaclCostorderId = Convert.ToInt32(drsCostOrder[costorderIndex][Tables.mz_costorder.COSTORDERID]); MZ_CostOrder mz_costorder = new MZ_CostOrder( ); DataBind <MZ_CostOrder>(drsCostOrder[costorderIndex], mz_costorder); mz_costorder.CostID = mz_costmaster.CostMasterID; BindEntity <MZ_CostOrder> .CreateInstanceDAL(_oleDb).Add(mz_costorder); MSAccessDb.Execute("update mz_costorder set upload_flag=1 where costorderid=" + loaclCostorderId); } //处方记录 DataRow[] drsPresMaster = tbPresMaster.Select(Tables.mz_presmaster.COSTMASTERID + "=" + localCostMasterId); for (int presMasterIndex = 0; presMasterIndex < drsPresMaster.Length; presMasterIndex++) { int localPresMasterId = Convert.ToInt32(drsPresMaster[presMasterIndex][Tables.mz_presmaster.PRESMASTERID]); MZ_PresMaster mz_presmaster = new MZ_PresMaster( ); DataBind <MZ_PresMaster>(drsPresMaster[presMasterIndex], mz_presmaster); mz_presmaster.CostMasterID = mz_costmaster.CostMasterID; mz_presmaster.PatListID = serverPatlistId; BindEntity <MZ_PresMaster> .CreateInstanceDAL(_oleDb).Add(mz_presmaster); MSAccessDb.Execute("update mz_presmaster set upload_flag=1 where presmasterid=" + localPresMasterId); //处方明细 DataRow[] drsPresOrder = tbPresOrder.Select(Tables.mz_presorder.PRESMASTERID + "=" + localPresMasterId); for (int presorderIndex = 0; presorderIndex < drsPresOrder.Length; presorderIndex++) { int localPresOrderId = Convert.ToInt32(drsPresOrder[presorderIndex][Tables.mz_presorder.PRESORDERID]); MZ_PresOrder mz_presorder = new MZ_PresOrder( ); DataBind <MZ_PresOrder>(drsPresOrder[presorderIndex], mz_presorder); mz_presorder.PresMasterID = mz_presmaster.PresMasterID; BindEntity <MZ_PresOrder> .CreateInstanceDAL(_oleDb).Add(mz_presorder); MSAccessDb.Execute("update mz_presorder set upload_flag =1 where presorderid=" + localPresOrderId); } } #endregion } //提交事务 CommitTrans( ); if (UpLoadingEvent != null) { UpLoadingEvent(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "上传成功!\r\n处方记录" + presMasterCount + "条,处方明细" + presOrderCount + "条,结算记录" + costMasterCount + "条,结算明细" + costOrderCount + "条,个人交款记录" + accountCount + "条\r\n\r\n"); } } catch (Exception err) { RollbackTrans( ); throw err; } }
/// <summary> /// 保存处方 /// </summary> /// <param name="Prescriptions">要保存的处方</param> /// <returns>成功标志</returns> /// <remarks></remarks> public bool SavePrescription(Prescription[] Prescriptions) { //oleDb.BeginTransaction(); MSAccessDb.BeginTrans( ); try { for (int i = 0; i < Prescriptions.Length; i++) { if (!Prescriptions[i].Modified) { continue; } if (Prescriptions[i].PresDetails == null) { continue; } if (Prescriptions[i].PresDetails.Length == 0) { continue; } HIS.Model.MZ_PresMaster t_mz_prescMaster = new HIS.Model.MZ_PresMaster( ); #region 赋值 t_mz_prescMaster.PatID = Prescriptions[i].PatientID; t_mz_prescMaster.PatListID = Prescriptions[i].RegisterID; t_mz_prescMaster.Charge_Flag = Prescriptions[i].Charge_Flag; t_mz_prescMaster.ChargeCode = Prescriptions[i].ChargeCode; t_mz_prescMaster.CostMasterID = Prescriptions[i].ChargeID; t_mz_prescMaster.Drug_Flag = Prescriptions[i].Drug_Flag; t_mz_prescMaster.ExecDeptCode = Prescriptions[i].ExecDeptCode; t_mz_prescMaster.ExecDocCode = Prescriptions[i].ExecDocCode; t_mz_prescMaster.OldID = Prescriptions[i].OldPresID; t_mz_prescMaster.PresCostCode = Prescriptions[i].PresCostCode; t_mz_prescMaster.PresMasterID = Prescriptions[i].PrescriptionID; t_mz_prescMaster.PresType = Prescriptions[i].PrescType; t_mz_prescMaster.PresDeptCode = Prescriptions[i].PresDeptCode; t_mz_prescMaster.PresDocCode = Prescriptions[i].PresDocCode; t_mz_prescMaster.Record_Flag = Prescriptions[i].Record_Flag; t_mz_prescMaster.TicketCode = Prescriptions[i].TicketCode; t_mz_prescMaster.TicketNum = Prescriptions[i].TicketNum; t_mz_prescMaster.Total_Fee = Prescriptions[i].Total_Fee; t_mz_prescMaster.PresDate = Prescriptions[i].PresDate; t_mz_prescMaster.PresAmount = Prescriptions[i].PresDetails[0].PresAmount; t_mz_prescMaster.Hand_Flag = (int)OPDOperationType.门诊收费; #endregion if (MSAccessDb.Exists("MZ_PRESMASTER", Tables.mz_presmaster.PRESMASTERID + "=" + Prescriptions[i].PrescriptionID)) { MZ_PresMaster mz_presmaster = (MZ_PresMaster)MSAccessDb.GetModel("MZ_PRESMASTER", Tables.mz_presmaster.PRESMASTERID + "=" + Prescriptions[i].PrescriptionID, typeof(MZ_PresMaster)); if (mz_presmaster.Charge_Flag == 1) { throw new Exception("处方已收费,不能修改!"); } //更新处方头 //BindEntity<MZ_PresMaster>.CreateInstanceDAL( oleDb ).Update( t_mz_prescMaster ); MSAccessDb.UpdateRecord(t_mz_prescMaster); } else { //插入新处方 t_mz_prescMaster.PresMasterID = MSAccessDb.GetMaxID("MZ_PRESMASTER", Tables.mz_presmaster.PRESMASTERID); MSAccessDb.InsertRecord(t_mz_prescMaster, Tables.mz_presmaster.PRESMASTERID); Prescriptions[i].PrescriptionID = t_mz_prescMaster.PresMasterID; } //更新或增加明细 PrescriptionDetail[] details = Prescriptions[i].PresDetails; int temp_detail_id = MSAccessDb.GetMaxID("MZ_PRESORDER", Tables.mz_presorder.PRESORDERID); for (int j = 0; j < details.Length; j++) { HIS.Model.MZ_PresOrder t_mz_presOrder = new HIS.Model.MZ_PresOrder( ); #region 赋值 t_mz_presOrder.Amount = details[j].Amount; t_mz_presOrder.BigItemCode = details[j].BigitemCode; t_mz_presOrder.Buy_Price = details[j].Buy_price; t_mz_presOrder.CaseID = details[j].ComplexId; t_mz_presOrder.ItemID = details[j].ItemId; t_mz_presOrder.ItemName = details[j].Itemname; t_mz_presOrder.ItemType = details[j].ItemType; t_mz_presOrder.Order_Flag = details[j].Order_Flag; t_mz_presOrder.PassID = details[j].PassId; t_mz_presOrder.PatID = this.patient.PatID; t_mz_presOrder.PatListID = this.patient.PatListID; t_mz_presOrder.PresAmount = details[j].PresAmount; t_mz_presOrder.PresMasterID = Prescriptions[i].PrescriptionID; t_mz_presOrder.PresOrderID = details[j].DetailId; t_mz_presOrder.RelationNum = details[j].RelationNum; t_mz_presOrder.Sell_Price = details[j].Sell_price; t_mz_presOrder.Standard = details[j].Standard; t_mz_presOrder.Tolal_Fee = details[j].Tolal_Fee; t_mz_presOrder.Unit = details[j].Unit; #endregion if (MSAccessDb.Exists("MZ_PRESORDER", Tables.mz_presorder.PRESORDERID + "=" + details[j].DetailId)) { //更新处方明细 MSAccessDb.UpdateRecord(t_mz_presOrder); } else { //插入新处方明细 t_mz_presOrder.PresOrderID = temp_detail_id; int ret2 = MSAccessDb.InsertRecord(t_mz_presOrder, Tables.mz_presorder.PRESORDERID); details[j].DetailId = temp_detail_id; temp_detail_id++; } } } MSAccessDb.CommitTrans( ); return(true); } catch (Exception err) { MSAccessDb.RollbackTrans( ); throw new Exception("保存处方发生错误!"); } }