///<summary> /// 保存数据 /// </summary> /// <param name="pObj">信息集实体类</param> /// <returns>返回保存成功(true)或失败(false)</returns> public void SaveBill(ExcessOrder ExcessOrder, List <ExcessOrderDetail> ExcessOrderDetail) { CommonInterface pComm = CommonFactory.CreateInstance(CommonData.sql); try { pComm.BeginTrans(); //保存单据主表数据 //先删除主表数据 string strDeleteSql = "Delete from ExcessOrder where ExcessOrderGuid='" + ExcessOrder.ExcessOrderGuid + "'"; pComm.Execute(strDeleteSql); //插入主表数据 string strInsertSql = GetAddBillSQL(ExcessOrder); pComm.Execute(strInsertSql); //删除明细表 strDeleteSql = "Delete from ExcessOrderDetail where ExcessOrderGuid='" + ExcessOrder.ExcessOrderGuid + "'"; pComm.Execute(strDeleteSql); //插入明细表数据 for (int i = 0; i < ExcessOrderDetail.Count; i++) { strInsertSql = GetAddBillDetailSQL(ExcessOrderDetail[i]); pComm.Execute(strInsertSql); } pComm.CommitTrans(); } catch (Exception e) { pComm.RollbackTrans(); pComm.Close(); throw e; } }
/// <summary> /// 得到新增sql /// </summary> public string GetAddBillSQL(ExcessOrder ExcessOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ExcessOrder("); strSql.Append("ExcessOrderGuid,ExcessOrderID,ExcessOrderDate,DrawPerson,EmitPerson,OutStorage,Remark,CreateGuid,CreateDate,CheckGuid,CheckDate,CheckGuid2,CheckDate2"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append("'" + ExcessOrder.ExcessOrderGuid + "',"); strSql.Append("'" + ExcessOrder.ExcessOrderID + "',"); strSql.Append("'" + ExcessOrder.ExcessOrderDate + "',"); strSql.Append("'" + ExcessOrder.DrawPerson + "',"); strSql.Append("'" + ExcessOrder.EmitPerson + "',"); strSql.Append("'" + ExcessOrder.OutStorage + "',"); strSql.Append("'" + ExcessOrder.Remark + "',"); strSql.Append("'" + ExcessOrder.CreateGuid + "',"); strSql.Append("'" + ExcessOrder.CreateDate + "',"); strSql.Append("'" + ExcessOrder.CheckGuid + "',"); if (ExcessOrder.CheckDate == DateTime.Parse("1900-01-01")) { strSql.Append("null,"); } else { strSql.Append("'" + ExcessOrder.CheckDate + "',"); } strSql.Append("'" + ExcessOrder.CheckGuid2 + "',"); if (ExcessOrder.CheckDate2 == DateTime.Parse("1900-01-01")) { strSql.Append("null"); } else { strSql.Append("'" + ExcessOrder.CheckDate2 + "'"); } strSql.Append(")"); return(strSql.ToString()); }