/// <summary>
        /// 创建供应商合同 Pwp 2015-09-23
        /// </summary>
        /// <param name="contractview"></param>
        /// <returns></returns>
        public void AddContract(ContractViewModel contractview)
        {
            string strNameType = "供应商";
            if (contractview.Type == (int)SellerSupplierType.Seller)
                strNameType = "销售商";
            //更新原合同为关闭
            if ( _contractRepository.GetModel()
                .Include(p => p.SellerSupplier)
                .Any(o => o.SpecialId == contractview.SpecialId && o.SellerSupplier.Name == contractview.Name && o.SellerSupplier.Type == (SellerSupplierType)contractview.Type))
                throw new BusinessException(string.Format(BusinessResourceMessage.ItemBeenHade, strNameType+"合同名称"));

            //供应商销售商集合
            SellerSupplier mSellerSupplier = new SellerSupplier();
            mSellerSupplier.Name = contractview.Name;
            mSellerSupplier.Type = (SellerSupplierType)contractview.Type;
            mSellerSupplier.Status = Convert.ToBoolean((int)SellerSupplierStatus.Normal);
            mSellerSupplier.Phone = contractview.Phone;
            mSellerSupplier.ChargeBankNumber = contractview.ChargeBankNumber;
            mSellerSupplier.Bank = contractview.Bank;
            mSellerSupplier.ChargeName = contractview.ChargeName;
            mSellerSupplier.CertificateNum =  contractview.CertificateNum;
            mSellerSupplier.CreaterId = contractview.OperatorID;
            mSellerSupplier.CreateTime = contractview.OptionTime;
            mSellerSupplier.UpdaterId = contractview.OperatorID;
            mSellerSupplier.UpdaterName = contractview.OperatorName;
            mSellerSupplier.UpdateTime = contractview.OptionTime;

            TransactionScopeNoMsdtc.UsingTransactionNoMsdtc(_db, () =>
            {
                _sellersupplierRepository.Insert(mSellerSupplier);
                Contract mNewContract = new Contract();
                mNewContract.Name = contractview.ContractName;
                mNewContract.Code = CommonMethod.GetInstance.GenerateCode("YTHT");

                mNewContract.Type = ContractType.Supplier;
                if (contractview.Type == (int)SellerSupplierType.Seller)
                    mNewContract.Type = ContractType.Seller;
                mNewContract.Status = ContractStatus.Normal;
                //mNewContract.StartDate = DateTime.Parse(_contractview.StartDate);
                mNewContract.EndDate = DateTime.Parse(contractview.EndDate);
                mNewContract.CreaterId = contractview.OperatorID;
                mNewContract.CreateTime = contractview.OptionTime;
                mNewContract.UpdaterId = contractview.OperatorID;
                mNewContract.UpdateTime = contractview.OptionTime;
                mNewContract.SpecialId = contractview.SpecialId;
                mNewContract.SellerSupplierId = mSellerSupplier.ID;

                List<Attachment> lstAttachment = new List<Attachment>();
                foreach (ContractAttachment temp in contractview.Attachments)
                {
                    Attachment mAttachment = new Attachment();
                    mAttachment.Name = temp.Item1;
                    mAttachment.Type = AttachmentType.ContractAttachment;
                    mAttachment.Address = temp.Item2;
                    string suffix = "";
                    string[] arrName = temp.Item1.Split('.');
                    if (arrName.Length > 1)
                    {
                        suffix = "."+arrName[arrName.Length - 1];
                    }
                    mAttachment.Suffix = suffix;
                    mAttachment.CreateTime = contractview.OptionTime;
                    lstAttachment.Add(mAttachment);
                }
                mNewContract.Attachments = lstAttachment;
                _contractRepository.Insert(mNewContract);
            });
        }
