Esempio n. 1
0
        public async Task <AjaxResult> GetItemData([FromUri] PageResult page)
        {
            var data = from a in BLLSession.IHard_MaterialItemBLL.Query(u => true)
                       join b in BLLSession.IHard_MaterialTypeBLL.Query(u => true)
                       on a.MatTypeNo equals b.MatTypeNo
                       join c in BLLSession.IHard_MaterialTypeBLL.Query(u => true)
                       on a.SubItemNo equals c.MatTypeNo
                       orderby a.CreateTime descending
                       select new
            {
                a.SerialNo,
                TypeNo = b.SerialNo,
                a.MatTypeNo,
                b.MatTypeName,
                a.SubItemNo,
                SubType = c.MatTypeName,
                a.Brand,
                a.ItemModel,
                a.ConfigDesc,
                a.AttachFiles,
                a.WarrantyPeriod,
                a.warrantyType,
                a.WarrantyCost,
                a.PurchasePrice,
                a.Offer,
                a.IsStop,
                a.IsEnergy,
                a.LastTime,
                a.DeliveryDay,
                a.CreateTime,
            };

            if (!string.IsNullOrEmpty(page.QueryKey))
            {
                string[] list = new JavaScriptSerializer().Deserialize <string[]>(page.QueryKey);
                if (list.Length > 0)
                {
                    data = data.Where(u => list.Contains(u.MatTypeName) || list.Contains(u.SubType) || list.Contains(u.Brand) || list.Contains(u.ItemModel));
                }
            }

            //查询条件
            //data = supplyList.WhereIf(!string.IsNullOrEmpty(page.QueryKey), u => u.PoNo.Contains(page.QueryKey)); new LinqPage(page.PageIndex, page.PageSize, page.Order, page.Sort)
            return(AjaxResult.ToJSON(new { total = data.Count(), rows = await data.PageResult(GetLinqPage(page.PageIndex, page.PageSize, "CreateTime", "desc")).ToListAsync <dynamic>() }));
        }
Esempio n. 2
0
        public Tuple <bool, string> FileVerify(string FilePath, string FileName, string PeriodPublicId)
        {
            var Excel = new FileInfo(FilePath);

            List <PlanModel> oCurrentPeriodList = ProveedoresOnLine.ThirdKnowledge.Controller.ThirdKnowledgeModule.GetCurrenPeriod(SessionModel.CurrentCompany.CompanyPublicId, true);

            using (var package = new ExcelPackage(Excel))
            {
                // Get the work book in the file
                ExcelWorkbook workBook = package.Workbook;

                if (workBook != null)
                {
                    object[,] values = (object[, ])workBook.Worksheets.First().Cells["A1:C1"].Value;

                    string UncodifiedObj = new JavaScriptSerializer().Serialize(values);
                    if (UncodifiedObj.Contains(Models.General.InternalSettings.Instance
                                               [Models.General.Constants.MP_CP_ColPersonType].Value) &&
                        UncodifiedObj.Contains(Models.General.InternalSettings.Instance
                                               [Models.General.Constants.MP_CP_ColIdNumber].Value) &&
                        UncodifiedObj.Contains(Models.General.InternalSettings.Instance
                                               [Models.General.Constants.MP_CP_ColIdName].Value))
                    {
                        bool isLoaded = ProveedoresOnLine.ThirdKnowledge.Controller.ThirdKnowledgeModule.AccessFTPClient(FileName, FilePath, PeriodPublicId);
                        if (isLoaded)
                        {
                            //Get The Active Plan By Customer
                            oCurrentPeriodList.FirstOrDefault().RelatedPeriodModel.FirstOrDefault().TotalQueries += (workBook.Worksheets[1].Dimension.End.Row - 1);
                            ProveedoresOnLine.ThirdKnowledge.Controller.ThirdKnowledgeModule.PeriodoUpsert(oCurrentPeriodList.FirstOrDefault().RelatedPeriodModel.FirstOrDefault());
                        }

                        return(new Tuple <bool, string>(true, oCurrentPeriodList.FirstOrDefault().RelatedPeriodModel.FirstOrDefault().TotalQueries.ToString()));
                    }
                    else
                    {
                        return(new Tuple <bool, string>(false, oCurrentPeriodList.FirstOrDefault().RelatedPeriodModel.FirstOrDefault().TotalQueries.ToString()));
                    }
                }
            }
            return(new Tuple <bool, string>(true, oCurrentPeriodList.FirstOrDefault().RelatedPeriodModel.FirstOrDefault().TotalQueries.ToString()));;
        }
