public bool CreateAgency(TravelAgency agency)
 {
     bool success = true;
     try
     {
         using (var db = new EntryContext())
         {
             if (db.TravelAgencies.FirstOrDefault(a => a.AgencyCode.Equals(agency.AgencyCode, StringComparison.CurrentCultureIgnoreCase)) != null)
             {
                 success = false;
             }
             else
             {
                 db.TravelAgencies.Add(agency);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         success = false;
         Logs.Error("CreateAgency Exception : " + ex.ToString());
     }
     return success;
 }
 private TravelAgency AssemblyAgency()
 {
     TravelAgency _agency = null;
     try
     {
         _agency = new TravelAgency();
         _agency.ItemGuid = Guid.NewGuid();
         _agency.AgencyName = this.ui_agencyName.Text;
         _agency.AgencyCode = this.ui_agencyCode.Text;
         _agency.AgencyPrincipal = this.ui_agencyPrincipal.Text;
         _agency.AgencyPrincipalPhone = this.ui_agencyPrincipalPhone.Text;
         _agency.AgencyFinancePhone = this.ui_agencyFinancePhone.Text;
         _agency.AgencyFax = this.ui_agencyFax.Text;
         _agency.AgencyAddress = this.ui_agencyAddress.Text;
         _agency.AgencyContacts = new List<TravelContact>();
         if (!(string.IsNullOrEmpty(this.ui_agencyContactU1.Text) && string.IsNullOrEmpty(this.ui_agencyContactQQ1.Text)))
         {
             _agency.AgencyContacts.Add(new TravelContact(this.ui_agencyContactU1.Text, this.ui_agencyContactQQ1.Text));
         }
         if (!(string.IsNullOrEmpty(this.ui_agencyContactU2.Text) && string.IsNullOrEmpty(this.ui_agencyContactQQ2.Text)))
         {
             _agency.AgencyContacts.Add(new TravelContact(this.ui_agencyContactU2.Text, this.ui_agencyContactQQ2.Text));
         }
         if (!(string.IsNullOrEmpty(this.ui_agencyContactU3.Text) && string.IsNullOrEmpty(this.ui_agencyContactQQ3.Text)))
         {
             _agency.AgencyContacts.Add(new TravelContact(this.ui_agencyContactU3.Text, this.ui_agencyContactQQ3.Text));
         }
         _agency.LastUpdateTime = _agency.CreateTime = DateTime.Now;
     }
     catch (Exception ex)
     {
         Logs.Error("AssemblyAgency Exception:" + ex.ToString());
     }
     return _agency;
 }
        protected void TypeIn_Click(object sender, EventArgs e)
        {
            GetAgencyControl();

            TravelAgency agency = new TravelAgency();
            agency.ItemGuid = Guid.NewGuid();
#if  true
            agency.AgencyCode = this.AgencyCode.Text;
            agency.AgencyName = this.AgencyName.Text;
            agency.AgencyFax = this.AgencyFax.Text;
            agency.AgencyPrincipal = this.AgencyPrincipal.Text;
            agency.AgencyPrincipalPhone = this.AgencyPrincipalPhone.Text;
            agency.AgencyAddress = this.AgencyAddress.Text;
#else
            agency.AgencyCode = "A003";
            agency.AgencyName = "飞雪旅行社";
            agency.AgencyPhonesList = new List<string>();
            agency.AgencyPhonesList.Add("18602410279");
            agency.AgencyFax = "024-77814515";
            agency.AgencyPrincipal = "张浩";
            agency.AgencyPrincipalPhone = "18602410279";
            agency.AgencyAddress = "沈阳";
#endif
            if (a_control.CreateAgency(agency))
            {
                Response.Redirect("AgencyManager");
            }
            else
            {
                FailureText.Text = "录入失败:检查是否存在或稍后重试!";
                ErrorMessage.Visible = true;
            }
        }
        private void CompleteAgency(ref TravelAgency agency)
        {
            if (agency.ItemGuid == new Guid())
            {
                agency.ItemGuid = Guid.NewGuid();
                agency.CreateTime = DateTime.Now;
            }
            agency.LastUpdateTime = DateTime.Now;

            foreach (var con in agency.AgencyContacts)
            {
                con.ItemGuid = Guid.NewGuid();
                con.CreateTime = con.LastUpdateTime = DateTime.Now;
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     string code = null;
     if (!IsPostBack)
     {
         code = Request.QueryString["Code"];
         if (!string.IsNullOrEmpty(code))
         {
             GetAgencyControl();
             var item = a_control.GetAgenciesByFilter("Code", code)[0];
             BindData(item);
             a_agency = item;
             ChangeInputFieldState(false);
             this.CreateButton.Visible = false;
             this.EditButton.Visible = true;
         }
     }
 }
 protected void Update_Click(object sender, EventArgs e)
 {
     GetAgencyControl();
     TravelAgency agency = new TravelAgency();
     agency.Id = Convert.ToInt32(this.HideId.Text);
     agency.ItemGuid = new Guid(this.HideGuid.Text);
     agency.AgencyCode = this.AgencyCode.Text;
     agency.AgencyName = this.AgencyName.Text;
     //agency.AgencyPhonesList = new List<string>();
     //agency.AgencyPhonesList.Add(this.AgencyPhone.Text);
     agency.AgencyFax = this.AgencyFax.Text;
     agency.AgencyPrincipal = this.AgencyPrincipal.Text;
     agency.AgencyPrincipalPhone = this.AgencyPrincipalPhone.Text;
     agency.AgencyAddress = this.AgencyAddress.Text;
     if (a_control.UpdateAgency(agency))
     {
         Response.Redirect("AgencyManager");
     }
     else
     {
         FailureText.Text = "更新失败!";
         ErrorMessage.Visible = true;
     }
 }
 public bool UpdateAgencyByCode(TravelAgency agency)
 {
     bool success = true;
     try
     {
     }
     catch (Exception ex)
     {
         success = false;
         Logs.Error("UpdateAgencyByCode Exception : " + ex.ToString());
     }
     return success;
 }
 public bool UpdateAgency(TravelAgency a_agency)
 {
     bool success = true;
     try
     {
         using (var db = new EntryContext())
         {
             db.Entry<TravelAgency>(a_agency).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         success = false;
         Logs.Error("UpdateAgency Exception : " + ex.ToString());
     }
     return success;
 }
 private void BindData(TravelAgency agency)
 {
     this.HideId.Text = agency.Id.ToString();
     this.HideGuid.Text = agency.ItemGuid.ToString();
     this.AgencyCode.Text = agency.AgencyCode;
     this.AgencyName.Text = agency.AgencyName;
     this.AgencyPhone.Text = agency.AgencyPrincipalPhone;
     this.AgencyFax.Text = agency.AgencyFax;
     this.AgencyPrincipal.Text = agency.AgencyPrincipal;
     this.AgencyPrincipalPhone.Text = agency.AgencyPrincipalPhone;
     this.AgencyAddress.Text = agency.AgencyAddress;
 }