示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FCCL_DAL.Entities.Ferme_CCL farm = null;
            if (Request.Params["ID"] != null)
            {
                var farmManager = new FarmManager(ConfigurationManager.ConnectionStrings["AdditionalInformation"].ConnectionString);
                farm = farmManager.GetFarmById(Convert.ToInt32(Request.Params["ID"]));
            }

            var fabricaManager =
                new FactoryManager(ConfigurationManager.ConnectionStrings["AdditionalInformation"].ConnectionString);
            var fabrici = fabricaManager.GetFactories();
            Asociatia.DataSource = fabrici;
            if (farm != null && farm.FabricaId != null)
            {
                Asociatia.SelectedValue = farm.FabricaId.ToString();
            }
            Asociatia.DataBind();

            var countyManager =
                new CountyManager(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString);
            var counties = countyManager.GetAllCounties();
            Judet.DataSource = counties;
            if (farm != null && farm.JudetId != null)
            {
                Judet.SelectedValue = farm.JudetId.ToString();
            }
            Judet.DataBind();

            InsertF.Visible = true;

            if (farm != null)
            {
                //populate farm table
                IdFerma.Text        = farm.Id.ToString();
                FermaCod.Text       = farm.Cod;
                FermaName.Text      = farm.Nume;
                FarmEmail.Text      = farm.Email;
                Localitate.Text     = farm.Oras;
                Strada.Text         = farm.Strada;
                Numar.Text          = farm.Numar;
                CodPostal.Text      = farm.CodPostal;
                Telefon.Text        = farm.Telefon;
                Fax.Text            = farm.Fax;
                PersContact.Text    = farm.PersoanaDeContact;
                TelPersContact.Text = farm.TelPersoanaContact;
                SendSms.Checked     = farm.SendSms;

                //populate user table
                var userManager =
                    new UserManager(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
                var userInfo = userManager.GetUserInformationByCod(farm.Cod);
                if (userInfo != null)
                {
                    UserId.Value           = userInfo.UserId.ToString();
                    Nume.Text              = userInfo.LastName;
                    Prenume.Text           = userInfo.FirstName;
                    UserNameLbl.Text       = userInfo.UserName;
                    Email.Text             = userInfo.Email;
                    Update.Visible         = true;
                    ResetareParola.Visible = true;
                    UserNameLbl.Visible    = true;
                    Parola.Visible         = false;
                }
                else
                {
                    Insert.Visible   = true;
                    UserName.Visible = true;
                }
                UserCodLbl.Text = farm.Cod;
                UpdateF.Visible = true;
                DeleteF.Visible = true;
            }
        }
    }