private void AddProductInfo(HttpContext ctx, string jsonStr) { var jobj = JObject.Parse(jsonStr.Replace("\\", "")); if (jobj == null) { ctx.Response.Write("-1"); return; } string reutrnId = string.Empty; var vUser = Utils.UserInfo; var entityMain = new CASE_PRODUCTIN_MAINEntity { CODE = PublicMethod.GetString(jobj["CODE"]), INDATE = PublicMethod.GetDateTime(jobj["INDATE"]), INTYPE = PublicMethod.GetString(jobj["INTYPE"]), DEPOT = PublicMethod.GetString(jobj["DEPOT"]), CUSTODIAN = PublicMethod.GetString(jobj["CUSTODIAN"]), SUPPLIERNAME = PublicMethod.GetString(jobj["SUPPLIERNAME"]), CREATEBY = PublicMethod.GetString(jobj["CREATEBY"]) == "" ? vUser.UserName : PublicMethod.GetString(jobj["CREATEBY"]), CREATEUSERID = vUser.Id, CREATEON = PublicMethod.GetDateTime(jobj["CREATEON"]) ?? DateTime.Now, DESCRIPTION = PublicMethod.GetString(jobj["DESCRIPTION"]) }; var managerMain = new CASE_PRODUCTIN_MAINManager(this.dbHelper, vUser); reutrnId = managerMain.AddEntity(entityMain); if (!string.IsNullOrEmpty(reutrnId)) { var products = jobj["products"]; var subdatas = products.Select(data => new { FullName = data["FULLNAME"], UnitPrice = data["UNITPRICE"], State = data["STATE"], CategoryName = data["categoryName"], Category = data["CATEGORY"] }); foreach (var data in subdatas) { var entityDetail = new CASE_PRODUCTIN_DETAILEntity { CASE_PRODUCTIN_MAIN_ID = reutrnId, FULLNAME = PublicMethod.GetString(data.FullName), UNITPRICE = BusinessLogic.ConvertToNullableDecimal(data.UnitPrice), STATE = PublicMethod.GetString(data.State), CATEGORY = PublicMethod.GetString(data.Category), }; var managerDetail = new CASE_PRODUCTIN_DETAILManager(this.dbHelper, vUser); managerDetail.AddEntity(entityDetail); } ctx.Response.Write("1"); } else { ctx.Response.Write("0"); } }
//增加实体语句事务测试 private bool InAddEntityTransactionTest() { //可以支持任意流行数据库类型,指定相关的数据库提供者即可(OracleProvider、SqlProvider、SqLiteProvider、MySqlProvider、DB2Provider、OleDbProvider) IDbProvider dbProvider = new SqlProvider(SystemInfo.RDIFrameworkDbConectionString); bool result = true; try { dbProvider.BeginTransaction(); //主表 CASE_PRODUCTIN_MAINManager manager = new CASE_PRODUCTIN_MAINManager(dbProvider, Utils.UserInfo); CASE_PRODUCTIN_MAINEntity mainEntity = new CASE_PRODUCTIN_MAINEntity { ID = BusinessLogic.NewGuid(), INDATE = BusinessLogic.ConvertToNullableDateTime(DateTime.Now), SUPPLIERNAME = "Test" }; string key = manager.AddEntity(mainEntity); //子表 CASE_PRODUCTIN_DETAILManager detailManager = new CASE_PRODUCTIN_DETAILManager(dbProvider, Utils.UserInfo); CASE_PRODUCTIN_DETAILEntity detailEntity = new CASE_PRODUCTIN_DETAILEntity { ID = BusinessLogic.NewGuid(), CASE_PRODUCTIN_MAIN_ID = key }; string key1 = detailManager.AddEntity(detailEntity); //事务提交 dbProvider.CommitTransaction(); } catch (Exception ex) { //事务回滚 dbProvider.RollbackTransaction(); result = false; } return(result); }
private void EditProductInfo(HttpContext ctx, string jsonStr, string keyId) { var jobj = JObject.Parse(jsonStr.Replace("\\", "")); if (jobj == null) { ctx.Response.Write("-1"); return; } var reutrnId = 0; var vUser = Utils.UserInfo; var managerMain = new CASE_PRODUCTIN_MAINManager(this.dbHelper, vUser); var entityMain = managerMain.GetEntity(keyId); if (entityMain == null) { ctx.Response.Write("-1"); return; } entityMain.CODE = PublicMethod.GetString(jobj["CODE"]); entityMain.INDATE = PublicMethod.GetDateTime(jobj["INDATE"]); entityMain.INTYPE = PublicMethod.GetString(jobj["INTYPE"]); entityMain.DEPOT = PublicMethod.GetString(jobj["DEPOT"]); entityMain.CUSTODIAN = PublicMethod.GetString(jobj["CUSTODIAN"]); entityMain.SUPPLIERNAME = PublicMethod.GetString(jobj["SUPPLIERNAME"]); entityMain.DESCRIPTION = PublicMethod.GetString(jobj["DESCRIPTION"]); reutrnId = managerMain.UpdateEntity(entityMain); if (reutrnId > 0) { var products = jobj["products"]; var subdatas = products.Select(data => new { Id = data["ID"], ReferId = data["CASE_PRODUCTIN_MAIN_ID"], FullName = data["FULLNAME"], UnitPrice = data["UNITPRICE"], State = data["STATE"], CategoryName = data["categoryName"], Category = data["CATEGORY"] }); var managerDetail = new CASE_PRODUCTIN_DETAILManager(this.dbHelper, vUser); foreach (var data in subdatas) { //TODO:情形一、新增的产品明细 if (string.IsNullOrEmpty(PublicMethod.GetString(data.Id))) { //增加 var entity = new CASE_PRODUCTIN_DETAILEntity { CASE_PRODUCTIN_MAIN_ID = entityMain.ID, FULLNAME = PublicMethod.GetString(data.FullName), UNITPRICE = BusinessLogic.ConvertToNullableDecimal(data.UnitPrice), STATE = PublicMethod.GetString(data.State), CATEGORY = PublicMethod.GetString(data.Category), }; managerDetail.AddEntity(entity); } //TODO:情形二、删除的产品明细、暂不处理.... //TODO:情形三、实行修改操作 var entityDetail = managerDetail.GetEntity(PublicMethod.GetString(data.Id)); if (entityDetail == null) { continue; } entityDetail.FULLNAME = PublicMethod.GetString(data.FullName); entityDetail.UNITPRICE = BusinessLogic.ConvertToNullableDecimal(data.UnitPrice); entityDetail.STATE = PublicMethod.GetString(data.State); entityDetail.CATEGORY = PublicMethod.GetString(data.Category); managerDetail.UpdateEntity(entityDetail); } ctx.Response.Write("1"); } else { ctx.Response.Write("0"); } }