Exemple #1
0
        public async Task GoToMod(string modId, string fieldName, string parr = "", string key = "")
        {
            HomeBus homeBus = new HomeBus(moduleService, iConfiguration, distributedCache);
            var     dataMod = await homeBus.GetModule(modId);

            if (!dataMod.ModulesInfo.Any())
            {
                //return RedirectToAction("Login", "Home");
            }

            var module    = homeBus.ConvertFromViewModel(dataMod);
            var btnParram = new List <ButtonParamInfo>();

            btnParram.Add(new ButtonParamInfo {
                FieldName = fieldName, Value = parr, ModuleID = modId
            });
            if (module.ModulesInfo.ModuleTypeName == EModuleType.MAINTAIN.ToString())
            {
                //return RedirectToAction("Edit", new { modId = modId, parram = JsonConvert.SerializeObject(btnParram) });
            }
            else
            {
                //return RedirectToAction("Search", new { modId = modId, parramMods = JsonConvert.SerializeObject(btnParram) });
            }
            //return View();
        }
Exemple #2
0
        public async Task BtnSearch(string export = "")
        {
            //if (string.IsNullOrEmpty(HttpContext.Session.GetString("UserName")))
            //{
            //    return RedirectToAction("Login", "Home");
            //}
            HomeBus homeBus = new HomeBus(moduleService, iConfiguration, distributedCache);
            var     data    = await homeBus.GetModule(modId);

            var module = homeBus.ConvertFromViewModel(data);

            ModuleInfo = module;
            var cb = module.FieldsInfo.Where(x => !String.IsNullOrEmpty(x.ListSource));

            if (cb.Any())
            {
                var sources        = cb.Select(x => x.ListSource).Distinct().ToList();
                var codeInfoParram = cb.Select(x => new CodeInfoParram
                {
                    CtrlType   = x.ControlType,
                    Name       = x.FieldName,
                    ListSource = x.ListSource
                });
                //var para = string.Join("", sources);
                var dataCB = (await moduleService.GetCombobox(codeInfoParram.ToList()));
                DataCombobox = dataCB.Data;
            }
            modSearch = await homeBus.LoadModSearchByModId(modId);

            if (modSearch != null)
            {
                var           fieldEdits = CommonFunction.GetModuleFields(moduleFieldInfo, modId, FLDGROUP.SEARCH_CONDITION);
                List <string> parrams    = new List <string>();
                foreach (var field in fieldEdits)
                {
                    if ((field.FieldType == EFieldType.DEC.ToString()) || (field.FieldType == EFieldType.INT.ToString()))
                    {
                        parrams.Add(string.Format("{0}={1}", field.FieldName, (field.Value ?? "").Trim()));
                    }
                    else
                    {
                        parrams.Add(string.Format("{0} LIKE N'%{1}%'", field.FieldName, (field.Value ?? "").Trim()));
                    }

                    var valid = field.ValidateFieldInfo();
                    if (!string.IsNullOrEmpty(valid))
                    {//Nếu validate trường dữ liệu có lỗi.
                        var invalidArr = valid.ToStringArray('.');
                        var fieldName  = field.FieldName;
                        string.Join(",", invalidArr.Select(x => fieldName + " " + x));
                    }
                }

                var query = "";
                if (modSearch.QueryFormat.IndexOf("{1}") > 0)
                {
                    if (modSearch.QueryFormat.IndexOf("{2}") > 0)
                    {
                        var paging = String.Format(" Limit {0} offset {1}", (currPage - 1) * CommonMethod.PageSize, (currPage - 1) * CommonMethod.PageSize + CommonMethod.PageSize);
                        query = string.Format(modSearch.QueryFormat, Schema, parrams.Any() ? String.Join(" AND ", parrams) : " 1=1 ", paging);
                    }
                    else
                    {
                        query = string.Format(modSearch.QueryFormat, Schema, parrams.Any() ? String.Join(" AND ", parrams) : " 1=1 ");
                    }
                }
                else
                {
                    query = String.Format(modSearch.QueryFormat, Schema);
                }

                //CurrPage = currPage;
                //FieldSubmited = fieldEdits;
                //Dongpv:
                //var dataGrid = await moduleService.LoadQueryModule(new ParramModuleQuery { Store = query });
                ////var dataGrid = await moduleService.LoadQueryModule(new ParramModuleQueryDynamicQuery { LogicConditionModels= SearchConditionInstances,SearchModuleInfo= modSearch });
                ////if (!string.IsNullOrEmpty(export))
                ////{
                ////    string pathSaveAs = Path.Combine(_hostingEnvironment.WebRootPath, String.Format("FileTemplate/TemplateExport_{0}.xls", DateTime.Now.ToString("dd-MM-yyyy")));
                ////    Data2ExcelFile(dataGrid, module.FieldsInfo, module, pathSaveAs);
                ////    return DownloadFile(pathSaveAs);
                ////}
                //DataSearch = dataGrid;
                ////int userId = int.Parse("0" + HttpContext.Session.GetString("UserId"));
                ////var groupModUser = await moduleService.GetGroupModByUserId(userId);
                ////ViewBag.RoleUser = groupModUser;

                var moduleFields = module.FieldsInfo.FirstOrDefault();

                if (modSearch.GroupModule == "004")
                {
                    string strCondition = " WHERE 1=1 ";
                    foreach (string parm in  parrams)
                    {
                        if (parm.IndexOf("N'%%'") == -1)
                        {
                            strCondition += " AND " + parm;
                        }
                    }

                    Message msg = new Message();
                    msg.ObjectName = Constants.OBJ_SEARCH;
                    msg.MsgType    = Constants.MSG_MISC_TYPE;
                    msg.MsgAction  = Constants.MSG_SEARCH;
                    msg.ModId      = modId;

                    msg.Body.Add("SearchObject");
                    msg.Body.Add(moduleFields.Entity);
                    msg.Body.Add("Condition");
                    msg.Body.Add(strCondition);
                    msg.Body.Add("Page");
                    msg.Body.Add(0);

                    var dataGrid = await moduleService.getQuery(msg);

                    DataSearch = dataGrid;
                }
                else
                {
                    var dataGrid = await moduleService.LoadQueryModule(new ParramModuleQuery { Store = query });

                    DataSearch = dataGrid;
                }
                //Dongpv:
            }
            //return View("Search", modId);
        }
