public ActionResult _Insert(SwitchTrading SwitchTrading)
 {
     if (CheckSwitchTrading(SwitchTrading))
     {
         this.genericMgr.Create(SwitchTrading);
         SaveSuccessMessage(Resources.EXT.ControllerLan.Con_AddedSuccessfully);
     }
     GridCommand command = (GridCommand)TempData["GridCommand"];
     SwitchTradingSearchModel searchModel = (SwitchTradingSearchModel)TempData["searchModel"];
     TempData["GridCommand"] = command;
     TempData["searchModel"] = searchModel;
     SearchStatementModel searchStatementModel = PrepareSearchStatement(command, searchModel);
     GridModel<SwitchTrading> gridModel = GetAjaxPageData<SwitchTrading>(searchStatementModel, command);
     return PartialView(gridModel);
 }
 public ActionResult _Update(SwitchTrading switchTrading, string id)
 {
     if (CheckSwitchTrading(switchTrading))
     {
         SwitchTrading upSwitchTrading = base.genericMgr.FindById<SwitchTrading>(Convert.ToInt32(id));
         upSwitchTrading.Flow = switchTrading.Flow;
         upSwitchTrading.Supplier = switchTrading.Supplier;
         upSwitchTrading.Customer = switchTrading.Customer;
         upSwitchTrading.PurchaseGroup = switchTrading.PurchaseGroup;
         upSwitchTrading.SalesOrg = switchTrading.SalesOrg;
         upSwitchTrading.DistrChan = switchTrading.DistrChan;
         upSwitchTrading.PriceList = switchTrading.PriceList;
         upSwitchTrading.DIVISION = switchTrading.DIVISION;
         this.genericMgr.Update(upSwitchTrading);
         SaveSuccessMessage(Resources.EXT.ControllerLan.Con_ModificateSuccessfully);
     }
     GridCommand command = (GridCommand)TempData["GridCommand"];
     SwitchTradingSearchModel searchModel = (SwitchTradingSearchModel)TempData["searchModel"];
     TempData["GridCommand"] = command;
     TempData["searchModel"] = searchModel;
     SearchStatementModel searchStatementModel = PrepareSearchStatement(command, searchModel);
     GridModel<SwitchTrading> gridModel = GetAjaxPageData<SwitchTrading>(searchStatementModel, command);
     return PartialView(gridModel);
 }
        private bool CheckSwitchTrading(SwitchTrading switchTrading)
        {
            bool hasError = false;
            FlowMaster flowMaster =new FlowMaster();
            if (string.IsNullOrWhiteSpace(switchTrading.SalesOrg))
            {
                hasError = true;
                SaveErrorMessage(Resources.EXT.ControllerLan.Con_SaleOrgCanNotBeEmpty);
            }
            if (string.IsNullOrWhiteSpace(switchTrading.DistrChan))
            {
                hasError = true;
                SaveErrorMessage(Resources.EXT.ControllerLan.Con_DistrChanCanNotBeEmpty);
            }
            if (string.IsNullOrWhiteSpace(switchTrading.Flow))
            {
                hasError = true;
                SaveErrorMessage(Resources.EXT.ControllerLan.Con_FlowCodeCanNotBeEmpty);
            }
            else
            {
                try
                {
                    flowMaster = this.genericMgr.FindById<FlowMaster>(switchTrading.Flow);
                }
                catch (Exception e)
                {
                    hasError = true;
                    SaveErrorMessage(Resources.EXT.ControllerLan.Con_FlowCodeIsWrong);
                }

            }
            if (string.IsNullOrWhiteSpace(switchTrading.Supplier))
            {
                //hasError = true;
                //SaveErrorMessage("供应商不能为空。");
            }
            else
            {
                try
                {
                    var supplier = this.genericMgr.FindById<Supplier>(switchTrading.Supplier);
                }
                catch (Exception e)
                {
                    hasError = true;
                    SaveErrorMessage(Resources.EXT.ControllerLan.Con_SupplierIsWrong);
                }

            }
            if (!string.IsNullOrWhiteSpace(switchTrading.Customer))
            {
                try
                {
                    var supplier = this.genericMgr.FindById<Customer>(switchTrading.Customer);
                }
                catch (Exception e)
                {
                    hasError = true;
                    SaveErrorMessage(Resources.EXT.ControllerLan.Con_CustomerIsWrong);
                }
            }
            //if (string.IsNullOrWhiteSpace(switchTrading.PurchaseGroup))
            //{
            //    hasError = true;
            //    SaveErrorMessage("采购组不能为空。");
            //}
            if (this.genericMgr.FindAllWithNativeSql<int>(" select isnull(count(*),0) as counts from MD_SwitchTrading where Flow=?  and Id <>? ", new object[] { switchTrading.Flow, switchTrading.Id }, new IType[] { NHibernate.NHibernateUtil.String,NHibernate.NHibernateUtil.Int32 })[0] > 0)
            {
                hasError = true;
                SaveErrorMessage(string.Format(Resources.EXT.ControllerLan.Con_FlowAlreadyMaitained, switchTrading.Flow));
            }
            return !hasError;
        }