Exemplo n.º 1
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ActionResult> Query(PlanDayQueryViewModel model)
        {
            MethodReturnResult result = new MethodReturnResult();

            try
            {
                using (PlanDayServiceClient client = new PlanDayServiceClient())
                {
                    //取得数据
                    await Task.Run(() =>
                    {
                        //取数条件
                        StringBuilder where = new StringBuilder();
                        if (model != null)
                        {
                            //年度条件
                            if (!string.IsNullOrEmpty(model.qYear))
                            {
                                where.AppendFormat(" {0} Key.Year = '{1}'"
                                                   , where.Length > 0 ? "AND" : string.Empty
                                                   , model.qYear);
                            }

                            //月度条件
                            if (!string.IsNullOrEmpty(model.qMonth))
                            {
                                where.AppendFormat(" {0} Key.Month = '{1}'"
                                                   , where.Length > 0 ? "and" : string.Empty
                                                   , model.qMonth);
                            }

                            //车间条件
                            if (!string.IsNullOrEmpty(model.LocationName))
                            {
                                where.AppendFormat(" {0} Key.LocationName = '{1}'"
                                                   , where.Length > 0 ? "AND" : string.Empty
                                                   , model.LocationName);
                            }

                            //产品条件
                            if (!string.IsNullOrEmpty(model.ProductCode))
                            {
                                where.AppendFormat(" {0} Key.ProductCode = '{1}'"
                                                   , where.Length > 0 ? "AND" : string.Empty
                                                   , model.ProductCode);
                            }
                        }

                        //设置参数
                        PagingConfig cfg = new PagingConfig()
                        {
                            OrderBy = "Key",
                            Where   = where.ToString()
                        };

                        //取得数据
                        MethodReturnResult <IList <PlanDay> > resultlist = client.Get(ref cfg);

                        if (resultlist.Code == 0)
                        {
                            ViewBag.PagingConfig = cfg;
                            ViewBag.List         = resultlist.Data;
                        }
                        else
                        {
                            //数据错误
                            result.Code    = resultlist.Code;       //错误代码
                            result.Message = resultlist.Message;    //错误信息
                            result.Detail  = resultlist.Message;    //错误明细
                        }
                    });

                    //处理错误信息
                    if (result.Code > 0)
                    {
                        return(Json(result));                        //终止并返回程序
                    }
                }

                return(PartialView("_ListPartial"));
            }
            catch (Exception e)
            {
                result.Code    = 1002;
                result.Message = e.Message;
                result.Detail  = e.ToString();

                return(Json(result));
            }
        }
Exemplo n.º 2
0
        // GET: /PPM/PlanDay/
        /// <summary>
        /// 页面开始处理事物
        /// </summary>
        /// <param name="year">         年</param>
        /// <param name="month">        月</param>
        /// <param name="locationname"> 车间</param>
        /// <returns></returns>
        public async Task <ActionResult> Index(string year, string month, string locationname)
        {
            MethodReturnResult result = new MethodReturnResult();

            try
            {
                //初始化参数
                string sYear  = System.DateTime.Now.ToString("yyyy");
                string sMonth = System.DateTime.Now.ToString("MM");

                //获取日生产计划。
                using (PlanDayServiceClient client = new PlanDayServiceClient())
                {
                    await Task.Run(() =>
                    {
                        //设置查询条件
                        PagingConfig cfg = new PagingConfig()
                        {
                            IsPaging = false,
                            Where    = string.Format(@" Key.Year = '{0}' 
                                                    AND Key.Month = '{1}'",
                                                     sYear,
                                                     sMonth
                                                     )
                        };

                        //取得列表数据
                        MethodReturnResult <IList <PlanDay> > resultlist = client.Get(ref cfg);

                        if (resultlist.Code == 0)
                        {
                            ViewBag.PagingConfig = cfg;
                            ViewBag.List         = resultlist.Data;
                        }
                        else
                        {
                            //数据错误
                            result.Code    = resultlist.Code;       //错误代码
                            result.Message = resultlist.Message;    //错误信息
                            result.Detail  = resultlist.Message;    //错误明细
                        }
                    });

                    //处理错误信息
                    if (result.Code > 0)
                    {
                        return(Json(result));            //终止并返回程序
                    }
                }

                PlanDayQueryViewModel model = new PlanDayQueryViewModel
                {
                    //初始化参数
                    qYear  = sYear,                       //年
                    qMonth = sMonth,                      //月
                };

                return(View(model));
            }
            catch (Exception ex)
            {
                result.Code    = 1000;
                result.Message = ex.Message;
                result.Detail  = ex.ToString();

                return(Json(result));
            }
        }