Esempio n. 3
0
        public JsonResult AddRolesToGroup(int groupId, string roles)
        {
            var userSrv      = IoC.Resolve <IuserService>();
            var groupSrv     = IoC.Resolve <INHOM_USERService>();
            var userGroupSrv = IoC.Resolve <IUSER_GROUPService>();
            var roleSrv      = IoC.Resolve <IroleService>();

            try
            {
                var lstRolesId = new JavaScriptSerializer().Deserialize <List <int> >(roles);

                var userIdOfGroup = userGroupSrv.GetUserIdByGroupId(groupId).Select(n => n.USER_ID).ToList();
                userSrv.BeginTran();
                // thanhpt sửa save quyền truy cập
                userSrv.Clear();
                foreach (var userid in userIdOfGroup)
                {
                    var user = userSrv.Getbykey(userid);
                    user.Roles = roleSrv.Query.Where(n => lstRolesId.Contains(n.roleid)).ToList();
                    userSrv.Save(user);
                }
                userSrv.CommitTran();
                return(Json(new
                {
                    status = true,
                    mess = "Cập nhật thành công."
                }));
            }
            catch (Exception e)
            {
                userSrv.RolbackTran();
                TryLog(log, e);
                return(Json(new
                {
                    status = false,
                    mess = "Cập nhật thất bại, vui lòng thử lại sau."
                }));
            }
        }
Esempio n. 4
0
        public HttpResponseMessage GetByMultiId(HttpRequestMessage request, string jsonlistId)
        {
            HttpResponseMessage response = null;

            if (!ModelState.IsValid)
            {
                response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
            }
            else
            {
                List <Article> list = new List <Article>();

                if (jsonlistId.Length != 2)
                {
                    var listLicense = new JavaScriptSerializer().Deserialize <List <int> >(jsonlistId);
                    list = ctr.LoadListObject <Article>().Where(x => listLicense.Contains(x.ID)).ToList();
                }

                response = request.CreateResponse(HttpStatusCode.OK, list);
            }
            return(response);
        }
