예제 #1
0
        private bool DumpToDataSet(DataSet ds, string TableName, string[] Data, char Divider)
        {
            IPGeoinfo GeoInfo = new IPGeoinfo(CommonFunctions.SxPath);

            if (!GeoInfo.Open())
            {
                ErrorMessage = GeoInfo.ErrorMessage;
                return(false);
            }
            ds.Tables[TableName].Rows.Clear();
            foreach (string rec in Data) //обходим массив входных строк
            {
                if (rec.Trim() != string.Empty)
                {
                    string[] val   = rec.Split(Divider); //разделяем строки на составляющие части
                    string   IP    = "";
                    string   Field = "";
                    try
                    {
                        IP    = val[0];
                        Field = val[1];
                    }
                    catch (Exception ex)
                    {
                        ErrorMessage = ex.Message;
                        GeoInfo.Close();
                        return(false);
                    }

                    // вытаскиваем из БД информацию об IP
                    Dictionary <string, object> IPInfo = GeoInfo.GetIPInfo(IP);

                    //раскладываем ее в DataSet
                    try
                    {
                        DataRow dr = ds.Tables[TableName].Rows.Add();
                        foreach (string Key in IPInfo.Keys)
                        {
                            dr[Key] = IPInfo[Key];
                        }
                        dr["Field"] = Field;
                    }
                    catch (Exception ex)
                    {
                        ErrorMessage = ex.Message;
                        GeoInfo.Close();
                        return(false);
                    }
                }
            }

            GeoInfo.Close();
            return(true);
        }
예제 #2
0
        private void CreateDataSet()
        {
            //вытаскиваем поля и строим таблицу DataSet
            IPGeoinfo tmpGeoInfo = new IPGeoinfo(CommonFunctions.SxPath);

            tmpGeoInfo.Open();
            Dictionary <string, Type> Fields = tmpGeoInfo.GetAllFields();

            Fields.Add("field", typeof(string));
            tmpGeoInfo.Close();

            dsIP.Tables.Add("Info");
            dsIP.Tables["Info"].Columns.Add("Parameter", typeof(string));
            dsIP.Tables["Info"].Columns.Add("Data", typeof(string));

            dsIP.Tables.Add("IP");
            foreach (string key in Fields.Keys)
            {
                dsIP.Tables["IP"].Columns.Add(key, Fields[key]);
            }
        }