Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Utility.VerificationUtility ver = new Utility.VerificationUtility();
                ver.JudgeOperate(this.Page, 37, new List<NFMT.Common.OperateEnum>() { NFMT.Common.OperateEnum.查询 });

                NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser;
                NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();
                string redirectUrl = string.Format("{0}Contract/ContractList.aspx", NFMT.Common.DefaultValue.NftmSiteName);

                //this.navigation1.Routes.Add("合约列表", redirectUrl);
                //this.navigation1.Routes.Add("合约预览", string.Empty);

                int contractId = 0;
                if (string.IsNullOrEmpty(Request.QueryString["id"]) || !int.TryParse(Request.QueryString["id"], out contractId) || contractId <= 0)
                    Utility.JsUtility.WarmAlert(this.Page, "参数错误", redirectUrl);

                //获取合约
                NFMT.Contract.BLL.ContractBLL contractBLL = new NFMT.Contract.BLL.ContractBLL();
                result = contractBLL.Get(user, contractId);
                if (result.ResultStatus != 0)
                    Utility.JsUtility.WarmAlert(this.Page, result.Message, redirectUrl);

                contract = result.ReturnValue as NFMT.Contract.Model.Contract;
                if (contract == null)
                    Utility.JsUtility.WarmAlert(this.Page, "获取合约失败", redirectUrl);

                //获取品种
                asset = NFMT.Data.BasicDataProvider.Assets.SingleOrDefault(a => a.AssetId == contract.AssetId);
                if (asset == null)
                    Utility.JsUtility.WarmAlert(this.Page, "获取品种失败", redirectUrl);

                NFMT.Contract.BLL.ContractCorporationDetailBLL contractCorporationDetailBLL = new NFMT.Contract.BLL.ContractCorporationDetailBLL();

                //采购销售
                if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.采购)
                {
                    tradeDirection = "采购";
                    isSelf = true;
                }
                else if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.销售)
                {
                    tradeDirection = "销售";
                    isSelf = false;
                }

                //买方抬头
                result = contractCorporationDetailBLL.LoadByContractId(user, contractId, isSelf);
                if (result.ResultStatus != 0)
                    Utility.JsUtility.WarmAlert(this.Page, result.Message, redirectUrl);

                buyCorporationDetails = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                if (buyCorporationDetails == null || !buyCorporationDetails.Any())
                    Utility.JsUtility.WarmAlert(this.Page, "获取买方抬头失败", redirectUrl);

                List<string> corpNames = new List<string>();
                buyCorporationDetails.ForEach(detail =>
                {
                    corp = NFMT.User.UserProvider.Corporations.SingleOrDefault(a => a.CorpId == detail.CorpId);
                    if (!corpNames.Contains(corp.CorpName))
                        corpNames.Add(corp.CorpName);
                });

                buyCorpName = string.Join(",", corpNames);

                if (string.IsNullOrEmpty(buyCorpName))
                    Utility.JsUtility.WarmAlert(this.Page, "获取买方抬头失败", redirectUrl);

                //卖方抬头
                result = contractCorporationDetailBLL.LoadByContractId(user, contractId, !isSelf);
                if (result.ResultStatus != 0)
                    Utility.JsUtility.WarmAlert(this.Page, result.Message, redirectUrl);

                sellCorporationDetails = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                if (sellCorporationDetails == null || !sellCorporationDetails.Any())
                    Utility.JsUtility.WarmAlert(this.Page, "获取卖方抬头失败", redirectUrl);

                corpNames.Clear();
                sellCorporationDetails.ForEach(detail =>
                {
                    corp = NFMT.User.UserProvider.Corporations.SingleOrDefault(a => a.CorpId == detail.CorpId);
                    if (!corpNames.Contains(corp.CorpName))
                        corpNames.Add(corp.CorpName);
                });

                sellCorpName = string.Join(",", corpNames);

                if (string.IsNullOrEmpty(sellCorpName))
                    Utility.JsUtility.WarmAlert(this.Page, "获取卖方抬头失败", redirectUrl);

                //列表明细
                result = contractBLL.GetContractDetail(user, contractId, (NFMT.Contract.TradeDirectionEnum)contract.TradeDirection);
                //if (result.ResultStatus != 0)
                //    Utility.JsUtility.WarmAlert(this.Page, result.Message, redirectUrl);

                dt = result.ReturnValue as System.Data.DataTable;
                //if (dt == null || dt.Rows.Count < 1)
                //    Utility.JsUtility.WarmAlert(this.Page, "获取合约明细失败", redirectUrl);

                contractDetailStr = GetGridDetail(dt, contract);

                //合约条款
                NFMT.Contract.BLL.ContractClauseBLL contractClauseBLL = new NFMT.Contract.BLL.ContractClauseBLL();
                result = contractClauseBLL.LoadClauseByContractId(user, contractId);
                if (result.ResultStatus != 0)
                    Utility.JsUtility.WarmAlert(this.Page, result.Message, redirectUrl);

                List<NFMT.Data.Model.ContractClause> contractClauses = result.ReturnValue as List<NFMT.Data.Model.ContractClause>;
                if (contractClauses == null || !contractClauses.Any())
                    Utility.JsUtility.WarmAlert(this.Page, "获取合约条款失败", redirectUrl);

                contractClausesStr = GetMasterClause(contractClauses);
            }
        }