Esempio n. 5
0
        public override void ExecuteCommand()
        {
            int lastNhour = 24;
            List <WorkInstanceDetail>     jobDetail       = new List <WorkInstanceDetail>();
            List <WorkJobInstanceDetails> instanceDetails = getWorkjobInstance();

            foreach (WorkJobInstanceDetails job in instanceDetails)
            {
                int    invocationCount = 0;
                double totalRunTime    = 0;
                int    faultCount      = 0;
                int    faultRate       = 0;
                int    runtime         = 0;
                Dictionary <string, List <string> > ErrorList = new Dictionary <string, List <string> >();
                string AdminKey = WorkServiceAdminKey;

                if (job.url.Contains("api-work-1"))
                {
                    AdminKey = WorkServiceFailoverAdminKey;
                }
                NetworkCredential nc = new NetworkCredential(WorkServiceUserName, AdminKey);
                //get all invocations in last 24 hours or last 10 invocations
                int no = (lastNhour * 60) / job.FrequencyInMinutes;
                if (no < 10)
                {
                    no = 10;
                }
                WebRequest request = WebRequest.Create(string.Format("{0}/instances/{1}?limit={2}", job.url, job.JobInstanceName, no));
                request.Credentials     = nc;
                request.PreAuthenticate = true;
                request.Method          = "GET";
                WebResponse respose = request.GetResponse();
                using (var reader = new StreamReader(respose.GetResponseStream()))
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    js.MaxJsonLength = Int32.MaxValue;
                    var objects = js.Deserialize <List <WorkJobInvocation> >(reader.ReadToEnd());
                    WorkJobInvocation lastJob;
                    bool   alert         = false;
                    string lastCompleted = string.Empty;
                    if (objects.Any((item => item.status.Equals("Executed") && item.result.Equals("Completed"))))
                    {
                        lastJob = objects.Where(item => item.status.Equals("Executed") && item.result.Equals("Completed")).ToList().FirstOrDefault();
                    }
                    else
                    {
                        lastJob = objects.FirstOrDefault();
                    }

                    if (lastJob != null)
                    {
                        lastCompleted = string.Format("{0} mins ago", Convert.ToInt32(DateTime.Now.Subtract(lastJob.completedAt).TotalMinutes));
                    }
                    else
                    {
                        lastCompleted = "N/A";
                    }

                    foreach (WorkJobInvocation each in objects)
                    {
                        if (each.result.Equals("Incomplete", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        if (each.completedAt >= DateTime.Now.AddHours(-1))
                        {
                            alert = true;                                                // check there is any failure happened in last one hour
                        }
                        invocationCount++;
                        totalRunTime += each.completedAt.Subtract(each.queuedAt).TotalSeconds;
                        if (each.result.Equals("Faulted"))
                        {
                            faultCount++;
                            string message = getResultMessage(each.resultMessage);
                            if (ErrorList.ContainsKey(message))
                            {
                                if (ErrorList[message].Count < 5)
                                {
                                    ErrorList[message].Add(each.logUrl);
                                }
                            }

                            else
                            {
                                List <string> LogUrl = new List <string>();
                                LogUrl.Add(each.logUrl);
                                ErrorList.Add(message, LogUrl);
                            }
                        }
                    }
                    if (invocationCount != 0)
                    {
                        faultRate = (faultCount * 100 / invocationCount);
                        runtime   = ((int)(totalRunTime / invocationCount));
                    }
                    jobDetail.Add(new WorkInstanceDetail(job.JobInstanceName, job.FrequencyInMinutes + "mins", lastCompleted, runtime.ToString() + "s", invocationCount.ToString(), faultCount.ToString(), faultRate, ErrorList));
                    AlertThresholds thresholdValues = new JavaScriptSerializer().Deserialize <AlertThresholds>(ReportHelpers.Load(StorageAccount, "Configuration.AlertThresholds.json", ContainerName));
                    string[]        Igonored        = new JavaScriptSerializer().Deserialize <string[]>(ReportHelpers.Load(StorageAccount, "Configuration.WorkerJobToBeIgnored.json", ContainerName));
                    if (Igonored.Contains(job.JobInstanceName, StringComparer.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    if (faultRate > thresholdValues.WorkJobErrorThreshold && alert)
                    {
                        new SendAlertMailTask
                        {
                            AlertSubject = string.Format("Error: Alert for Nuget Work Service : {0} failure", job.JobInstanceName),
                            Details      = string.Format("Rate of failure exceeded Error threshold for {0}. Threshold count : {1}%, failure in last 24 hour : {2}", job.JobInstanceName, thresholdValues.WorkJobErrorThreshold, faultCount),
                            AlertName    = string.Format("Error: Nuget Work Service {0}", job.JobInstanceName),
                            Component    = "Nuget Work Service",
                            Level        = "Error"
                        }.ExecuteCommand();
                    }
                    else if (faultRate > thresholdValues.WorkJobWarningThreshold && alert)
                    {
                        new SendAlertMailTask
                        {
                            AlertSubject = string.Format("Warning: Alert for Nuget Work Service: {0} failure", job.JobInstanceName),
                            Details      = string.Format("Rate of failure exceeded Warning threshold for {0}. Threshold count : {1}%, failure in last 24 hour : {2}", job.JobInstanceName, thresholdValues.WorkJobWarningThreshold, faultCount),
                            AlertName    = string.Format("Warning: Nuget Work Service {0}", job.JobInstanceName),
                            Component    = "Nuget Work Service",
                            Level        = "Warning"
                        }.ExecuteCommand();
                    }
                }
                //check to make sure that the jobs that are not queued as part of scheduler are being invoked properly
                if (invocationCount < ((lastNhour * 60 / job.FrequencyInMinutes) / 2))
                {
                    new SendAlertMailTask
                    {
                        AlertSubject = string.Format("Error: Alert for Nuget Work Service : {0} failure", job.JobInstanceName),
                        Details      = string.Format("In last 24 hours, invocation of {0} is only {1}, it's less than half of scheduled jobs", job.JobInstanceName, invocationCount),
                        AlertName    = string.Format("Error: Nuget Work Service {0}", job.JobInstanceName),
                        Component    = "Nuget Work Service",
                        Level        = "Error"
                    }.ExecuteCommand();
                }
            }

            List <WorkServiceAdmin> allkey = new List <WorkServiceAdmin>();

            allkey.Add(new WorkServiceAdmin(WorkServiceUserName, WorkServiceAdminKey));
            allkey.Add(new WorkServiceAdmin(WorkServiceUserName, WorkServiceFailoverAdminKey));
            var json = new JavaScriptSerializer().Serialize(jobDetail);
            var key  = new JavaScriptSerializer().Serialize(allkey);

            ReportHelpers.CreateBlob(StorageAccount, "WorkJobDetail.json", ContainerName, "application/json", ReportHelpers.ToStream(json));
            ReportHelpers.CreateBlob(StorageAccount, "WorkServiceAdminKey.json", ContainerName, "application/json", ReportHelpers.ToStream(key));
        }
Esempio n. 6
0
        public async Task <AjaxResult> SearchItemData([FromUri] PageResult page)
        {
            var GroupByItme = BLLSession.IHard_GroupByItmeBLL.Query(u => true);
            var data        = from a in BLLSession.IHard_GroupByProLineBLL.Query(u => true)
                              join dict in BLLSession.IHard_BaseDictBLL.Query(u => true)
                              on a.ProLineNo equals dict.DictNo
                              join b in BLLSession.IHard_MaterialItemBLL.Query(u => u.IsStop == 0)
                              on a.GroupNo equals b.SubItemNo
                              join c in BLLSession.IHard_MaterialTypeBLL.Query(u => true)
                              on b.MatTypeNo equals c.MatTypeNo
                              where !GroupByItme.Any(i => i.ItemNo == b.ItemNo)
                              orderby b.ItemNo
                              select new
            {
                b.SerialNo,
                TypeNo = c.SerialNo,
                dict.DictName,
                b.ItemNo,
                b.MatTypeNo,
                b.SubItemNo,
                c.MatTypeName,
                SubType = a.GroupType,
                b.Brand,
                b.ItemModel,
                b.ConfigDesc,
                b.AttachFiles,
                b.WarrantyPeriod,
                b.warrantyType,
                b.WarrantyCost,
                b.PurchasePrice,
                b.Offer,
                b.IsStop,
                b.IsEnergy,
                b.LastTime,
                b.DeliveryDay,
                b.CreateTime,
            };

            if (!string.IsNullOrEmpty(page.QueryKey))
            {
                string[] list = new JavaScriptSerializer().Deserialize <string[]>(page.QueryKey);
                if (list.Length > 0)
                {
                    var LineData = data.Where(u => list.Contains(u.DictName));
                    var cont     = LineData.GroupBy(u => new { u.DictName }).Select(u => new { DictName = u.Key.DictName });

                    if (LineData.Count() > 0)
                    {
                        if (list.Length == cont.Count())
                        {
                            data = LineData.Where(u => list.Contains(u.DictName));
                        }
                        else if (list.Length > cont.Count())
                        {
                            data = LineData.Where(u => list.Contains(u.DictName) && (list.Contains(u.MatTypeName) || list.Contains(u.SubType) || list.Contains(u.Brand) || list.Contains(u.ItemModel)));
                        }
                    }
                    else
                    {
                        data = data.Where(u => list.Contains(u.MatTypeName) || list.Contains(u.SubType) || list.Contains(u.Brand) || list.Contains(u.ItemModel));
                    }
                }
            }

            //查询条件
            //data = supplyList.WhereIf(!string.IsNullOrEmpty(page.QueryKey), u => u.PoNo.Contains(page.QueryKey)); new LinqPage(page.PageIndex, page.PageSize, page.Order, page.Sort)
            return(AjaxResult.ToJSON(new { total = data.Count(), rows = await data.PageResult(GetLinqPage(page.PageIndex, page.PageSize, "CreateTime", "desc")).ToListAsync <dynamic>() }));
        }