public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string detailStr = context.Request.Form["Details"];
            if (string.IsNullOrEmpty(detailStr))
            {
                context.Response.Write("分配信息不能为空");
                context.Response.End();
            }

            string allotDesc = context.Request.Form["AllotDesc"];

            int stockLogId = 0;
            if (string.IsNullOrEmpty(context.Request.Form["StockLogId"]) || !int.TryParse(context.Request.Form["StockLogId"], out stockLogId) || stockLogId <= 0)
            {
                context.Response.Write("库存信息错误");
                context.Response.End();
            }

            NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser;
            NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();

            try
            {
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                List<NFMT.Funds.Model.CashInContractDirect> directs = serializer.Deserialize<List<NFMT.Funds.Model.CashInContractDirect>>(detailStr);
                if (directs == null)
                {
                    context.Response.Write("分配信息错误");
                    context.Response.End();
                }

                List<NFMT.Funds.Model.CashInCorp> corps = new List<NFMT.Funds.Model.CashInCorp>();
                foreach (NFMT.Funds.Model.CashInContractDirect direct in directs)
                {
                    NFMT.Funds.Model.CashInCorp corp = new NFMT.Funds.Model.CashInCorp();
                    corp.AllotBala = direct.AllotBala;
                    corp.CorpId = direct.AllotCorpId;
                    corp.IsShare = false;
                    corp.CashInId = direct.CashInId;

                    corps.Add(corp);
                }

                NFMT.Funds.Model.CashInAllot allot = new NFMT.Funds.Model.CashInAllot();
                allot.AllotDesc = allotDesc;
                allot.AllotStatus = NFMT.Common.StatusEnum.已录入;

                NFMT.Funds.BLL.CashInStcokBLL bll = new NFMT.Funds.BLL.CashInStcokBLL();
                result = bll.CreateDirectStock(user, allot, corps, stockLogId);
            }
            catch (Exception e)
            {
                result.Message = e.Message;
            }

            if (result.ResultStatus == 0)
                result.Message = "分配成功";

            context.Response.Write(result.Message);
            context.Response.End();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string redirectUrl = "CashInAllotMainList.aspx";

            if (!IsPostBack)
            {
                NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser;
                NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();

                Utility.VerificationUtility ver = new Utility.VerificationUtility();
                ver.JudgeOperate(this.Page, 122, new List<NFMT.Common.OperateEnum>() { NFMT.Common.OperateEnum.提交审核, NFMT.Common.OperateEnum.作废, NFMT.Common.OperateEnum.撤返, NFMT.Common.OperateEnum.执行完成, NFMT.Common.OperateEnum.执行完成撤销 });

                this.navigation1.Routes.Add("收款分配", redirectUrl);
                this.navigation1.Routes.Add("收款分配明细", string.Empty);

                int allotId = 0;
                if (string.IsNullOrEmpty(Request.QueryString["id"]) || !int.TryParse(Request.QueryString["id"], out allotId) || allotId <= 0)
                    this.WarmAlert("序号错误", redirectUrl);

                //获取收款分配
                NFMT.Funds.BLL.CashInAllotBLL cashInAllotBLL = new NFMT.Funds.BLL.CashInAllotBLL();
                result = cashInAllotBLL.Get(user, allotId);
                if (result.ResultStatus != 0)
                    this.WarmAlert(result.Message, redirectUrl);

                cashInAllot = result.ReturnValue as NFMT.Funds.Model.CashInAllot;
                if (cashInAllot == null)
                    this.WarmAlert("获取收款分配失败", redirectUrl);

                NFMT.Common.StatusEnum status = NFMT.Common.StatusEnum.已生效;
                if (cashInAllot.AllotStatus == NFMT.Common.StatusEnum.已完成)
                    status = NFMT.Common.StatusEnum.已完成;
                else if(cashInAllot.AllotStatus == NFMT.Common.StatusEnum.已作废)
                    status = NFMT.Common.StatusEnum.已作废;
                else if (cashInAllot.AllotStatus == NFMT.Common.StatusEnum.已关闭)
                    status = NFMT.Common.StatusEnum.已关闭;

                //获取收款分配至公司
                NFMT.Funds.BLL.CashInCorpBLL cashInCorpBLL = new NFMT.Funds.BLL.CashInCorpBLL();
                result = cashInCorpBLL.Load(user, allotId, status);
                if (result.ResultStatus != 0)
                    this.WarmAlert(result.Message, redirectUrl);

                List<NFMT.Funds.Model.CashInCorp> cashInCorps = result.ReturnValue as List<NFMT.Funds.Model.CashInCorp>;
                if (cashInCorps == null || !cashInCorps.Any())
                    this.WarmAlert("获取收款分配至公司失败", redirectUrl);

                cashInCorp = cashInCorps.FirstOrDefault();

                //获取收款分配至合约
                NFMT.Funds.BLL.CashInContractBLL cashInContractBLL = new NFMT.Funds.BLL.CashInContractBLL();
                result = cashInContractBLL.GetByAllot(user, allotId, status);
                if (result.ResultStatus != 0)
                    this.WarmAlert(result.Message, redirectUrl);

                cashInContract = result.ReturnValue as NFMT.Funds.Model.CashInContract;
                if (cashInContract == null)
                    this.WarmAlert("获取收款分配至合约失败", redirectUrl);

                //获取收款分配至库存
                NFMT.Funds.BLL.CashInStcokBLL cashInStockBLL = new NFMT.Funds.BLL.CashInStcokBLL();
                result = cashInStockBLL.LoadByAllot(user, allotId, status);
                if (result.ResultStatus != 0)
                    this.WarmAlert(result.Message, redirectUrl);

                cashInStocks = result.ReturnValue as List<NFMT.Funds.Model.CashInStcok>;
                if (cashInStocks == null || !cashInStocks.Any())
                    this.WarmAlert("获取收款分配至库存失败", redirectUrl);

                //获取合约列表
                NFMT.Contract.BLL.ContractSubBLL contractSubBLL = new NFMT.Contract.BLL.ContractSubBLL();
                NFMT.Common.SelectModel select = contractSubBLL.GetListSelect(1, 200, string.Empty, cashInContract.SubContractId);
                result = contractSubBLL.Load(user, select);
                if (result.ResultStatus != 0)
                    this.WarmAlert(result.Message, redirectUrl);

                int totalRows = result.AffectCount;
                System.Data.DataTable dt = result.ReturnValue as System.Data.DataTable;

                this.contractGirdInfo = Newtonsoft.Json.JsonConvert.SerializeObject(dt, new Newtonsoft.Json.Converters.DataTableConverter());

                //获取库存列表
                result = cashInStockBLL.GetStockInfoByAlotId(user, allotId, status);
                if (result.ResultStatus != 0)
                    this.WarmAlert(result.Message, redirectUrl);

                totalRows = result.AffectCount;
                dt = result.ReturnValue as System.Data.DataTable;

                this.stockGridInfo = Newtonsoft.Json.JsonConvert.SerializeObject(dt, new Newtonsoft.Json.Converters.DataTableConverter());

                //获取收款登记信息
                NFMT.Funds.BLL.CashInBLL cashInBLL = new NFMT.Funds.BLL.CashInBLL();
                result = cashInBLL.Get(user, cashInCorp.CashInId);
                if (result.ResultStatus != 0)
                    this.WarmAlert(result.Message, redirectUrl);

                cashIn = result.ReturnValue as NFMT.Funds.Model.CashIn;
                if (cashIn == null)
                    this.WarmAlert("获取收款登记失败", redirectUrl);

                //初始化
                InitCashInInfo(cashIn, redirectUrl);

                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                string json = serializer.Serialize(cashInAllot);
                this.hidModel.Value = json;

                NFMT.Funds.BLL.CashInInvoiceBLL cashInInvoiceBLL = new NFMT.Funds.BLL.CashInInvoiceBLL();
                result = cashInInvoiceBLL.GetSIIdsbyAllotId(user, allotId);
                if (result.ResultStatus != 0)
                    this.WarmAlert(result.Message, redirectUrl);

                upSIIds = result.ReturnValue != null ? result.ReturnValue.ToString() : string.Empty;
            }
        }