public static DbDataAdapter CreateDataAdapter(GmConnection conn, Document doc) { DbDataAdapter da = conn.CreateDataAdapter(); GmCommand cmd = conn.CreateCommand(selectCmdText); cmd.AddInt("DocumentId", doc.DocumentId); cmd.AddBool("FactFlag", false); (da as IDbDataAdapter).SelectCommand = cmd.DbCommand; cmd = conn.CreateCommand(insertCmdText); cmd.AddString("ProductCode").SourceColumn = "ProductCode"; cmd.AddString("UnitCode").SourceColumn = "UnitCode"; cmd.AddInt("DocumentId", doc.DocumentId); cmd.AddDecimal("Coef").SourceColumn = "Coef"; cmd.AddDecimal("Count").SourceColumn = "Count"; cmd.AddBool("FactFlag", true); cmd.AddBool("HandledFlag").SourceColumn = "HandledFlag"; cmd.DbCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord; (da as IDbDataAdapter).InsertCommand = cmd.DbCommand; cmd = conn.CreateCommand(deleteCmdText); cmd.AddInt("DocumentProductId").SourceColumn = "DocumentProductId"; (da as IDbDataAdapter).DeleteCommand = cmd.DbCommand; cmd = conn.CreateCommand(updateCmdText); cmd.AddInt("DocumentProductId").SourceColumn = "DocumentProductId"; cmd.AddDecimal("Count").SourceColumn = "Count"; cmd.AddBool("HandledFlag").SourceColumn = "HandledFlag"; (da as IDbDataAdapter).UpdateCommand = cmd.DbCommand; return(da); }
public void Save(GmConnection conn, DbTransaction trans) { GmCommand cmd = conn.CreateCommand(trans); cmd.AddInt("Id", id); cmd.AddInt("ProductId", productId); cmd.AddDecimal("Price", price); cmd.AddNullableDateTime("ExpiredDate", expiredDate); cmd.AddDecimal("CurrentCount", currentCount); cmd.AddDecimal("ReservedCount", reservedCount); cmd.AddString("Series", series); if (id == 0) { cmd.CommandText = "insert into StoreProducts values (@ProductId,@Price,@ExpiredDate,@CurrentCount,@ReservedCount,@Series) select @@Identity"; id = (int)(decimal)cmd.ExecuteScalar(); } else { cmd.CommandText = "update StoreProducts set ProductId=@ProductId,Price=@Price,ExpiredDate=@ExpiredDate,CurrentCount=@CurrentCount,ReservedCount=@ReservedCount,Series=@Series where Id=@Id"; cmd.ExecuteNonQuery(); } }
public void Save(GmConnection conn) { GmCommand cmd = conn.CreateCommand(); cmd.AddInt("Id", id); cmd.AddString("Name", name); cmd.AddString("Code", code); cmd.AddInt("PackedNumber", packedNumber); cmd.AddInt("MedicamentId", medicamentId); cmd.AddString("Maker", maker); cmd.AddInt("BaseUnitId", baseUnitId); cmd.AddDecimal("UnitCount", unitCount); cmd.AddString("MedLists", medLists); if (id == 0) { cmd.CommandText = "insert into Products values (@Code,@Name,@PackedNumber,@MedicamentId,@Maker,@BaseUnitId,@UnitCount,@MedLists) select @@Identity"; id = (int)(decimal)cmd.ExecuteScalar(); } else { cmd.CommandText = "update Products set Code=@Code,Name=@Name,PackedNumber=@PackedNumber,MedicamentId=@MedicamentId,Maker=@Maker,BaseUnitId=@BaseUnitId,UnitCount=@UnitCount,MedLists=@MedLists where Id=@Id"; cmd.ExecuteNonQuery(); } }