public async Task <SaveResult> Save(Refund Refund) { SaveResult saveRlt = new SaveResult(); saveRlt.UniqueKey = Refund.OMSDocEntry.ToString();//回传接收方的主键 using (IDbConnection conn = SqlConnectionFactory.CreateSqlConnection()) { conn.Open(); IDbTransaction dbTransaction = conn.BeginTransaction(); try { string insertSql = @"INSERT INTO T_Refund (OMSDocEntry,PlatformCode,DocType,BusinessType,RefundType,RefundReason,CardCode,GrossRefund,Freight,FrghtVendor,PayMethod,Comments,CreateDate,UpdateDate,Creator,UpDator) VALUES (@OMSDocEntry,@PlatformCode,@DocType,@BusinessType,@RefundType,@RefundReason,@CardCode,@GrossRefund,@Freight,@FrghtVendor,@PayMethod,@Comments,@CreateDate,@UpdateDate,@Creator,@UpDator)select SCOPE_IDENTITY();"; string insertItemSql = @"INSERT INTO T_RefundItem (DocEntry,LineNum,OMSDocEntry,OMSLineNum,ItemCode,Quantity,Price,ItemRefund) VALUES (@DocEntry,@LineNum,@OMSDocEntry,@OMSLineNum,@ItemCode,@Quantity,@Price,@ItemRefund)"; object DocEntry = await conn.ExecuteScalarAsync(insertSql, new { OMSDocEntry = Refund.OMSDocEntry, PlatformCode = Refund.PlatformCode, DocType = Refund.DocType, BusinessType = Refund.BusinessType, RefundType = Refund.RefundType, RefundReason = Refund.RefundReason, CardCode = Refund.CardCode, GrossRefund = Refund.GrossRefund, Freight = Refund.Freight, FrghtVendor = Refund.FrghtVendor, PayMethod = Refund.PayMethod, Comments = Refund.Comments, CreateDate = DateTime.Now, UpdateDate = Refund.UpdateDate, Creator = Refund.Creator, UpDator = Refund.UpDator }, dbTransaction); saveRlt.ReturnUniqueKey = DocEntry.ToString();//回传保存订单的主键 conn.Execute(insertItemSql, DocumentItemHandle <RefundItem> .GetDocumentItems(Refund.RefundItems, Convert.ToInt32(DocEntry)), dbTransaction); dbTransaction.Commit(); saveRlt.Code = 0; } catch (Exception ex) { dbTransaction.Rollback(); saveRlt.Code = 1; saveRlt.Message = ex.Message; throw ex; } finally { conn.Close(); } return(saveRlt); } }
public async Task <SaveResult> Save(SalesOrder SalesOrder) { SaveResult saveRlt = new SaveResult(); saveRlt.UniqueKey = SalesOrder.OMSDocEntry.ToString();//回传接收方的主键 using (IDbConnection conn = SqlConnectionFactory.CreateSqlConnection()) { conn.Open(); IDbTransaction dbTransaction = conn.BeginTransaction(); try { string insertSql = @"insert into T_SalesOrder(OMSDocEntry,OMSDocDate,DocType,BusinessType,PlatformCode,CardCode,OrderPaied,Freight,PayMethod,Comments,CreateDate,UpdateDate) values(@OMSDocEntry,@OMSDocDate,@DocType,@BusinessType,@PlatfromCode,@CardCode,@OrderPaied,@Freight,@Paymenthod,@Comments,@CreateDate,@UpdateDate)select SCOPE_IDENTITY();"; string insertItemSql = @"insert into T_SalesOrderItem(DocEntry,LineNum,OMSDocEntry,OMSLineNum,ItemCode,Quantity,Price,ItemPaied) values(@DocEntry,@LineNum,@OMSDocEntry,@OMSLineNum,@ItemCode,@Quantity,@Price,@ItemPaied)"; object DocEntry = await conn.ExecuteScalarAsync(insertSql, new { OMSDocEntry = SalesOrder.OMSDocEntry, OMSDocDate = SalesOrder.OMSDocDate, DocType = SalesOrder.DocType, BusinessType = SalesOrder.BusinessType, PlatfromCode = SalesOrder.PlatformCode, CardCode = SalesOrder.CardCode, OrderPaied = SalesOrder.OrderPaied, Freight = SalesOrder.Freight, Paymenthod = SalesOrder.PayMethod, Comments = SalesOrder.Comments, CreateDate = DateTime.Now, UpdateDate = DateTime.Now }, dbTransaction); saveRlt.ReturnUniqueKey = DocEntry.ToString();//回传保存订单的主键 await conn.ExecuteAsync(insertItemSql, DocumentItemHandle <SalesOrderItem> .GetDocumentItems(SalesOrder.SalesOrderItems, Convert.ToInt32(DocEntry)), dbTransaction); dbTransaction.Commit(); saveRlt.Code = 0; } catch (Exception ex) { dbTransaction.Rollback(); saveRlt.Code = 1; saveRlt.Message = ex.Message; throw ex; } finally { conn.Close(); } return(saveRlt); } }
public async Task <SaveResult> SaveJournalRelationMap(JournalRelationMap JournalRelationMap) { SaveResult saveRlt = new SaveResult(); saveRlt.UniqueKey = JournalRelationMap.TransId.ToString();//回传接收方的主键 using (IDbConnection conn = SqlConnectionFactory.CreateSqlConnection()) { conn.Open(); IDbTransaction dbTransaction = conn.BeginTransaction(); try { string insertSql = @"INSERT INTO T_JournalRelationMap (Number,TransId,TransType,BPLId,Series,BaseRef,Memo,RefDate,DueDate,TaxDate,CreateDate,BPLName,Ref1,Ref2,Ref3,Creator,Approver,BtfLine,IsApart) VALUES(@Number,@TransId,@TransType,@BPLId,@Series,@BaseRef,@Memo,@RefDate,@DueDate,@TaxDate,@CreateDate,@BPLName,@Ref1,@Ref2,@Ref3,@Creator,@Approver,@BtfLine,@IsApart) select SCOPE_IDENTITY();"; string insertItemSql = @"INSERT INTO T_JournalRelationMapItem (DocEntry,LineNum,TransId,LineId,BPLId,AcctCode,ShorName,ProfitCode,OcrCode2,OcrCode3,OcrCode4,OcrCode5,LineMemo,CardCode,CardName,Credit,Debit) VALUES(@DocEntry,@LineNum,@TransId,@LineId,@BPLId,@AcctCode,@ShorName,@ProfitCode,@OcrCode2,@OcrCode3,@OcrCode4,@OcrCode5,@LineMemo,@CardCode,@CardName,@Credit,@Debit)"; object DocEntry = await conn.ExecuteScalarAsync(insertSql, new { Number = JournalRelationMap.Number, TransId = JournalRelationMap.TransId, BPLId = JournalRelationMap.BPLId, Series = JournalRelationMap.Series, BaseRef = JournalRelationMap.BaseRef, Memo = JournalRelationMap.Memo, RefDate = JournalRelationMap.RefDate, DueDate = JournalRelationMap.DueDate, TaxDate = JournalRelationMap.TaxDate, CreateDate = JournalRelationMap.CreateDate, BPLName = JournalRelationMap.BPLName, Ref1 = JournalRelationMap.Ref1, Ref2 = JournalRelationMap.Ref2, Ref3 = JournalRelationMap.Ref3, Creator = JournalRelationMap.Creator, Approver = JournalRelationMap.Approver, BtfLine = JournalRelationMap.BtfLine, IsApart = JournalRelationMap.IsApart, TransType = JournalRelationMap.TransType }, dbTransaction); saveRlt.ReturnUniqueKey = DocEntry.ToString();//回传保存订单的主键 await conn.ExecuteAsync(insertItemSql, DocumentItemHandle <JournalRelationMapLine> .GetDocumentItems(JournalRelationMap.JournalRelationMapLines, Convert.ToInt32(DocEntry)), dbTransaction); dbTransaction.Commit(); saveRlt.Code = 0; } catch (Exception ex) { dbTransaction.Rollback(); saveRlt.Code = 1; saveRlt.Message = ex.Message; throw ex; } finally { conn.Close(); } return(saveRlt); } }