/// <summary>
        /// 合同续签
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult EntendContract(string id)
        {
            ViewBag.Classify = ListToSelect(SysDataDictService.GetContractClassify().Select(o => new SelectListItem()
            {
                Value = o.DicSN.ToString(), Text = o.Title
            }), emptyTitle: "请选择");
            //ViewBag.Suppliers = ListToSelect(SupplierService.GetList().Where(o => o.BusinessType == 1 && o.MasterState == 1).Select(o => new SelectListItem() { Value = o.Id, Text = o.Title }));

            var      obj         = new Logic.Entity.Contract();
            var      curr        = DateTime.Now;
            Contract oldContract = ContractBLL.FindById(id);

            oldContract.ToCopyProperty(obj);
            obj.Id          = CommonRules.GUID;
            obj.Version     = (short)(oldContract.Version + 1);
            ViewBag.Version = "续签 v" + obj.Version + ".0";
            if (obj.Version == 2)
            {
                obj.ContractSN = oldContract.ContractSN + "-" + obj.Version;
                //obj.PId = oldContract.Id;
            }

            if (obj.Version > 2)
            {
                string   st     = oldContract.ContractSN;
                string[] sArray = st.Split(new char[] { '-' });
                obj.ContractSN = sArray[0] + "-" + obj.Version;
                //obj.PId = oldContract.PId;
            }

            obj.PId         = id;
            obj.SigningDate = curr.ToString("yyyy-MM-dd");
            obj.CreateUID   = Sys.CurrentUser.UID;
            obj.CreateDT    = DateTime.Now;
            obj.StartDate   = DateTime.Parse(oldContract.EndDate).AddDays(1).ToString("yyyy-MM-dd");

            var      oldStartDate = DateTime.Parse(oldContract.StartDate);
            var      oldEndDate   = DateTime.Parse(oldContract.EndDate);
            TimeSpan ts           = oldEndDate - oldStartDate;
            var      duringDate   = ts.Days;

            obj.EndDate = DateTime.Parse(obj.StartDate).AddDays(duringDate).ToString("yyyy-MM-dd");

            obj.ContractBoths = oldContract.ContractBoths;

            return(View(obj));
        }
        public ActionResult setState_Editor(string id, short state)
        {
            var obj    = ContractBLL.FindById(id);
            var _oData = new Contract();

            ExtendHelper.CopyProperty <Contract>(_oData, obj);
            obj.State = state;
            var re = ContractBLL.Update(obj);

            #region 操作日志
            if (re.Successed)
            {
                var msg = LogEngine.CompareModelToLog <Contract>(LogModule.合同管理, obj, _oData);
                new LogEngine().WriteUpdate(msg, LogModule.合同管理);
            }
            #endregion
            return(new JsonNetResult(re));
        }
        public ActionResult EntendContract(Contract obj)
        {
            var re = new OpResult();

            var relativePath = "";
            var files        = new List <Attachment>();
            var path         = Sys.SysConstPool.SaveAttachPath(ref relativePath);

            for (int i = 0; i < Request.Files.Count; i++)
            {
                var file = Request.Files[i];
                if (file.ContentLength <= 0)
                {
                    continue;
                }
                var    filename = CommonRules.GUID + Path.GetExtension(file.FileName);
                string fullname = path + filename;
                file.SaveAs(fullname);
                files.Add(new Attachment()
                {
                    SourceClassify = 1,
                    Title          = Path.GetFileName(file.FileName),
                    Size           = file.ContentLength / 1024,
                    SaveUrl        = relativePath + filename
                });
            }

            var jia      = new Logic.Entity.ContractBoth();
            var yi       = new Logic.Entity.ContractBoth();
            var compname = Request["CompanyName"];

            if (!compname.IsNullOrEmpty())
            {
                var comps = compname.Split(',');
                jia.CompanyName = comps[0];
                yi.CompanyName  = comps[1];
            }
            var representative = Request["Representative"];

            if (!representative.IsNullOrEmpty())
            {
                var repr = representative.Split(',');
                jia.Representative = repr[0];
                yi.Representative  = repr[1];
            }
            var tel = Request["Tel"];

            if (!tel.IsNullOrEmpty())
            {
                var te = tel.Split(',');
                jia.Tel = te[0];
                yi.Tel  = te[1];
            }
            var fax = Request["Fax"];

            if (!fax.IsNullOrEmpty())
            {
                var fa = fax.Split(',');
                jia.Fax = fa[0];
                yi.Fax  = fa[1];
            }
            var taxnumber = Request["TaxNumber"];//甲方是TaxNumber,乙方是PayNumber,除此之外其余的项甲乙方都相同

            if (!taxnumber.IsNullOrEmpty())
            {
                jia.TaxNumber = taxnumber;
            }
            var paynumber = Request["PayNumber"];//乙方是PayNumber

            if (!paynumber.IsNullOrEmpty())
            {
                yi.PayNumber = paynumber;
            }
            var url = Request["Url"];

            if (!url.IsNullOrEmpty())
            {
                var ur = url.Split(',');
                jia.Url = ur[0];
                yi.Url  = ur[1];
            }
            var address = Request["Address"];

            if (!address.IsNullOrEmpty())
            {
                var addr = address.Split(',');
                jia.Address = addr[0];
                yi.Address  = addr[1];
            }
            var postcode = Request["PostCode"];

            if (!postcode.IsNullOrEmpty())
            {
                var pcode = postcode.Split(',');
                jia.PostCode = pcode[0];
                yi.PostCode  = pcode[1];
            }
            var bankname = Request["BankName"];

            if (!bankname.IsNullOrEmpty())
            {
                var bname = bankname.Split(',');
                jia.BankName = bname[0];
                yi.BankName  = bname[1];
            }

            var bankaccount = Request["BankAccount"];

            if (!bankaccount.IsNullOrEmpty())
            {
                var baccount = bankaccount.Split(',');
                jia.BankAccount = baccount[0];
                yi.BankAccount  = baccount[1];
            }
            if (!string.IsNullOrEmpty(obj.Id))
            {
                Contract oldContract = ContractBLL.FindById(obj.Id);
                obj.ContractBoths = new List <Logic.Entity.ContractBoth>();

                obj.Version     = (short)(oldContract.Version + 1);
                ViewBag.Version = "续签 v" + obj.Version + ".0";
                if (obj.Version == 2)
                {
                    obj.ContractSN = oldContract.ContractSN + "-" + obj.Version;
                    //obj.PId = oldContract.Id;
                }

                //var cSN = Request["ContractSN"];
                //obj.ContractSN = cSN;

                if (obj.Version > 2)
                {
                    string   st     = oldContract.ContractSN;
                    string[] sArray = st.Split(new char[] { '-' });
                    obj.ContractSN = sArray[0] + "-" + obj.Version;
                    //obj.PId = oldContract.PId;
                }
                obj.PId = oldContract.Id;

                obj.Id          = CommonRules.GUID;
                obj.CreateDT    = DateTime.Now;
                obj.CreateUID   = Sys.CurrentUser.UID;
                obj.CompanyId   = CommonService.CompanyId;
                obj.Attachments = files;
                jia.Signatory   = (int)(ContractSignatory.甲方);
                yi.Signatory    = (int)(ContractSignatory.乙方);
                obj.ContractBoths.Add(jia);
                obj.ContractBoths.Add(yi);

                //var existContractSN = ContractBLL.Find(o => o.ContractSN == obj.ContractSN);
                //if (existContractSN != null)
                //{
                //    re.Message = "该合同编号已存在!";
                //}
                //else
                //{
                //    re = ContractBLL.Add(obj);
                //}

                re = ContractBLL.Add(obj);
                #region 操作日志
                var msg = LogEngine.CompareModelToLog <Contract>(LogModule.合同管理, obj);
                new LogEngine().WriteInsert(msg, LogModule.合同管理);
                #endregion
            }
            return(Content(re.ToJson()));
        }