public int Update(ResourceModel resModel, ResourceGaugeModel resGaugeModel, ResourcePriceModel resPriceModel) { int num = 0; if (((resModel.ResourceCode != "") && (resGaugeModel.ResourceCode != "")) && (resPriceModel.ResourceCode != "")) { num = ResourceEdit.Update(resModel, resGaugeModel, resPriceModel); } return(num); }
public static int Update(ResourceModel resModel, ResourceGaugeModel resGaugeModel, ResourcePriceModel resPriceModel) { SqlConnection connection = new SqlConnection(SqlHelper.ConnectionString); connection.Open(); SqlTransaction trans = connection.BeginTransaction(); int num = 0; StringBuilder builder = new StringBuilder(); try { builder.Append("begin update EPM_Res_Resource set "); builder.Append("VersionCode=@VersionCode,CategoryCode=@CategoryCode"); builder.Append(",ResourceName=@ResourceName,Specification=@Specification,ResourceStyle=@ResourceStyle"); builder.Append(",ResourceType=@ResourceType,IsValid=@IsValid,Owner=@Owner,VersionTime=@VersionTime,imgurl=@imgurl "); builder.Append(" where ResourceCode=@ResourceCode "); builder.Append(" update EPM_Res_Gauge set "); builder.Append(" VersionCode=@VersionCode,UnitID=@UnitID,Quotiety=@Quotiety,IsDefault=@IsDefault,IsValid=@IsValid,Owner=@Owner,VersionTime=@VersionTime "); builder.Append(" where ResourceCode=@ResourceCode "); builder.Append(" update EPM_Res_PriceRelations set "); builder.Append(" VersionCode=@VersionCode,PriceItemID=@PriceItemID,Price=@Price,Owner=@Owner,VersionTime=@VersionTime "); builder.Append(" where ResourceCode=@ResourceCode end "); SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@VersionCode", SqlDbType.UniqueIdentifier, 0x10), new SqlParameter("@ResourceCode", SqlDbType.VarChar, 50), new SqlParameter("@CategoryCode", SqlDbType.VarChar, 50), new SqlParameter("@ResourceName", SqlDbType.VarChar, 200), new SqlParameter("@Specification", SqlDbType.VarChar, 200), new SqlParameter("@ResourceStyle", SqlDbType.Int, 4), new SqlParameter("@ResourceType", SqlDbType.Int, 4), new SqlParameter("@IsValid", SqlDbType.Bit, 1), new SqlParameter("@Owner", SqlDbType.VarChar, 10), new SqlParameter("@VersionTime", SqlDbType.DateTime), new SqlParameter("@UnitID", SqlDbType.Int, 4), new SqlParameter("@Quotiety", SqlDbType.Decimal, 9), new SqlParameter("@IsDefault", SqlDbType.Bit, 1), new SqlParameter("@PriceItemID", SqlDbType.Int, 4), new SqlParameter("@Price", SqlDbType.Decimal, 9), new SqlParameter("@imgurl", SqlDbType.VarChar, 0xd7) }; commandParameters[0].Value = new Guid(resModel.VersionCode); commandParameters[1].Value = resModel.ResourceCode; commandParameters[2].Value = resModel.CategoryCode; commandParameters[3].Value = resModel.ResourceName; commandParameters[4].Value = resModel.Specification; commandParameters[5].Value = int.Parse(resModel.ResourceStyle); commandParameters[6].Value = int.Parse(resModel.ResourceType); commandParameters[7].Value = Convert.ToBoolean(int.Parse(resModel.IsValid)); commandParameters[8].Value = resModel.Owner; commandParameters[9].Value = resModel.VersionTime; commandParameters[10].Value = int.Parse(resGaugeModel.UnitId); commandParameters[11].Value = decimal.Parse(resGaugeModel.Quantity); commandParameters[12].Value = Convert.ToBoolean(int.Parse(resGaugeModel.IsDefault)); commandParameters[13].Value = int.Parse(resPriceModel.PriceItem); commandParameters[14].Value = decimal.Parse(resPriceModel.Price); commandParameters[15].Value = resModel.ResourceImageUrl; num = SqlHelper.ExecuteNonQuery(trans, CommandType.Text, builder.ToString(), commandParameters); trans.Commit(); } catch { trans.Rollback(); connection.Close(); connection.Dispose(); } connection.Close(); connection.Dispose(); return(num); }