Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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");
            }
        }