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