Ejemplo n.º 1
0
        /// <summary>Handles the Load event of the Page control.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            using (ApsoilWeb.Service soilsDB = new Apsoil.ApsoilWeb.Service())
            {
                List <string> allSoils = new List <string>();
                allSoils.AddRange(soilsDB.SoilNames());
                allSoils.Sort();

                if (Request.QueryString["Paths"] != null)
                {
                    allSoils.Clear();
                    string[] paths = Request.QueryString["Paths"].Split(";".ToCharArray());
                    allSoils.AddRange(paths);
                }

                List <string> selectedItems = GetSelectedItems();

                Label.Text = "Number of soils: " + allSoils.Count.ToString();
                ListBox.Items.Clear();
                foreach (string soilName in allSoils)
                {
                    ListItem item = new ListItem(soilName);
                    item.Selected = selectedItems.Contains(soilName);
                    ListBox.Items.Add(item);
                }
            }
        }
        /// <summary>
        /// User has clicked on upload button.
        /// </summary>
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            using (ApsoilWeb.Service Soils = new Apsoil.ApsoilWeb.Service())
            {
                StreamReader In       = new StreamReader(File1.FileContent);
                string       contents = In.ReadToEnd();

                if (!userSoil)
                {
                    // Insert all soils into database.
                    Soils.UpdateAllSoils(contents);
                }
                else
                {
                    // Update a user soil.
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(contents);
                    foreach (var soil in XmlHelper.ChildNodes(doc.DocumentElement, "Soil"))
                    {
                        var soilParams = new ApsoilWeb.JsonSoilParam()
                        {
                            JSonSoil = JsonConvert.SerializeXmlNode(soil)
                        };
                        var ok = Soils.UpdateUserSoil(soilParams);
                    }
                }

                string[] AllSoils = Soils.SoilNames();
                SuccessLabel.Text    = "Success. " + AllSoils.Length.ToString() + " soils in database.";
                SuccessLabel.Visible = true;
            }
        }
        /// <summary>
        /// User has clicked on upload button.
        /// </summary>
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            using (ApsoilWeb.Service Soils = new Apsoil.ApsoilWeb.Service())
            {
                StreamReader In       = new StreamReader(File1.FileContent);
                string       contents = In.ReadToEnd();

                if (pathToOverride == null)
                {
                    // Insert all soils into database.
                    Soils.UpdateAllSoils(contents);
                }
                else
                {
                    // Update a single soil.
                    Soils.UpdateSoil(pathToOverride, contents);
                }

                string[] AllSoils = Soils.SoilNames();
                SuccessLabel.Text    = "Success. " + AllSoils.Length.ToString() + " soils in database.";
                SuccessLabel.Visible = true;
            }
        }