Пример #1
0
    public List <Fabrica> createTable()
    {
        var farmManager =
            new FarmManager(ConfigurationManager.ConnectionStrings["AdditionalInformation"].ConnectionString);

        var factory = Fabrica.Text.Length > 0 ? Fabrica.Text.Trim() : null;
        var farm    = Ferma.Text.Length > 0 ? Ferma.Text.Trim() : null;
        var cod     = Code.Text.Length > 0 ? Code.Text.Trim() : null;

        var farms = farmManager.GetAllFarms(farm, cod);

        var factoryManager =
            new FactoryManager(ConfigurationManager.ConnectionStrings["AdditionalInformation"].ConnectionString);
        var factories = factoryManager.GetFactories(factory);

        var countiesManager =
            new CountyManager(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString);
        var counties = countiesManager.GetAllCounties();

        var values = farms.Select(x => new Fabrica
        {
            id        = x.Id.ToString(),
            cod       = x.Cod,
            nume      = x.Nume,
            numar     = x.Numar,
            email     = x.Email,
            telefon   = x.Telefon,
            oras      = x.Oras,
            strada    = x.Strada,
            fabricaid = x.FabricaId.ToString(),
            judet     = x.Judet
        }).ToList();

        var farctorieslist = values.ToList();

        foreach (var fabrica in farctorieslist)
        {
            var factoryEntity = factories.FirstOrDefault(x => x.Id.ToString(CultureInfo.InvariantCulture) == fabrica.fabricaid);
            if (factoryEntity == null)
            {
                values.Remove(fabrica);
            }
            else
            {
                fabrica.fabricaid = factoryEntity.Nume;
            }

            var countyEntity = counties.FirstOrDefault(x => x.Id.ToString(CultureInfo.InvariantCulture) == fabrica.judet);
            if (countyEntity != null)
            {
                fabrica.judet = countyEntity.DenLoc;
            }
        }

        lcount.Text = values.Count + " ferme";
        return(values);
    }
Пример #2
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;
            }
        }
    }