예제 #2
0
        public DataResult RenewalContract(ContractViewModel inputContract)
        {
            #region 角色验证
            //分社访问
            if (LoginUser.Type != 0 && LoginUser.Type != UserType.Branch)
            {
                throw new DataOperationPermissions(BusinessResourceMessage.NoPower);
            }
            #endregion

            #region 输入验证
            if (string.IsNullOrEmpty(inputContract.ContractName))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemCanNotNull, "合同名称"));
            if (inputContract.ContractName.Length > 50)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemLenError, "合同名称", "50"));
            if (!CommonValidator.isDateTime(inputContract.EndDate.ToString()))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemFormatError, "合同到期时间"));
            if (DateTime.Now > DateTime.Parse(inputContract.EndDate))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemComparison, "合同到期时间","当前时间"));
            if (inputContract.Attachments.Count < 1 || string.IsNullOrEmpty(inputContract.Attachments.FirstOrDefault().ToString()))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemCanNotNull, "合同附件"));
            bool isErrAttachments = false;
            bool isErrLenAttachments = false;
            foreach (var item in inputContract.Attachments)
            {
                string fileEnd = item.Item1.Trim().Substring(item.Item1.Trim().LastIndexOf(".") + 1).ToLower();
                if (fileEnd != "gif" && fileEnd != "jpg" && fileEnd != "png" && fileEnd != "jpeg" && fileEnd != "bmp" && fileEnd != "pdf")
                {
                    isErrAttachments = true;
                    break;
                }
                if (item.Item1.Length > 50)
                {
                    isErrLenAttachments = true;
                    break;
                }
            }
            if (isErrAttachments)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemFormatError, "合同附件"));
            if (isErrLenAttachments)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemLenError, "合同附件名称", "50"));
            #endregion

            inputContract.OperatorID = LoginUser.ID;
            inputContract.OperatorName = LoginUser.Name;
            inputContract.OptionTime = DateTime.Now;
            contractService.RenewalContract(inputContract);
            dataResult.Code = ResponseStatusCode.Success;
            dataResult.Msg = BusinessResourceMessage.Success;
            return dataResult;
        }
        /// <summary>
        /// 续约专线合同 Pwp 2015-09-22
        /// </summary>
        /// <param name="_branchview"></param>
        /// <returns></returns>
        public void RenewalContract(ContractViewModel contractview)
        {
            //更新原合同为关闭
            Contract mOldContract = _contractRepository.GetModelTracking().Where(o => o.ID == contractview.ID).FirstOrDefault();
            if(mOldContract == null)
                throw new BusinessException(string.Format(BusinessResourceMessage.ItemNotFound, "原合同单"));

            //新合同创建
            Contract mNewContract = new Contract();
            mNewContract.Name = contractview.ContractName;
            mNewContract.Code = CommonMethod.GetInstance.GenerateCode("YTHT");
            mNewContract.Type = ContractType.SpecialLine;
            mNewContract.Status = ContractStatus.Renewal;
            //mNewContract.StartDate = mOldContract.StartDate;
            mNewContract.EndDate = DateTime.Parse(contractview.EndDate);
            mNewContract.CreaterId = contractview.OperatorID;
            mNewContract.CreateTime = contractview.OptionTime;
            mNewContract.UpdaterId = contractview.OperatorID;
            mNewContract.UpdateTime = contractview.OptionTime;
            if (mOldContract.BranchId!=null)
            mNewContract.BranchId = mOldContract.BranchId;
            if (mOldContract.SpecialId != null)
            mNewContract.SpecialId = mOldContract.SpecialId;
            if (mOldContract.SellerSupplierId != null)
            mNewContract.SellerSupplierId = mOldContract.SellerSupplierId;

            List<Attachment> lstAttachment = new List<Attachment>();
            foreach (ContractAttachment temp in contractview.Attachments)
            {
                Attachment mAttachment = new Attachment();
                mAttachment.Name = temp.Item1;
                mAttachment.Type = AttachmentType.ContractAttachment;
                mAttachment.Address = temp.Item2;
                string suffix = "";
                string[] arrName = temp.Item1.Split('.');
                if (arrName.Length > 1)
                {
                    suffix = "." + arrName[arrName.Length - 1];
                }
                mAttachment.Suffix = suffix;
                mAttachment.CreateTime = contractview.OptionTime;
                lstAttachment.Add(mAttachment);
            }
            mNewContract.Attachments = lstAttachment;

            TransactionScopeNoMsdtc.UsingTransactionNoMsdtc(_db, () =>
            {
                _contractRepository.Update(x => x.ID == contractview.ID, u => new Contract
                {
                    Status = ContractStatus.Close
                });
                _contractRepository.Insert(mNewContract);
                _specialRepository.Update(x => x.ID == mOldContract.SpecialId, u => new Special
                {
                    EndDate = DateTime.Parse(contractview.EndDate)
                });
            });
        }
