public Procurementcontract CreateProcurementcontract(Procurementcontract info, List<Procurementcontractdetail> detailInfos)
 {
     var coderuleManagement = new CoderuleManagement(Management);
     info.Contractid = coderuleManagement.GenerateCodeRule(Procurementcontract.RuleCode+DateTime.Today.ToString("yyyyMM"), false);
     foreach (var detailInfo in detailInfos)
     {
         detailInfo.Contractid = info.Contractid;
     }
     var detailManagement = new ProcurementcontractdetailManagement(Management);
     try
     {
         Management.BeginTransaction();
         Management.CreateProcurementcontract(info);
         foreach (var detailInfo in detailInfos)
         {
             detailManagement.CreateProcurementcontractdetail(detailInfo);
         }
         Management.Commit();
     }
     catch
     {
         Management.Rollback();
         throw;
     }
     return info;
 }
 public Procurementcontract CreateProcurementcontract(Procurementcontract info)
 {
     try
     {
         Management.BeginTransaction();
         Management.CreateProcurementcontract(info);
         Management.Commit();
     }
     catch
     {
         Management.Rollback();
         throw;
     }
     return info;
 }
        public Procurementcontract CreateProcurementcontract(Procurementcontract info)
        {
            try
            {
                string sqlCommand = @"INSERT INTO ""PROCUREMENTCONTRACT"" (""CONTRACTID"",""CONTENT"",""CREATEDDATE"",""CONTRACTDATE"",""SUPPLIER"",""OPERATOR"",""SUBCOMPANY"",""CREATOR"",""PSID"") VALUES (:Contractid,:Content,:Createddate,:Contractdate,:Supplier,:Operator,:Subcompany,:Creator,:Psid)";
                this.Database.AddInParameter(":Contractid", info.Contractid);//DBType:VARCHAR2
                this.Database.AddInParameter(":Content", info.Content);//DBType:NVARCHAR2
                this.Database.AddInParameter(":Createddate", info.Createddate);//DBType:DATE
                this.Database.AddInParameter(":Contractdate", info.Contractdate);//DBType:DATE
                this.Database.AddInParameter(":Supplier", info.Supplier);//DBType:NVARCHAR2
                this.Database.AddInParameter(":Operator", info.Operator);//DBType:NVARCHAR2
                this.Database.AddInParameter(":Subcompany", info.Subcompany);//DBType:VARCHAR2
                this.Database.AddInParameter(":Creator", info.Creator);//DBType:NVARCHAR2
                this.Database.AddInParameter(":Psid", info.Psid);//DBType:VARCHAR2
                this.Database.ExecuteNonQuery(sqlCommand);

            }
            finally
            {
                this.Database.ClearParameter();
            }
            return info;
        }
 protected void ReadEntityToControl(Procurementcontract headInfo)
 {
     litContractid.Text = headInfo.Contractid;//合同编号
     //litContent.Text = headInfo.Content;//主要内容
     if (headInfo.Createddate.HasValue)
     {
         litCreateddate.Text = headInfo.Createddate.Value.ToString(UiConst.DateFormat);//创建日期
     }
     if (headInfo.Contractdate.HasValue)
     {
         litContractdate.Text = headInfo.Contractdate.Value.ToString(UiConst.DateFormat); ;//签订日期
     }
     ucSelectSupplier.Supplierid = headInfo.Supplier;//供应商
     //litOperator.Text = headInfo.Operator;//合同负责人
     ucSubCompany.SubcompanyId = headInfo.Subcompany; //分公司
     litCreator.Text = headInfo.Creator;//创建人
 }
 protected void ReadEntityToControl(Procurementcontract headInfo)
 {
     litPsid.Text = headInfo.Contractid;
     if (headInfo.Contractdate.HasValue)
     {
         litContactscheduledate.Text = Convert.ToDateTime(headInfo.Contractdate.Value).ToString("yyyy-MM-dd"); ;
     }
     var info = this.AssetsupplierService.RetrieveAssetsupplierBySupplierid(headInfo.Supplier);
     if (info != null)
     {
         lblSelectSupplier.Text = info.Suppliername;
     }
     var subcompanyinfoService = new SubcompanyinfoService();
     decimal decSubcompanyId = 0;
     if (decimal.TryParse(headInfo.Subcompany, out decSubcompanyId))
     {
         var infosubcompany = subcompanyinfoService.RetrieveSubcompanyinfoBySubcompanyid(decSubcompanyId);
         if (infosubcompany != null)
         {
             lblSubCompany.Text = infosubcompany.Subcompanyname;
         }
     }
     if (headInfo.Createddate.HasValue)
     {
         lblApplydate.Text = Convert.ToDateTime(headInfo.Createddate).ToString("yyyy-MM-dd");
     }
 }
        public Procurementcontract UpdateProcurementcontractByContractid(Procurementcontract info, List<Procurementcontractdetail> detailInfos)
        {
            foreach (var detailInfo in detailInfos)
            {
                detailInfo.Contractid = info.Contractid;
            }
            var detailManagement = new ProcurementcontractdetailManagement(Management);

            var dbContractDetails = detailManagement.RetrieveProcurementcontractdetailListByContractid(info.Contractid);

            try
            {
                Management.BeginTransaction();
                Management.UpdateProcurementcontractByContractid(info);

                foreach (var detail in detailInfos)
                {
                    var existInfo = dbContractDetails.Where(p => p.Contractdetailid == detail.Contractdetailid).FirstOrDefault();

                    if (existInfo == null)
                    {
                        detailManagement.CreateProcurementcontractdetail(detail);
                    }
                    else
                    {
                        detailManagement.UpdateProcurementcontractdetailByContractdetailid(detail);
                    }
                }
                Management.Commit();
            }
            catch
            {
                Management.Rollback();
                throw;
            }
            return info;
        }
 public Procurementcontract UpdateProcurementcontractByContractid(Procurementcontract info)
 {
     try
     {
         this.Database.AddInParameter(":Contractid", info.Contractid);//DBType:VARCHAR2
         this.Database.AddInParameter(":Content", info.Content);//DBType:NVARCHAR2
         this.Database.AddInParameter(":Createddate", info.Createddate);//DBType:DATE
         this.Database.AddInParameter(":Contractdate", info.Contractdate);//DBType:DATE
         this.Database.AddInParameter(":Supplier", info.Supplier);//DBType:NVARCHAR2
         this.Database.AddInParameter(":Operator", info.Operator);//DBType:NVARCHAR2
         this.Database.AddInParameter(":Subcompany", info.Subcompany);//DBType:VARCHAR2
         this.Database.AddInParameter(":Creator", info.Creator);//DBType:NVARCHAR2
         this.Database.AddInParameter(":Psid", info.Psid);//DBType:VARCHAR2
         string sqlCommand = @"UPDATE ""PROCUREMENTCONTRACT"" SET  ""CONTENT""=:Content , ""CREATEDDATE""=:Createddate , ""CONTRACTDATE""=:Contractdate , ""SUPPLIER""=:Supplier , ""OPERATOR""=:Operator , ""SUBCOMPANY""=:Subcompany , ""CREATOR""=:Creator , ""PSID""=:Psid WHERE  ""CONTRACTID""=:Contractid";
         this.Database.ExecuteNonQuery(sqlCommand);
     }
     finally
     {
         this.Database.ClearParameter();
     }
     return info;
 }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            if (!ucContactscheduledate.DateValue.HasValue)
            {
                UIHelper.Alert(this, "请选择合同签订日期!");
                return;
            }
            if (string.IsNullOrEmpty(ucSubCompany.SubcompanyId))
            {
                UIHelper.Alert(this, "请选择分公司!");
                return;
            }
            if (string.IsNullOrEmpty(ucSelectSupplier.Supplierid))
            {
                UIHelper.Alert(this, "请选择供应商!");
                return;
            }
            if (!ucApplydate.DateValue.HasValue)
            {
                UIHelper.Alert(this, "请选择创建日期!");
                return;
            }

            Procurementcontract headInfo = null;
            if (string.IsNullOrEmpty(Contractid))
            {
                //add
                headInfo = new Procurementcontract();
                WriteControlValueToEntity(headInfo);
                this.ProcurementcontractService.CreateProcurementcontract(headInfo, ProcurementContractDetail);
            }
            else
            {
                //edit
                headInfo = ProcurementcontractService.RetrieveProcurementcontractByContractid(Contractid);
                if (headInfo == null) { UIHelper.Alert(this, "对不起,合同已被删除,请重新录入!"); return; }
                WriteControlValueToEntity(headInfo);
                ProcurementcontractService.UpdateProcurementcontractByContractid(headInfo, ProcurementContractDetail);
            }
            UIHelper.AlertMessageGoToURL(this, "保存成功!", ResolveUrl("~/Admin/ContractList.aspx"));
        }
 protected void WriteControlValueToEntity(Procurementcontract headInfo)
 {
     headInfo.Contractid = litPsid.Text;
     headInfo.Contractdate = ucContactscheduledate.DateValue;
     headInfo.Psid=PageUtility.GetQueryStringValue("Psid");
     headInfo.Supplier = ucSelectSupplier.Supplierid;
     headInfo.Subcompany = ucSubCompany.SubcompanyId;
     headInfo.Createddate = ucApplydate.DateValue;
     if (!headInfo.Createddate.HasValue)
     {
         headInfo.Createddate = DateTime.Now;
     }
     if(WebContext.Current.CurrentUser!=null)
     {
         headInfo.Creator = WebContext.Current.CurrentUser.Username;
     }
 }
 protected void ReadEntityToControl(Procurementcontract headInfo)
 {
     litPsid.Text = headInfo.Contractid;
     if (headInfo.Contractdate.HasValue)
     {
         ucContactscheduledate.DateValue = headInfo.Contractdate;
     }
     ucSelectSupplier.Supplierid = headInfo.Supplier;
     ucSubCompany.SubcompanyId = headInfo.Subcompany;
     if (headInfo.Createddate.HasValue)
     {
         ucApplydate.DateValue = headInfo.Createddate;
     }
 }
 /// <summary>
 /// 确定
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     DateTime dateTime = DateTime.MinValue;
     if (!ucContactscheduledate.DateValue.HasValue)
     {
         UIHelper.Alert(this, "请选择合同签订日期!");
         return;
     }
     if (!ucApplydate.DateValue.HasValue)
     {
         UIHelper.Alert(this, "请选择创建日期!");
         return;
     }
     if (ProcurementContractDetail.Count == 0)
     {
         UIHelper.Alert(this, "请录入合同明细!"); return;
     }
     Procurementcontract headInfo = null;
     if (string.IsNullOrEmpty(Contractid))
     {
         //add
         headInfo = new Procurementcontract();
         WriteControlValueToEntity(headInfo);
         this.ProcurementcontractService.CreateProcurementcontract(headInfo, ProcurementContractDetail);
     }
     else
     {
         //edit
         headInfo = ProcurementcontractService.RetrieveProcurementcontractByContractid(Contractid);
         if (headInfo == null) { UIHelper.Alert(this, "对不起,合同已被删除,请重新录入!"); return; }
         WriteControlValueToEntity(headInfo);
         ProcurementcontractService.UpdateProcurementcontractByContractid(headInfo, ProcurementContractDetail);
     }
     UIHelper.AlertMessageGoToURL(this, "提交成功!", ResolveUrl("~/Admin/ContractList.aspx"));
 }