Exemple #3
0
        protected override async Task OnInitializedAsync()
        {
            try
            {
                //if (string.IsNullOrEmpty(HttpContext.Session.GetString("UserName")) && modId.ToLower() != ConstMod.ModListHomo.ToLower())
                //{
                //    return RedirectToAction("Login", "Home");
                //    NavigationManager.NavigateTo("PageToRedirect");
                //}
                //Dongpv:look updata
                if (!string.IsNullOrEmpty(modId) && !string.IsNullOrEmpty(OrderID))
                {
                    ArrayList arrDetail = new ArrayList();
                    SysUtils.String2ArrayList(ref arrDetail, OrderID, "@", "=");
                    modId = SysUtils.getValue(arrDetail, "MODID").ToString();
                    //Fix
                    //modId = "03" + modId.Substring(2, 3);
                }
                //Dongpv:look updata

                CheckBoxModels  = new List <CheckBoxModel>();
                lstControl      = new List <ModuleFieldInfo>();
                moduleFieldInfo = new List <ModuleFieldInfo>();
                HomeBus homeBus = new HomeBus(moduleService, iConfiguration, distributedCache);
                var     data    = await homeBus.GetModule(modId);

                int userId       = int.Parse("0" + "" /*HttpContext.Session.GetString("UserId")*/);
                var groupModUser = await moduleService.GetGroupModByUserId(userId);

                RoleUser        = groupModUser;
                moduleInfoModel = homeBus.ConvertFromViewModel(data);
                //Set title
                var arr = new string[1];
                arr[0] = moduleInfoModel.ModulesInfo.ModuleName.GetLanguageTitle(moduleInfoModel.LanguageInfo);
                await JSRuntime.InvokeVoidAsync("SetTitle", arr);

                //Hết SetTitle
                Title = moduleInfoModel.ModulesInfo.ModuleName.GetLanguageTitle(await homeBus.LoadAllBtnLanguage());
                var cb      = moduleInfoModel.FieldsInfo.Where(x => !String.IsNullOrEmpty(x.ListSource));
                var scdType = moduleInfoModel.FieldsInfo.Select(x => x.ConditionType);
                if (cb.Any())
                {
                    var codeInfoParram = cb.Select(x => new CodeInfoParram
                    {
                        CtrlType   = x.ControlType,
                        Name       = x.FieldName,
                        ListSource = x.ListSource
                    });
                    //var para = string.Join("", sources);
                    var sourceCodeInfo = cb.Where(x => x.ListSource.Contains(":"));//Lấy những thông tin các ListSource từ DefCode
                    var codeInfoModels = new List <CodeInfoModel>();
                    if (sourceCodeInfo != null && sourceCodeInfo.Any())
                    {
                        var defCodeAll = await homeBus.LoadAllDefCode();

                        var lstSource = sourceCodeInfo.Select(x => x.ListSource).ToList();
                        var cbDefCode = defCodeAll.Where(x => lstSource.Contains(":" + x.CodeType + "." + x.CodeName));
                        foreach (var item in sourceCodeInfo)
                        {
                            codeInfoModels.Add(new CodeInfoModel {
                                Name = item.FieldName, CodeInfos = cbDefCode.Where(x => ":" + x.CodeType + "." + x.CodeName == item.ListSource).ToList()
                            });
                        }
                    }

                    var dataCB = (await moduleService.GetCombobox(codeInfoParram.Where(x => !x.ListSource.Contains(":")).ToList()));//Lấy thông tin các Combobox theo Store
                    codeInfoModels.AddRange(dataCB.Data);
                    DataCombobox = codeInfoModels;
                }

                modSearch = await homeBus.LoadModSearchByModId(modId);

                if (modSearch != null)
                {
                    var parrams = new List <string>();
                    if (!string.IsNullOrEmpty(parramMods))
                    {
                        var btnParramInfo = (List <ButtonParamInfo>)JsonConvert.DeserializeObject <List <ButtonParamInfo> >(parramMods);
                        var temp          = btnParramInfo.Select(x => x.FieldName + " = '" + x.Value + "'");
                        parrams.AddRange(temp);
                    }
                    var query = "";
                    if (modSearch.QueryFormat.IndexOf("{0}") > 0)
                    {
                        if (modSearch.QueryFormat.IndexOf("{1}") > 0)
                        {
                            var currPage = 1;
                            var paging   = String.Format("  Limit {1} offset {0}", (currPage - 1) * CommonMethod.PageSize, (currPage - 1) * CommonMethod.PageSize + CommonMethod.PageSize);
                            query = string.Format(modSearch.QueryFormat, Schema, parrams.Any() ? String.Join(" AND ", parrams) : " 1=1 ", paging);
                        }
                        else
                        {
                            query = string.Format(modSearch.QueryFormat, Schema, parrams.Any() ? String.Join(" AND ", parrams) : " 1=1 ");
                        }
                    }
                    else
                    {
                        query = String.Format(modSearch.QueryFormat, Schema);
                    }

                    //Dongpv:
                    //var dataGrid = await moduleService.LoadQueryModule(new ParramModuleQuery { Store = query });
                    var moduleFields = moduleInfoModel.FieldsInfo.FirstOrDefault();
                    if (modSearch.GroupModule == "004")
                    {
                        Message msg = new Message();
                        msg.MsgType    = Constants.MSG_MISC_TYPE; //MESSAGE TYPE: INQ, MAINTAIN, TXN, REPORT
                        msg.ObjectName = Constants.OBJ_SEARCH;
                        msg.MsgAction  = Constants.MSG_SEARCH;

                        msg.Body.Add("SearchObject");
                        msg.Body.Add(moduleFields.Entity);
                        msg.Body.Add("Condition");
                        msg.Body.Add(" WHERE 1=1");
                        msg.Body.Add("Page");
                        msg.Body.Add(0);

                        var dataGrid = await moduleService.getQuery(msg);

                        DataSearch = dataGrid;
                    }
                    else
                    {
                        var dataGrid = await moduleService.LoadQueryModule(new ParramModuleQuery { Store = query });

                        DataSearch = dataGrid;
                    }
                    //Dongpv:

                    //var dataGrid = await _moduleService.LoadQueryModule(new ParramModuleQuery { Store = modSearch.QueryFormat });
                    ////Dongpv:
                    //DataSearch = dataGrid;

                    btnInfos = moduleInfoModel.ButtonsInfo == null ? new List <ButtonInfo>() : moduleInfoModel.ButtonsInfo;
                    var moduleInfo = moduleInfoModel.ModulesInfo == null ? new ModuleInfo() : moduleInfoModel.ModulesInfo;
                    moduleFieldInfo = moduleInfoModel.FieldsInfo == null ? new List <ModuleFieldInfo>() : moduleInfoModel.FieldsInfo;
                    var parrs = moduleInfoModel.ButtonParamsInfo == null ? new List <ButtonParamInfo>() : moduleInfoModel.ButtonParamsInfo;
                    codeInfos        = DataCombobox;
                    checkColAction   = btnInfos.Where(x => x.ShowOnToolbar == "N").ToList();
                    checkBtnViews    = btnInfos.Where(x => x.ButtonName.ToUpper() == EDefModBtn.BTN_VIEW.ToString().ToUpper()).ToList();
                    checkBtnEdits    = btnInfos.Where(x => x.ButtonName.ToUpper() == EDefModBtn.BTN_EDIT.ToString().ToUpper()).ToList();
                    checkBtnDels     = btnInfos.Where(x => x.ButtonName.ToUpper() == EDefModBtn.BTN_DELETE.ToString().ToUpper()).ToList();
                    checkBtnAssRole  = btnInfos.Where(x => x.ButtonName.ToUpper() == EDefModBtn.BTN_ASSIGN_ROLE.ToString().ToUpper()).ToList();
                    checkBtnAssUsers = btnInfos.Where(x => x.ButtonName.ToUpper() == EDefModBtn.BTN_ASSIGN_USER.ToString().ToUpper()).ToList();
                    if (groupMods == null || groupMods.Count == 0)
                    {
                        groupMods = new List <GroupMod>();
                        groupMods.Add(new GroupMod {
                            GroupId = "1", ModId = moduleInfoModel.ModulesInfo.ModuleID
                        });
                        if (checkBtnEdits.Any())
                        {
                            groupMods.Add(new GroupMod {
                                GroupId = "1", ModId = checkBtnEdits.First().CallModuleID
                            });
                        }
                        if (checkBtnDels.Any())
                        {
                            groupMods.Add(new GroupMod {
                                GroupId = "1", ModId = checkBtnDels.First().CallModuleID
                            });
                        }
                    }
                    checkBtnDel        = checkBtnDels.Any();
                    checkBtnView       = checkBtnViews.Any();
                    checkBtnEdit       = checkBtnEdits.Any();
                    checkBtnAssignRole = checkBtnAssRole.Any();
                    checkBtnAssignUser = checkBtnAssUsers.Any();
                    parramEdit         = new List <ButtonParamInfo>();
                    parramView         = new List <ButtonParamInfo>();

                    parramDel        = new List <ButtonParamInfo>();
                    parramAssignUser = new List <ButtonParamInfo>();
                    if (checkBtnView)
                    {
                        var parramViews = parrs.Where(x => x.ButtonName == EDefModBtn.BTN_VIEW.ToString());
                        if (parramViews.Any())
                        {
                            parramView = parramViews.ToList();
                        }
                    }
                    if (checkBtnEdit)
                    {
                        var parramEdits = parrs.Where(x => x.ButtonName == EDefModBtn.BTN_EDIT.ToString());
                        if (parramEdits.Any())
                        {
                            parramEdit = parramEdits.ToList();
                        }
                    }
                    if (checkBtnDel)
                    {
                        var parramDels = parrs.Where(x => x.ButtonName == EDefModBtn.BTN_DELETE.ToString());
                        if (parramDels.Any())
                        {
                            parramDel = parramDels.ToList();
                        }
                    }
                    if (checkBtnAssignUser)
                    {
                        var parramAssignUsers = parrs.Where(x => x.ButtonName == EDefModBtn.BTN_ASSIGN_USER.ToString());
                        if (parramAssignUsers.Any())
                        {
                            parramAssignUser = parramAssignUsers.ToList();
                        }
                    }
                }

                //return View("Search", modId);
            }
            catch (Exception ex)
            {
                //return View("Search", modId);
            }
        }