예제 #4
0
        public DataResult AddContract(ContractViewModel inputContract)
        {
            #region 角色验证
            //分社访问
            if (LoginUser.Type != 0 && LoginUser.Type != UserType.Branch)
            {
                throw new DataOperationPermissions(BusinessResourceMessage.NoPower);
            }
            #endregion

            #region 输入验证

            string strNameType = "供应商";
            if (inputContract.Type == (int)SellerSupplierType.Seller)
                strNameType = "销售商";

            if (inputContract.SpecialId == 0)
                throw new DataValidationException(string.Format(BusinessResourceMessage.Inexistent, "专线"));
            if (string.IsNullOrEmpty(inputContract.Name))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemCanNotNull, strNameType+"名称"));
            if (inputContract.Name.Length > 50)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemLenError, strNameType+"名称", "50"));
            if (string.IsNullOrEmpty(inputContract.Bank))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemCanNotNull, "开户行"));
            if (inputContract.Bank.Length > 30)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemLenError, "开户行", "30"));
            if (string.IsNullOrEmpty(inputContract.ChargeBankNumber))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemCanNotNull, "银行帐号"));
            if (inputContract.ChargeBankNumber.Length > 20)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemLenError, "银行帐号", "20"));
            if (string.IsNullOrEmpty(inputContract.ChargeName))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemCanNotNull, "负责人"));
            if (inputContract.ChargeName.Length > 20)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemLenError, "负责人", "20"));
            if (string.IsNullOrEmpty(inputContract.CertificateNum))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemCanNotNull, "身份证"));
            if (inputContract.CertificateNum.Length > 18)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemLenError, "身份证", "18"));
            if (!CommonValidator.isMobile(inputContract.Phone))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemFormatError, "手机"));
            if (string.IsNullOrEmpty(inputContract.ContractName))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemCanNotNull, "合同名称"));
            if (inputContract.ContractName.Length > 50)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemLenError, "合同名称", "50"));
            if (!CommonValidator.isDateTime(inputContract.EndDate))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemFormatError, "合同到期时间"));
            if (inputContract.Attachments.Count < 1 || string.IsNullOrEmpty(inputContract.Attachments.FirstOrDefault().ToString()))
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemCanNotNull, "合同附件"));
            bool isErrAttachments = false;
            bool isErrLenAttachments = false;
            foreach (var item in inputContract.Attachments)
            {
                string fileEnd = item.Item1.Trim().Substring(item.Item1.Trim().LastIndexOf(".") + 1).ToLower();
                if (fileEnd != "gif" && fileEnd != "jpg" && fileEnd != "png" && fileEnd != "jpeg" && fileEnd != "bmp" && fileEnd != "pdf")
                {
                    isErrAttachments = true;
                    break;
                }
                if (item.Item1.Length > 50)
                {
                    isErrLenAttachments = true;
                    break;
                }
            }
            if (isErrAttachments)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemFormatError, "合同附件"));
            if (isErrLenAttachments)
                throw new DataValidationException(string.Format(BusinessResourceMessage.ItemLenError, "合同附件名称", "50"));
            #endregion

            inputContract.OperatorID = LoginUser.ID;
            inputContract.OperatorName = LoginUser.Name;
            inputContract.OptionTime = DateTime.Now;
            contractService.AddContract(inputContract);
            dataResult.Code = ResponseStatusCode.Success;
            dataResult.Msg = BusinessResourceMessage.Success;
            return dataResult;
        }