protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         op   = !string.IsNullOrEmpty(Request.QueryString["op"]) ? Request.QueryString["op"] : string.Empty;
         guid = System.Guid.NewGuid().ToString();
         int ContractID = 0;
         int.TryParse(Request.QueryString["ID"], out ContractID);
         contract = Foresight.DataAccess.Contract.GetContract(ContractID);
         if (contract != null)
         {
             var list = Contract_Room.GetContract_RoomListByContractID(contract.ID);
             SetInfo(contract);
             approve = Foresight.DataAccess.Contract_Approve.GetContract_ApproveByContractID(contract.ID);
             stop    = Foresight.DataAccess.Contract_Stop.GetContract_StopByContractID(contract.ID);
         }
         if (contract == null || contract.ContractStatus.Equals("yuding") || this.op.Equals("edit"))
         {
             canEdit = true;
         }
         if (this.op.Equals("edit"))
         {
             cansavelog = true;
         }
         if (contract != null)
         {
             canprint = true;
         }
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         op   = !string.IsNullOrEmpty(Request.QueryString["op"]) ? Request.QueryString["op"] : string.Empty;
         guid = System.Guid.NewGuid().ToString();
         int.TryParse(Request.QueryString["ID"], out ContractID);
         if (this.op.Equals("add"))
         {
             canAdd = true;
         }
         if (this.op.Equals("edit") || this.op.Equals("newrent"))
         {
             canEdit = true;
         }
         contract = Foresight.DataAccess.Contract.GetContract(ContractID);
         if (contract == null)
         {
             canEdit = true;
         }
         else
         {
             canprint = true;
             if (contract.ContractStatus.Equals("yuding"))
             {
                 canEdit = true;
             }
             if (this.op.Equals("rent"))
             {
                 canRent    = true;
                 cansavelog = true;
             }
             if (this.op.Equals("edit"))
             {
                 cansavelog = true;
             }
             if (this.op.Equals("view"))
             {
                 canView = true;
             }
             if (this.op.Equals("newrent"))
             {
                 canNewRent = true;
                 cansavelog = true;
                 canprint   = false;
                 canAdd     = true;
             }
             SetInfo(contract);
             if (!canNewRent)
             {
                 approve = Foresight.DataAccess.Contract_Approve.GetContract_ApproveByContractID(contract.ID);
                 stop    = Foresight.DataAccess.Contract_Stop.GetContract_StopByContractID(contract.ID);
             }
             else
             {
                 int.TryParse(Request.QueryString["ID"], out TopContractID);
                 ContractID = 0;
                 var contractRoomList = Contract_Room.GetContract_RoomListByContractID(contract.ID);
                 using (SqlHelper helper = new SqlHelper())
                 {
                     try
                     {
                         helper.BeginTransaction();
                         foreach (var item in contractRoomList)
                         {
                             var data = new Contract_Room
                             {
                                 ContractID   = 0,
                                 GUID         = guid,
                                 ChargeID     = item.ChargeID,
                                 RoomID       = item.RoomID,
                                 RentName     = item.RentName,
                                 RoomLocation = item.RoomLocation,
                                 RoomArea     = item.RoomArea
                             };
                             data.Save(helper);
                         }
                         helper.Commit();
                     }
                     catch (Exception)
                     {
                         helper.Rollback();
                     }
                 }
             }
         }
     }
 }