///<summary> /// 保存数据----点击保存时用 /// </summary> /// <param name="pObj">信息集实体类</param> /// <returns>返回保存成功(true)或失败(false)</returns> public void SaveBill(IncomeOrder IncomeOrder, List <IncomeOrderDetail1> IncomeOrderDetail1, List <IncomeOrderDetail2> IncomeOrderDetail2) { CommonInterface pComm = CommonFactory.CreateInstance(CommonData.sql); try { pComm.BeginTrans(); //保存单据主表数据 //先删除主表数据 string strDeleteSql = "Delete from IncomeOrder where IncomeOrderGuid='" + IncomeOrder.IncomeOrderGuid + "'"; pComm.Execute(strDeleteSql); //插入主表数据 string strInsertSql = GetAddSQL(IncomeOrder); pComm.Execute(strInsertSql); //删除明细表 strDeleteSql = "Delete from IncomeOrderDetail1 where IncomeOrderGuid='" + IncomeOrder.IncomeOrderGuid + "'"; pComm.Execute(strDeleteSql); //插入明细表数据 for (int i = 0; i < IncomeOrderDetail1.Count; i++) { strInsertSql = GetAddDetailSQL1(IncomeOrderDetail1[i]); pComm.Execute(strInsertSql); } //删除计算明细 strDeleteSql = "Delete from IncomeOrderDetail2 where IncomeOrderGuid='" + IncomeOrder.IncomeOrderGuid + "'"; pComm.Execute(strDeleteSql); //插入明细表数据 for (int i = 0; i < IncomeOrderDetail2.Count; i++) { strInsertSql = GetAddDetailSQL2(IncomeOrderDetail2[i]); pComm.Execute(strInsertSql); } pComm.CommitTrans(); } catch (Exception e) { pComm.RollbackTrans(); pComm.Close(); throw e; } }
/// <summary> /// 得到新增sql /// </summary> public string GetAddSQL(IncomeOrder IncomeOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into IncomeOrder("); strSql.Append("IncomeOrderGuid,IncomeOrderID,IncomeOrderDate,ClientGuid,IncomePerson,Remark,CreateGuid,CreateDate,CheckGuid,CheckDate"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append("'" + IncomeOrder.IncomeOrderGuid + "',"); strSql.Append("'" + IncomeOrder.IncomeOrderID + "',"); if (IncomeOrder.IncomeOrderDate == DateTime.Parse("1900-01-01")) { strSql.Append("null,"); } else { strSql.Append("'" + IncomeOrder.IncomeOrderDate + "',"); } strSql.Append("'" + IncomeOrder.ClientGuid + "',"); strSql.Append("'" + IncomeOrder.IncomePerson + "',"); strSql.Append("'" + IncomeOrder.Remark + "',"); strSql.Append("'" + IncomeOrder.CreateGuid + "',"); strSql.Append("'" + IncomeOrder.CreateDate + "',"); strSql.Append("'" + IncomeOrder.CheckGuid + "',"); if (IncomeOrder.CheckDate == DateTime.Parse("1900-01-01")) { strSql.Append("null"); } else { strSql.Append("'" + IncomeOrder.CreateDate + "'"); } strSql.Append(")"); return(strSql.ToString()); }