Пример #1
0
 public dynamic Get(RequestWrapper request)
 {
     request.SetJson("{where:[{column:'CodeType',ignore:'empty'}],orderby:'Seq'}");
     var service = new sys_codeService();
     var result = service.GetModelListWithPaging(request.ToParamQuery());
     return result;
 }
Пример #2
0
        // 查询主表:GET api/mms/send
        public dynamic Get(RequestWrapper query)
        {
            query.SetXml(@"
<settings  >
    <select>
        *
    </select>
    <from>
        test_user
    </from>
    <where>
        <c column='UserCode'        ignore='empty'     symbol='like'      ></c>
        <c column='UserName'        ignore='empty'     symbol='like'      ></c>
        <c column='Description'     ignore='empty'     symbol='like'      ></c>
        <c column='IsEnable'        ignore='empty'     symbol='equal'      ></c>
        <c column='LoginCount'      ignore='empty'     symbol='equal'      ></c>
        <c column='LastLoginDate'   ignore='empty'     symbol='daterange'      ></c>
    </where>
    <orderby>UserCode</orderby>
</settings>");

            var pQuery = query.ToParamQuery();
            var list = new mms_sendService().GetDynamicListWithPaging(pQuery);
            return list;
        }
        public dynamic Get(RequestWrapper request)
        {
            request.LoadSettingXmlString(@"
<settings defaultOrderBy='MerchantsCode'>
   <where>
        <field name='MerchantsTypeCode' cp='equal' ignoreEmpty='true'></field>
    </where>
</settings>");
            var service = new mms_merchantsService();
            var result = service.GetModelListWithPaging(request.ToParamQuery());
            return result;
        }
Пример #4
0
        public dynamic GetCodeType(RequestWrapper request)
        {
            request.SetJson(@"{
where:[
{column:'CodeType',ignore:'empty'},
{column:'CodeTypeName',symbol:'like',ignore:'empty'}
],
orderby:'Seq,CodeType'
}");
            var result =  new sys_codeTypeService().GetDynamicListWithPaging(request.ToParamQuery());
            return result;
        }
Пример #5
0
        public dynamic GetLoginLog(RequestWrapper request) 
        {
            var service = new sys_loginHistoryService();
            request.SetXml(@"
<settings>
    <select>A.*</select>
    <from>sys_loginHistory A</from>
    <where><c column='LoginDate' values='{LogDate}' symbol='daterange' ignore='empty'></c></where>
    <orderby>ID desc</orderby>
</settings>");
            return service.GetModelListWithPaging(request.ToParamQuery());
        }
Пример #6
0
        public dynamic Get(RequestWrapper request) 
        {
            request.LoadSettingXmlString(@"
<settings defaultOrderBy='UserSeq'>
   <where>
        <field name='UserCode' cp='mapchild' extend='sys_userOrganizeMap,OrganizeCode,sys_organize' variable='OrganizeCode' ignoreEmpty='true'></field>
    </where>
</settings>");
            var service = new sys_userService();
            var result = service.GetModelListWithPaging(request.ToParamQuery());
            return result;
        }
        public dynamic Get(RequestWrapper request)
        {
            request.SetXml(@"
<settings>
    <where>
        <c column='ProjectCode' symbol='equal' ignore='empty'></c>
    </where>
    <orderby>WarehouseCode</orderby>
</settings>");
            var service = new mms_warehouseService();
            var result = service.GetModelListWithPaging(request.ToParamQuery());
            return result;
        }
        public dynamic GetTypes(RequestWrapper request)
        {
            request.LoadSettingXmlString(@"
<settings defaultOrderBy='MerchantsTypeCode'>
   <where defaultIgnoreEmpty='true'>
        <field name='MerchantsTypeCode'      cp='equal'></field>
        <field name='MerchantsTypeName'  cp='like' ></field>
    </where>
</settings>
");
            var result = new mms_merchantsTypeService().GetDynamicListWithPaging(request.ToParamQuery());
            return result;
        }
Пример #9
0
        public dynamic Get(RequestWrapper request) 
        {
            request.SetXml(@"
<settings>
   <where>
        <c column='UserCode' symbol='mapchild' values='{OrganizeCode},sys_userOrganizeMap,OrganizeCode,sys_organize' ignore='empty'></c>
    </where>
    <orderby>UserSeq</orderby>
</settings>");
            var service = new sys_userService();
            var result = service.GetModelListWithPaging(request.ToParamQuery());
            return result;
        }
        public List<dynamic> Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='DEPTID'>
    <select>*</select>
    <from>REMP_Department</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
    </where>
</settings>");
            var service = new REMP_DepartmentService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #11
0
        public dynamic GetTypes(RequestWrapper request)
        {
            request.SetXml(@"
<settings>
   <where>
        <c column='MerchantsTypeCode'      symbol='equal' ignore='empty'></c>
        <c column='MerchantsTypeName'      symbol='like'  ignore='empty'></c>
    </where>
    <orderby>MerchantsTypeCode</orderby>
</settings>
");
            var result = new mms_merchantsTypeService().GetDynamicListWithPaging(request.ToParamQuery());
            return result;
        }
Пример #12
0
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='ID'>
    <select>*</select>
    <from>sys_code</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='Code' cp='equal'></field>   
        <field name='Text' cp='equal'></field>   
    </where>
</settings>");
            var service = new sys_codeService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='ID'>
    <select>*</select>
    <from>mms_merchants</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='MerchantsTypeName' cp='equal'></field>   
        <field name='RegisterFund' cp='equal'></field>   
    </where>
</settings>");
            var service = new mms_merchantsService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #14
0
        public dynamic GetOperateLog(RequestWrapper request) 
        {
            var service = new sys_logService();
            request.LoadSettingXmlString(@"
<settings defaultOrderBy='ID desc'>
    <select>
        A.*
    </select>
    <from>
        sys_log A
    </from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='Date'           cp='daterange' variable='LogDate'  ></field>
    </where>
</settings>");
            return service.GetModelListWithPaging(request.ToParamQuery());
        }
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='RowId'>
    <select>*</select>
    <from>mms_lossReportBatches</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='MaterialCode'		cp='equal'></field>   
        <field name='Money'		cp='equal'></field>   
        <field name='SrcRowId'		cp='equal'></field>   
    </where>
</settings>");
            var service = new mms_lossReportBatchesService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='ID'>
    <select>*</select>
    <from>mms_lossReport</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='BillNo' cp='equal'></field>   
        <field name='BillDate' cp='equal'></field>   
        <field name='DoPerson' cp='equal'></field>   
    </where>
</settings>");
            var service = new mms_lossReportService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #17
0
        public dynamic GetSystemLog(RequestWrapper request) 
        {
            var page = ZConvert.To<int>(request["page"], 1);
            var rows = ZConvert.To<int>(request["rows"], 0);
            var logDate = ZConvert.ToString(request["logdate"]);

            var list = new List<dynamic>();
            var basepath = HttpContext.Current.Server.MapPath("/logs/");
            var di = new DirectoryInfo(basepath);
            if (!di.Exists) di.Create();

            string[] s = logDate.Split('到');
            string s1 = "1990-01-01";
            string s2 = DateTime.Now.Date.ToString();
            switch (s.Length)
            { 
                case 1:
                    if (logDate.Length > 0)
                    {
                        s1 = s[0];
                        s2 = s1;
                    }
                    break;
                case 2:
                    s1 = s[0];
                    s2 = s[1];
                    break;
            }

            int t1 = Convert.ToInt32(Convert.ToDateTime(s1).ToString("yyyyMMdd"));
            int t2 = Convert.ToInt32(Convert.ToDateTime(s2).ToString("yyyyMMdd"));

            foreach (var fi in di.GetFiles().Where(x => (Convert.ToInt32(x.FullName.Replace(basepath, "").Substring(3,8)) >= t1 && Convert.ToInt32(x.FullName.Replace(basepath, "").Substring(3,8)) <= t2)))
            {
                dynamic item = new ExpandoObject();
                item.filename = fi.FullName.Replace(basepath, "");
                item.size = (fi.Length / 1024).ToString() + " KB";
                item.time = fi.CreationTime.ToString();
                item.id = item.filename.Replace(".txt", "");
                list.Add(item);
            }

            var result = list.OrderByDescending(x => x.filename).Skip((page - 1) * rows).Take(rows);
            return new { rows = result, total = list.Count() };
        }
Пример #18
0
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='Id'>
    <select>*</select>
    <from>psi_supplier</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='Id'            cp='equal'></field>
        <field name='Name'          cp='like' ></field>
        <field name='ChargePerson'  cp='like'></field>
        <field name='Catagory'      cp='equal'></field>
    </where>
</settings>");
            var service = new psi_supplierService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #19
0
        public dynamic Get(RequestWrapper query)
        {
            query.SetXml(@"
<settings >
    <select>*</select>
    <from>base_line</from>
    <where>
        <c column='linecd'		symbol='like' ignore='empty'></c>   
        <c column='line'		symbol='like' ignore='empty'></c>   
        <c column='bizlist'		symbol='like' ignore='empty'></c>   
    </where>
    <orderby>keyid</orderby>
</settings>");
            var service = new base_lineService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='ID'>
    <select>*</select>
    <from>mms_productTest</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='ProductName'		cp='like'></field>   
        <field name='ProductCode'		cp='startwith'></field>   
        <field name='ProductColor'		cp='equal'></field>   
        <field name='ProductType'		cp='equal'></field>   
        <field name='ProductDate'		cp='daterange'></field>   
    </where>
</settings>");
            var service = new mms_productTestService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #21
0
        public dynamic Get(RequestWrapper query)
        {
            query.SetXml(@"
<settings >
    <select>*</select>
    <from>base_area</from>
    <where>
        <c column='areacd'		symbol='equal' ignore='empty'></c>   
        <c column='parentcd'		symbol='equal' ignore='empty'></c>   
        <c column='areahelpcd'		symbol='equal' ignore='empty'></c>   
        <c column='areaname'		symbol='equal' ignore='empty'></c>   
    </where>
    <orderby>keyid</orderby>
</settings>");
            var service = new base_areaService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #22
0
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='ID'>
    <select>*</select>
    <from>test_liy</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='DepartmentID'		cp='equal'></field>   
        <field name='IsValid'		cp='equal'></field>   
        <field name='ApproveState'		cp='equal'></field>   
        <field name='Remark'		cp='like'></field>   
        <field name='OutDateTime'		cp='daterange'></field>   
    </where>
</settings>");
            var service = new test_liyService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #23
0
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='ID'>
    <select>*</select>
    <from>mms_test</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='ID'                    cp='equal'></field>
        <field name='ProjectName'           cp='like' ></field>
        <field name='DeclaringUnits'        cp='like'></field>
        <field name='ProjectType'           cp='equal'></field>
        <field name='StartDate'             cp='dtgreaterequal'></field>
        <field name='EndDate'               cp='dtlessequal'></field>
    </where>
</settings>");
            var service = new mms_testService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #24
0
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='ProjectCode'>
    <select>*</select>
    <from>mms_project</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='ParentCode' cp='equal'></field>   
        <field name='ShortName' cp='equal'></field>   
        <field name='ProjectName' cp='equal'></field>   
        <field name='OwnerUnit' cp='equal'></field>   
        <field name='DesignUnit' cp='equal'></field>   
        <field name='ConstructionUnit' cp='equal'></field>   
    </where>
</settings>");
            var service = new mms_projectService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #25
0
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='BillNo'>
    <select>*</select>
    <from>mms_deal</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='ProjectCode'		cp='like'></field>   
        <field name='ApplyDate'		cp='daterange'></field>   
        <field name='DealType'		cp='equal'></field>   
        <field name='DealKind'		cp='equal'></field>   
        <field name='TotalMoney'		cp='equal'></field>   
        <field name='ApproveState'		cp='equal'></field>   
    </where>
</settings>");
            var service = new mms_dealService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #26
0
        public dynamic Get(RequestWrapper query)
        {
            query.SetXml(@"
<settings >
    <select>*</select>
    <from>mms_send</from>
    <where>
        <c column='BillNo'		symbol='equal' ignore='empty'></c>   
        <c column='BillDate'		symbol='equal' ignore='empty'></c>   
        <c column='DoPerson'		symbol='equal' ignore='empty'></c>   
        <c column='ProjectCode'		symbol='equal' ignore='empty'></c>   
        <c column='WarehouseCode'		symbol='equal' ignore='empty'></c>   
    </where>
    <orderby>BillNo</orderby>
</settings>");
            var service = new mms_sendService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #27
0
        public dynamic Get(RequestWrapper query)
        {
            query.SetXml(@"
<settings>
    <select>*</select>
    <from>test_liy</from>
    <where>
        <c column='DepartmentID'		cp='equal'    ignore='empty'></c>   
        <c column='IsValid'		        cp='equal'    ignore='empty'></c>   
        <c column='ApproveState'		cp='equal'    ignore='empty'></c>   
        <c column='Remark'		        cp='like'     ignore='empty'></c>   
        <c column='OutDateTime'		    cp='daterange' ignore='empty'></c>   
    </where>
    <orderby>ID</orderby>
</settings>");
            var service = new test_liyService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #28
0
        public dynamic Get(RequestWrapper query)
        {
            query.SetXml(@"
<settings>
    <select>*</select>
    <from>mms_product</from>
    <where>
        <c column='ProductName'   ignore='empty'  symbol='like'></c>
        <c column='Color'         ignore='empty'  symbol='equal' ></c>
        <c column='Price'         ignore='empty'  symbol='equal'></c>
        <c column='Unit'          ignore='empty'  symbol='equal'></c>
        <c column='Remark'        ignore='empty'  symbol='like'></c>
        <c column='CreateDate'    ignore='empty'  symbol='daterange'></c>
    </where>
    <orderby>ID</orderby>
</settings>");
            var service = new mms_productService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #29
0
        public dynamic Get(RequestWrapper query)
        {
            query.SetXml(@"
<settings>
    <select>*</select>
    <from>mms_test</from>
    <where>
        <c column='ID'                ignore='empty'    symbol='equal'></c>
        <c column='ProjectName'       ignore='empty'    symbol='like' ></c>
        <c column='DeclaringUnits'    ignore='empty'    symbol='like'></c>
        <c column='ProjectType'       ignore='empty'    symbol='equal'></c>
        <c column='StartDate'         ignore='empty'    symbol='dtgreaterequal'></c>
        <c column='EndDate'           ignore='empty'    symbol='dtlessequal'></c>
    </where>
    <orderby>ID</orderby>
</settings>");
            var service = new mms_testService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
        public dynamic Get(RequestWrapper query)
        {
            query.SetXml(@"
<settings>
    <select>*</select>
    <from>trade_scheduler</from>
    <where>
        <c column='JOBNO'		symbol='equal' ignore='empty'></c>   
        <c column='SNO'		symbol='equal' ignore='empty'></c>   
        <c column='SC_DRIVER'		symbol='equal' ignore='empty'></c>   
        <c column='SC_TRUCKCD'		symbol='equal' ignore='empty'></c>   
        <c column='SC_DISTANCEID'		symbol='equal' ignore='empty'></c>   
        <c column='SC_ONCNTDATE'		symbol='equal' ignore='empty'></c>   
        <c column='SC_ARRIVEDATE'		symbol='equal' ignore='empty'></c>   
    </where>
    <orderby>JOBNO</orderby>
</settings>");
            var service = new trade_schedulerService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);
            return result;
        }
Пример #31
0
        public int Edit(JObject data, RequestWrapper formWrapper, List <RequestWrapper> tabsWrapper)
        {
            const string DATA_TYPE_DELETED  = "deleted";
            const string DATA_TYPE_UPDATED  = "updated";
            const string DATA_TYPE_INSERTED = "inserted";

            const string DATA_TYPE_FORM  = "form";
            const string DATA_TYPE_TABS  = "tabs";
            const string DATA_TYPE_ARRAY = "Array";

            Dictionary <string, OptType> actionTypes = new Dictionary <string, OptType> {
                { DATA_TYPE_DELETED, OptType.Del },
                { DATA_TYPE_UPDATED, OptType.Mod },
                { DATA_TYPE_INSERTED, OptType.Add }
            };

            var handles = new Dictionary <string, Func <RequestWrapper, int> > {
                { DATA_TYPE_DELETED, x => BuilderParse(x.ToParamDelete()).Execute() },
                { DATA_TYPE_UPDATED, x => BuilderParse(x.ToParamUpdate()).Execute() },
                { DATA_TYPE_INSERTED, x => BuilderParse(x.ToParamInsert()).Execute() }
            };

            var rowsAffected = 0;

            Logger("编辑记录", () =>
            {
                var formData = data[DATA_TYPE_FORM];
                var tabsData = data[DATA_TYPE_TABS];
                var editArgs = new EditEventArgs()
                {
                    db = db, data = data, formWrapper = formWrapper, tabsWrapper = tabsWrapper
                };

                //开启事务
                db.UseTransaction(true);

                //更新全部数据之前事件
                var rtnBefore = this.OnBeforeEdit(editArgs);
                if (!rtnBefore)
                {
                    return;
                }

                //更新主表
                if (formData != null && formWrapper != null)
                {
                    formWrapper.SetValue(formData);
                    var changedFieldCount = formWrapper.ToParamUpdate().GetData().Columns.Count;

                    //如果有字段被修改则更新
                    if (changedFieldCount > 0)
                    {
                        //到数据库中取得旧值
                        var formOld   = BuilderParse(formWrapper.ToParamQuery()).QuerySingleDynamic();
                        var strAction = (formOld == null) ? DATA_TYPE_INSERTED : DATA_TYPE_UPDATED;

                        //事件参数
                        editArgs.dataNew     = formData;
                        editArgs.dataOld     = formOld ?? new JObject();
                        editArgs.dataAction  = actionTypes[strAction];
                        editArgs.dataWrapper = formWrapper;

                        //主表编辑前事件
                        rtnBefore = this.OnBeforeEditForm(editArgs);
                        if (!rtnBefore)
                        {
                            return;
                        }

                        //主表数据处理
                        formWrapper.SetValue(editArgs.dataNew);
                        editArgs.executeValue = handles[strAction](formWrapper);
                        rowsAffected         += editArgs.executeValue;

                        //把未修改的数据更新到form新值上,避免在后面的事件中使用formNew值时为null出现错误
                        if (editArgs.dataAction == OptType.Mod)
                        {
                            EachHelper.EachObjectProperty(editArgs.dataOld as object, (i, name, value) =>
                            {
                                if (editArgs.dataNew[name] == null)
                                {
                                    editArgs.dataNew[name] = JToken.FromObject(value ?? string.Empty);
                                }
                            });
                        }

                        //主表编辑结束事件
                        this.OnAfterEditForm(editArgs);
                    }
                }

                //更新tabs
                if (tabsData != null && tabsWrapper != null)
                {
                    var current      = 0;
                    var wrapperCount = tabsWrapper.Count;

                    foreach (JToken tab in tabsData.Children())
                    {
                        //如果Tab数据长度大于wrapper长度,则结束
                        if (current > wrapperCount - 1)
                        {
                            break;
                        }

                        //如果数据为null或未配置相应的wrapper则跳过处理
                        var wrapper = tabsWrapper[current];
                        if (tab == null || wrapper == null)
                        {
                            continue;
                        }

                        //判断是form类型还是grid类型
                        bool IsGrid = (tab[DATA_TYPE_DELETED] != null && tab[DATA_TYPE_DELETED].Type.ToString() == DATA_TYPE_ARRAY) ||
                                      (tab[DATA_TYPE_UPDATED] != null && tab[DATA_TYPE_UPDATED].Type.ToString() == DATA_TYPE_ARRAY) ||
                                      (tab[DATA_TYPE_INSERTED] != null && tab[DATA_TYPE_INSERTED].Type.ToString() == DATA_TYPE_ARRAY);

                        //事件参数
                        editArgs.dataWrapper = wrapper;
                        editArgs.tabIndex    = current++;
                        editArgs.tabType     = IsGrid ? TabType.Grid : TabType.Form;
                        editArgs.tabData     = tab;

                        if (IsGrid)
                        {
                            foreach (JProperty item in tab.Children())
                            {
                                //只处理deleted updated inserted三个节点
                                if (!handles.ContainsKey(item.Name))
                                {
                                    continue;
                                }

                                //循环每一行数据
                                foreach (var row in item.Value.Children())
                                {
                                    //到数据库中取得旧值
                                    wrapper.SetValue(row);
                                    var rowOld = BuilderParse(wrapper.ToParamQuery()).QuerySingleDynamic();

                                    //事件参数
                                    editArgs.dataNew    = row;
                                    editArgs.dataOld    = rowOld ?? new JObject();
                                    editArgs.dataAction = actionTypes[item.Name];

                                    //行编辑前事件
                                    rtnBefore = this.OnBeforeEditRow(editArgs);
                                    if (!rtnBefore)
                                    {
                                        return;
                                    }

                                    //数据处理
                                    wrapper.SetValue(editArgs.dataNew);
                                    editArgs.executeValue = handles[item.Name](wrapper);
                                    rowsAffected         += editArgs.executeValue;

                                    //行编辑后事件
                                    this.OnAfterEditRow(editArgs);
                                }
                            }
                        }
                        else
                        {
                            wrapper.SetValue(tab);
                            var changedFieldCount = wrapper.ToParamUpdate().GetData().Columns.Count;

                            //如果有字段被修改则更新
                            if (changedFieldCount > 0)//更新主表
                            {
                                //到数据库中取得旧值
                                var formOld   = BuilderParse(wrapper.ToParamQuery()).QuerySingleDynamic();
                                var strAction = (formOld == null) ? DATA_TYPE_INSERTED : DATA_TYPE_UPDATED;

                                //事件参数
                                editArgs.dataNew     = tab;
                                editArgs.dataOld     = formOld ?? new JObject();
                                editArgs.dataAction  = actionTypes[strAction];
                                editArgs.dataWrapper = wrapper;

                                //Form编辑前事件
                                rtnBefore = this.OnBeforeEditRow(editArgs);
                                if (!rtnBefore)
                                {
                                    return;
                                }

                                //Form数据处理
                                wrapper.SetValue(editArgs.dataNew);
                                editArgs.executeValue = handles[strAction](wrapper);
                                rowsAffected         += editArgs.executeValue;

                                //把未修改的数据更新到form新值上
                                if (editArgs.dataAction == OptType.Mod)
                                {
                                    EachHelper.EachObjectProperty(editArgs.dataOld as object, (i, name, value) =>
                                    {
                                        if (editArgs.dataNew[name] == null)
                                        {
                                            editArgs.dataNew[name] = JToken.FromObject(value ?? string.Empty);
                                        }
                                    });
                                }

                                //Form编辑结束事件
                                this.OnAfterEditRow(editArgs);
                            }
                        }
                    }
                }

                //更新全部数据之后事件
                editArgs.executeValue = rowsAffected;
                this.OnAfterEdit(editArgs);

                //提交事务
                if (rowsAffected > 0)
                {
                    db.Commit();
                }
            }, e => db.Rollback());

            return(rowsAffected);
        }
Пример #32
0
        public int Edit(RequestWrapper formWrapper, RequestWrapper listWrapper, JObject data)
        {
            #region 定义变量
            var types = new Dictionary <string, OptType> {
                { "deleted", OptType.Del },
                { "updated", OptType.Mod },
                { "inserted", OptType.Add }
            };

            var handles = new Dictionary <string, Func <RequestWrapper, int> > {
                { "deleted", x => BuilderParse(x.ToParamDelete()).Execute() },
                { "updated", x => BuilderParse(x.ToParamUpdate()).Execute() },
                { "inserted", x => BuilderParse(x.ToParamInsert()).Execute() }
            };
            #endregion

            var rowsAffected = 0;

            Logger("编辑记录", () =>
            {
                db.UseTransaction(true); //开启事务
                var editArgs = new EditEventArgs()
                {
                    db = db, form = data["form"], list = data["list"]
                };

                if (data["form"] != null && formWrapper != null)
                {
                    editArgs.wrapper = formWrapper;
                    editArgs.formOld = this.GetDynamic(formWrapper.SetRequestData(editArgs.form).ToParamQuery()) ?? new JObject();
                    var rtnBefore    = this.OnBeforEdit(editArgs);
                    if (!rtnBefore)
                    {
                        return;
                    }

                    var pUpdate = formWrapper.SetRequestData(editArgs.form).ToParamUpdate();
                    if (pUpdate.GetData().Columns.Count > 0)//更新主表
                    {
                        rtnBefore = this.OnBeforEditMaster(editArgs);
                        if (rtnBefore)
                        {
                            pUpdate      = formWrapper.SetRequestData(editArgs.form).ToParamUpdate(); //在before事件中更改了form中的值,刷新更新时的值
                            rowsAffected = BuilderParse(pUpdate).Execute();
                            if (rowsAffected == 0)
                            {
                                rowsAffected = BuilderParse(formWrapper.ToParamInsert()).Execute();
                            }

                            editArgs.executeValue = rowsAffected;
                            this.OnAfterEditMaster(editArgs);
                        }
                    }

                    if (editArgs.formOld != null && editArgs.formOld.GetType() != typeof(JObject))
                    {
                        EachHelper.EachObjectProperty(editArgs.formOld as object, (i, name, value) => {
                            if (editArgs.form[name] == null)
                            {
                                editArgs.form[name] = JToken.FromObject(value ?? string.Empty);
                            }
                        });
                    }
                }

                if (data["list"] != null && listWrapper != null)
                {
                    editArgs.wrapper = listWrapper;

                    foreach (JProperty item in data["list"].Children())
                    {
                        if (!handles.ContainsKey(item.Name))
                        {
                            continue;
                        }

                        foreach (var row in item.Value.Children())
                        {
                            editArgs.row    = row;
                            editArgs.type   = types[item.Name];
                            editArgs.rowOld = this.GetDynamic(listWrapper.SetRequestData(editArgs.row).ToParamQuery()) ?? new JObject();

                            var rtnBefore = this.OnBeforEditDetail(editArgs);
                            if (!rtnBefore)
                            {
                                continue;
                            }
                            editArgs.executeValue = handles[item.Name](listWrapper.SetRequestData(row));
                            rowsAffected         += editArgs.executeValue;

                            this.OnAfterEditDetail(editArgs);
                        }
                    }
                }

                editArgs.executeValue = rowsAffected;
                editArgs.wrapper      = formWrapper;

                this.OnAfterEdit(editArgs);

                if (rowsAffected > 0)
                {
                    db.Commit();
                    this.OnAfterSave(editArgs);
                    Msg.Set(MsgType.Success, APP.MSG_SAVE_SUCCESS);
                }
            }, e => db.Rollback());

            return(rowsAffected);
        }