public JsonResult OrderNow(KanbanOrderSearchModel searchModel)
        {
            ViewBag.SearchModel = searchModel;
            try
            {
                if (searchModel.OrderTime == null)
                {
                    SaveWarningMessage("窗口时间不能为空");
                }
                else
                {
                    OrderHolder.CleanOrders();
                    this.kanbanScanOrderMgr.OrderCard(searchModel.ChosenScans, searchModel.OrderTime.Value);
                    IList<string> orderNoList = OrderHolder.GetOrders();
                    string orderNos = string.Empty;
                    if (orderNoList != null && orderNoList.Count > 0)
                    {
                        foreach (var orderNo in orderNoList)
                        {
                            orderNos += orderNo + ",";
                        }
                    }
                    SaveSuccessMessage("收料单创建成功,单号{0}", orderNos.Substring(0, orderNos.Length - 1));


                    return Json(null);
                }
            }
            catch (Exception ex)
            {
                SaveErrorMessage(ex.Message);
            }
            return Json(null);
        }
        public JsonResult MultiOrderNow(KanbanOrderSearchModel searchModel, string flowStr, string windowTimeStr)
        {
            ViewBag.SearchModel = searchModel;
            try
            {
                if (string.IsNullOrEmpty(flowStr))
                {
                    SaveErrorMessage("明细不能为空");
                }
                else
                {
                    OrderHolder.CleanOrders();
                    string[] flowArray = flowStr.Split(',');
                    string[] windowStrTimeArray = windowTimeStr.Split(',');

                    if (searchModel.OrderTime != null)
                    {

                        #region 调整时间的
                        IList<SupplierRegion> supplierRegionList = new List<SupplierRegion>();
                        string sql = "Select distinct Region, RegionName, Supplier, SupplierName,Flow from KB_KanbanScan s where s.IsOrdered = 0 ";
                        //取用户有权限的所有区域
                        User user = SecurityContextHolder.Get();
                        if (user.Code.Trim().ToLower() != "su")
                        {
                            sql += " and exists (select 1 from VIEW_UserPermission as up where up.UserId =" + user.Id + " and  up.CategoryType = " + (int)com.Sconit.CodeMaster.PermissionCategoryType.Region + "  and up.PermissionCode = s.Region)";
                        }
                        if (!string.IsNullOrEmpty(searchModel.Supplier))
                        {
                            sql += " and s.Supplier = '" + searchModel.Supplier + "'";
                        }

                        IList<object[]> resultList = genericMgr.FindAllWithNativeSql<object[]>(sql);
                        #endregion

                        var match = resultList.Where(p => (string)p[4] == (string)flowArray[0]).First();
                        IList<object[]> matchList = resultList.Where(p => (string)p[0] == (string)match[0]).ToList();
                        List<string> totalFlowList = new List<string>();
                        List<DateTime> totalWindowTimeList = new List<DateTime>();
                        for (int i = 0; i < matchList.Count; i++)
                        {
                            totalFlowList.Add((string)matchList[i][4]);
                            totalWindowTimeList.Add(searchModel.OrderTime.Value);
                        }
                        this.kanbanScanMgr.OrderCard(totalFlowList.ToArray(), totalWindowTimeList.ToArray());

                        IList<string> orderNoList = OrderHolder.GetOrders();
                        string orderNos = string.Empty;
                        if (orderNoList != null && orderNoList.Count > 0)
                        {
                            foreach (var orderNo in orderNoList)
                            {
                                orderNos += orderNo + ",";
                            }
                        }

                        SaveSuccessMessage("收料单创建成功,收料单号{0}", orderNos.Substring(0, orderNos.Length - 1));

                        return Json(null);

                    }
                    else
                    {
                        DateTime[] windowTimeArray = Array.ConvertAll(windowStrTimeArray, windowTime => Convert.ToDateTime(windowTime));
                        this.kanbanScanMgr.OrderCard(flowArray, windowTimeArray);
                        IList<string> orderNoList = OrderHolder.GetOrders();

                        string orderNos = string.Empty;
                        if (orderNoList != null && orderNoList.Count > 0)
                        {
                            foreach (var orderNo in orderNoList)
                            {
                                orderNos += orderNo + ",";
                            }
                        }
                        SaveSuccessMessage("收料单创建成功,收料单号{0}", orderNos.Substring(0, orderNos.Length - 1));
                        return Json(null);
                    }

                }
            }
            catch (Exception ex)
            {
                SaveErrorMessage(ex.Message);
            }
            return Json(null);
        }
        public ActionResult _KanbanOrderSaveBatch([Bind(Prefix = "updated")]IEnumerable<KanbanScan> updates,
            KanbanOrderSearchModel searchModel)
        {
            if (updates != null)
            {
                foreach (KanbanScan scan in updates)
                {
                    this.genericMgr.Update(scan);
                }
            }

            GridCommand command = new GridCommand();
            SearchStatementModel searchStatementModel = this.KanbanScanPrepareSearchStatement(command, searchModel);
            return PartialView(GetAjaxPageData<KanbanScan>(searchStatementModel, command));
        }
        private SearchStatementModel KanbanScanPrepareSearchStatement(GridCommand command, KanbanOrderSearchModel searchModel)
        {
            string whereStatement = string.Empty;

            IList<object> param = new List<object>();

            if (whereStatement == string.Empty)
            {
                //whereStatement = " where IsOrdered = 0 and exists(select 1 from FlowStrategy as s where s.Flow = o.Flow and s.IsOrderNow=0)";
                //只要没结转过的都可以前台结转,不要再看自动结转选项,因为有时候可能会自动结转失败
                whereStatement = " where IsOrdered = 0 and exists(select 1 from FlowStrategy as s where s.Flow = o.Flow)";
            }

            SecurityHelper.AddRegionPermissionStatement(ref whereStatement, "o", "Region");

            // 按单个供应商结转,或者按照物流中心结转

            if (!string.IsNullOrEmpty(searchModel.Supplier))
            {

                HqlStatementHelper.AddEqStatement("Supplier", searchModel.Supplier, "o", ref whereStatement, param);
            }

            if (!string.IsNullOrEmpty(searchModel.Region))
            {
                HqlStatementHelper.AddEqStatement("Region", searchModel.Region, "o", ref whereStatement, param);
            }



            if (!string.IsNullOrEmpty(searchModel.Flow))
            {
                HqlStatementHelper.AddEqStatement("Flow", searchModel.Flow, "o", ref whereStatement, param);
            }
            string sortingStatement = HqlStatementHelper.GetSortingStatement(command.SortDescriptors);

            SearchStatementModel searchStatementModel = new SearchStatementModel();
            searchStatementModel.SelectCountStatement = selectCountStatementKanbanOrder;
            searchStatementModel.SelectStatement = selectStatementKanbanOrder;
            searchStatementModel.WhereStatement = whereStatement;
            searchStatementModel.SortingStatement = sortingStatement;
            searchStatementModel.Parameters = param.ToArray<object>();

            return searchStatementModel;
        }
 public ActionResult _KanbanOrderAjaxList(GridCommand command, KanbanOrderSearchModel searchModel)
 {
     GridModel<KanbanScan> kanbanScanGrid = new GridModel<KanbanScan>(new List<KanbanScan>());
     if (!string.IsNullOrEmpty(searchModel.Flow))
     {
         SearchStatementModel searchStatementModel = this.KanbanScanPrepareSearchStatement(command, searchModel);
         kanbanScanGrid = GetAjaxPageData<KanbanScan>(searchStatementModel, command);
     }
     return PartialView(kanbanScanGrid);
 }
        public ActionResult ListKanbanOrder(GridCommand command, KanbanOrderSearchModel searchModel)
        {
            SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
            ViewBag.SearchModel = searchModel;
            ViewBag.PageSize = base.ProcessPageSize(100);

            //if (string.IsNullOrEmpty(searchModel.Supplier))
            //{
            //    SaveWarningMessage("供应商不能都为空");
            //    return View();
            //}

            return View();
        }
        public ActionResult _OrderSupplierRegionAjaxList(GridCommand command, KanbanOrderSearchModel searchModel)
        {
            IList<SupplierRegion> supplierRegionList = new List<SupplierRegion>();
            if (!string.IsNullOrEmpty(searchModel.Supplier))
            {
                string sql = "Select distinct Region, RegionName, Supplier, SupplierName,Flow from KB_KanbanScan s where s.IsOrdered = 0 ";

                //取用户有权限的所有区域
                User user = SecurityContextHolder.Get();
                if (user.Code.Trim().ToLower() != "su")
                {
                    sql += " and exists (select 1 from VIEW_UserPermission as up where up.UserId =" + user.Id + " and  up.CategoryType = " + (int)com.Sconit.CodeMaster.PermissionCategoryType.Region + "  and up.PermissionCode = s.Region)";
                }

                if (!string.IsNullOrEmpty(searchModel.Supplier))
                {
                    sql += " and s.Supplier = '" + searchModel.Supplier + "'";
                }

                IList resultList = genericMgr.FindAllWithNativeSql(sql);
                DateTime nowDate = DateTime.Now;
                foreach (object[] result in resultList)
                {
                    SupplierRegion s = new SupplierRegion();
                    s.Region = result[0].ToString();
                    s.RegionName = result[1].ToString();
                    s.Supplier = result[2].ToString();
                    s.SupplierName = result[3].ToString();
                    s.Flow = result[4].ToString();
                    supplierRegionList.Add(s);

                    #region 算交货时间
                    FlowStrategy flowStrategy = genericMgr.FindById<FlowStrategy>(s.Flow);
                    try
                    {
                        s.WindowTime = genericMgr.FindAllWithNativeSql<DateTime>("USP_Busi_GetNextWindowTime ?,?,?", new Object[] { s.Flow, flowStrategy.PreWinTime, null }, new IType[] { NHibernateUtil.String, NHibernateUtil.DateTime, NHibernateUtil.DateTime }).FirstOrDefault();

                    }
                    catch (Exception ex)
                    {
                        if (ex.InnerException != null)
                        {
                            if (ex.InnerException.InnerException != null)
                            {
                                s.Memo = ex.InnerException.InnerException.Message;

                            }
                            else
                            {
                                s.Memo = ex.InnerException.Message;
                            }
                        }
                        else
                        {
                            s.Memo = ex.Message;
                        }
                    }
                    #endregion

                }
            }
            return PartialView(new GridModel<SupplierRegion> { Data = supplierRegionList });
        }
        public ActionResult ListSupplierRegion(GridCommand command, KanbanOrderSearchModel searchModel)
        {
            SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
            ViewBag.SearchModel = searchModel;
            ViewBag.PageSize = base.ProcessPageSize(command.PageSize);

            if (string.IsNullOrEmpty(searchModel.Supplier))
            {
                SaveWarningMessage("供应商不能都为空");
                return View("Order", searchModel);
            }

            return View();
        }
 public ActionResult Order(KanbanOrderSearchModel searchModel)
 {
     TempData["KanbanOrderSearchModel"] = searchModel;
     return View();
 }