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"); } }
//以下为测试代码:一个可以兼容各种数据库事务的使用范例 //1、传入实体执行执行事务测试 private bool InEntityTransactionTest(string mainId, string detailId) { //可以支持任意流行数据库类型,指定相关的数据库提供者即可(OracleProvider、SqlProvider、SqLiteProvider、MySqlProvider、DB2Provider、OleDbProvider) IDbProvider dbProvider = new OracleProvider(SystemInfo.BusinessDbConnectionString); bool result = true; try { dbProvider.BeginTransaction(); //主表 CASE_PRODUCTIN_MAINManager manager = new CASE_PRODUCTIN_MAINManager(dbProvider, Utils.UserInfo); CASE_PRODUCTIN_MAINEntity mainEntity = manager.GetEntity(dbProvider.SqlSafe(mainId)); manager.Delete(mainEntity); //子表 CASE_PRODUCTIN_DETAILManager detailManager = new CASE_PRODUCTIN_DETAILManager(dbProvider, Utils.UserInfo); CASE_PRODUCTIN_DETAILEntity detailEntity = detailManager.GetEntity(dbProvider.SqlSafe(detailId)); detailManager.Delete(detailEntity); //事务提交 dbProvider.CommitTransaction(); } catch (Exception ex) { //事务回滚 dbProvider.RollbackTransaction(); result = false; } return(result); }
private void GetProductMainEntity(HttpContext ctx) { var returnJson = "[]"; var vId = PublicMethod.GetString(getObj("keyid")); var manager = new CASE_PRODUCTIN_MAINManager(this.dbHelper); var entity = manager.GetEntity(vId); if (entity != null) { returnJson = JSONhelper.ToJson(entity); } ctx.Response.Write(returnJson); }
private void DelProductInfo(HttpContext ctx) { var vUser = Utils.UserInfo; var vId = PublicMethod.GetString(getObj("keyid")); var managerMain = new CASE_PRODUCTIN_MAINManager(this.dbHelper, vUser); var managerDetail = new CASE_PRODUCTIN_DETAILManager(this.dbHelper, vUser); var returnValue = managerMain.SetDeleted(vId); string[] names = { CASE_PRODUCTIN_DETAILTable.FieldCASE_PRODUCTIN_MAIN_ID, CASE_PRODUCTIN_DETAILTable.FieldDELETEMARK }; object[] values = { vId, 0 }; var ids = managerDetail.GetIds(names, values, CASE_PRODUCTIN_DETAILTable.FieldID); managerDetail.SetDeleted(ids as object[]); ctx.Response.Write(returnValue > 0 ? "1" : "0"); }
private string GetProductInMainJson(HttpContext context) { var returnJson = "[]"; var managerMain = new CASE_PRODUCTIN_MAINManager(this.dbHelper, Utils.UserInfo); var where = "DELETEMARK = 0"; var pageParam = new PageParam(context); if (!string.IsNullOrEmpty(pageParam.Filter)) { where = pageParam.Filter; } int recordCount; var dtProductIn = managerMain.GetDTByPage(out recordCount, pageParam.PageIndex, pageParam.PageSize, where, pageParam.SortField + " " + pageParam.Order); //RDIFrameworkService.Instance.RDIFrameworkDBProviderService.Fill(Utils.UserInfo, sql); if (dtProductIn != null && dtProductIn.Rows.Count > 0) { returnJson = JSONhelper.FormatJSONForEasyuiDataGrid(recordCount, dtProductIn); } return(returnJson); }
private string GetProductMultiPage(HttpContext context) { var returnJson = "[]"; var managerMain = new CASE_PRODUCTIN_MAINManager(this.dbHelper, Utils.UserInfo); var pageParam = new PageParam(context); int recordCount; managerMain.CurrentTableName = @"(SELECT tab1.ID,tab1.CODE,tab1.INDATE,tab1.INTYPE,tab1.CUSTODIAN,tab1.CREATEON,tab2.FULLNAME,tab2.AMOUNT,tab2.UNITPRICE FROM CASE_PRODUCTIN_MAIN tab1 INNER JOIN CASE_PRODUCTIN_DETAIL tab2 ON tab1.ID = tab2.CASE_PRODUCTIN_MAIN_ID) pageData"; managerMain.SelectField = "*"; var dtProductIn = managerMain.GetDTByPage(out recordCount, pageParam.PageIndex, pageParam.PageSize, null, "CREATEON DESC"); if (dtProductIn != null && dtProductIn.Rows.Count > 0) { returnJson = JSONhelper.FormatJSONForEasyuiDataGrid(recordCount, dtProductIn); } return(returnJson); }
//增加实体语句事务测试 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"); } }