예제 #1
0
        private static AreaStatItem ParseAreaStat(XElement statElement)
        {
            if (statElement == null)
            {
                return(null);
            }
            string name = statElement.Attribute("name").Value;

            if (!string.IsNullOrEmpty(name))
            {
                AreaStatItem statItem = new AreaStatItem(name);
                string       fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, statElement.Attribute("filename").Value);
                statItem.FileName = fileName;
                statItem.MenuName = statElement.Attribute("menuname").Value;
                if (statElement.Attribute("infofilename") != null)
                {
                    statItem.InfoFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, statElement.Attribute("infofilename").Value);
                }
                string fileType = statElement.Attribute("filetype").Value.ToLower();
                switch (fileType)
                {
                case "raster":
                {
                    statItem.StatFileType = enumStatTemplateType.Raster;
                    break;
                }

                case "vector":
                {
                    statItem.StatFileType = enumStatTemplateType.Vector;
                    break;
                }
                }
                if (statElement.Attribute("statfield") != null)
                {
                    statItem.StatField = statElement.Attribute("statfield").Value;
                }
                if (statElement.Attribute("columnnames") != null)
                {
                    string   names     = statElement.Attribute("columnnames").Value;
                    string[] nameArray = names.Split(new char[] { ',', ',' });
                    if (nameArray != null && nameArray.Length > 0)
                    {
                        statItem.ColumnNames = nameArray;
                    }
                }
                return(statItem);
            }
            return(null);
        }
예제 #2
0
        public static AreaStatItem[] GetAreaStatItems()
        {
            XElement root = GetXmlRoot();

            if (root == null)
            {
                return(null);
            }
            IEnumerable <XElement> items = root.Elements("StatItem");

            if (items == null || items.Count() == 0)
            {
                return(null);
            }
            List <AreaStatItem> lstAreaStat = new List <AreaStatItem>();

            foreach (XElement item in items)
            {
                AreaStatItem statItem = ParseAreaStat(item);
                lstAreaStat.Add(statItem);
            }
            return(lstAreaStat.ToArray());
        }
예제 #3
0
 private void ChangeControlsVisibleByStatType(AreaStatItem statItem)
 {
     if (statItem.StatFileType == enumStatTemplateType.Raster)
     {
         btnOpenInfoFile.Enabled = true;
         labFields.Visible       = true;
         txtInfoFile.Visible     = true;
         btnOpenInfoFile.Visible = true;
         labFields.Visible       = false;
         cmbFields.Visible       = false;
         labInfoFile.Visible     = true;
         labColumnNames.Enabled  = true;
         txtColumnNames.Enabled  = true;
         if (statItem.ColumnNames != null && statItem.ColumnNames.Length == 3)
         {
             string   namesString = null;
             string[] columnNames = statItem.ColumnNames;
             for (int i = 0; i < columnNames.Length; i++)
             {
                 namesString = namesString + columnNames[i] + ",";
             }
             namesString         = namesString.Remove(namesString.Length - 1);
             txtColumnNames.Text = namesString;
         }
     }
     else
     {
         labFields.Visible       = true;
         labInfoFile.Visible     = false;
         cmbFields.Visible       = true;
         btnOpenInfoFile.Visible = false;
         labInfoFile.Visible     = false;
         txtInfoFile.Visible     = false;
         labColumnNames.Enabled  = false;
         txtColumnNames.Enabled  = false;
         txtColumnNames.Text     = "";
         using (IVectorFeatureDataReader vdr = VectorDataReaderFactory.GetUniversalDataReader(statItem.FileName) as IVectorFeatureDataReader)
         {
             if (vdr == null || vdr.ShapeType != enumShapeType.Polygon)
             {
                 return;
             }
             cmbFields.Items.Clear();
             if (vdr.Fields != null && vdr.Fields.Length > 0)
             {
                 foreach (string field in vdr.Fields)
                 {
                     cmbFields.Items.Add(field);
                 }
                 string settedField = statItem.StatField;
                 if (cmbFields.Items.Contains(settedField))
                 {
                     cmbFields.SelectedItem = settedField;
                 }
                 else
                 {
                     cmbFields.SelectedIndex = 0;
                 }
             }
         }
     }
     if (string.IsNullOrEmpty(statItem.InfoFileName))
     {
         txtInfoFile.Text = "";
     }
     else
     {
         txtInfoFile.Text = statItem.InfoFileName;
     }
     ChangeFileList(statItem.StatFileType);
 }