Esempio n. 1
0
        /// <summary>
        /// 设置表类型配置
        /// </summary>
        /// <param name="ClassName">类名</param>
        /// <param name="TableElementName">表元素名</param>
        /// <param name="dt">表配置</param>
        public void SetTableConfig(string ClassName, string TableElementName, System.Data.DataTable dt)
        {
            if (xn == null)
            {
                throw new System.Exception("请先设置 Root!");
            }

            System.Xml.XmlNode xn1 = xn.SelectSingleNode(ClassName);
            if (xn1 == null)
            {
                xn1 = xd.CreateElement(ClassName);
                xn.AppendChild(xn1);
            }

            System.Xml.XmlNode xn2 = xn1.SelectSingleNode(TableElementName);
            if (xn2 == null)
            {
                xn2 = xd.CreateElement(TableElementName);
                xn1.AppendChild(xn2);
            }

            if (xn2 != null && xn2.ChildNodes.Count > 0)
            {
                xn2.InnerXml = string.Empty;
            }

            StringWriter sw = new StringWriter();

            dt.WriteXml(sw, System.Data.XmlWriteMode.WriteSchema);
            xn2.InnerXml = sw.ToString();
        }
Esempio n. 2
0
        public void DoXmlResult(String[] parameters, StreamWriter w)
        {
            String sql = parameters[0];

            System.Data.DataTable tbl = _database.SelectAsDataTable("query", sql, new object[] { });
            tbl.WriteXml(w);
        }
Esempio n. 3
0
 private static int RunDataTable(SqlCeCommand cmd, SqlCeConnection conn)
 {
     cmd.Connection = conn;
     System.Data.DataTable table = new System.Data.DataTable();
     table.Locale    = CultureInfo.InvariantCulture;
     table.TableName = "data";
     table.Load(cmd.ExecuteReader());
     table.WriteXml(Console.Out, System.Data.XmlWriteMode.WriteSchema);
     return(table.Rows.Count);
 }
Esempio n. 4
0
        public response GetSpecificStory(int ID)
        {
            var dataTable = new System.Data.DataTable();

            dataTable = new System.Data.DataTable {
                TableName = "Stories"
            };
            string connString = URLInfo.GetDataBaseConnectionString();

            System.IO.StringWriter writer = new System.IO.StringWriter();
            string   returnString         = "";
            response response             = new response();

            response.result = 0;
            using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connString))
            {
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetSpecificStory", con))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add("@ID", System.Data.SqlDbType.NVarChar).Value = ID;
                    con.Open();
                    var dataReader = cmd.ExecuteReader();
                    dataTable.Load(dataReader);
                    dataTable.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema, false);
                    returnString = writer.ToString();
                    int numberOfRecords = dataTable.Rows.Count;
                    response.result = numberOfRecords;



                    SpecificStoryList list = new SpecificStoryList();
                    foreach (System.Data.DataRow row in dataTable.Rows)
                    {
                        specificStory myprod = new specificStory();
                        myprod.ID                 = row["ID"].ToString();
                        myprod.JakataID           = row["JakataID"].ToString();
                        myprod.AnimalType         = row["AnimalType"].ToString();
                        myprod.Comments           = row["Comments"].ToString();
                        myprod.MoralType          = row["MoralType"].ToString();
                        myprod.Stories            = row["Stories"].ToString();
                        myprod.StoryCategorytName = row["StoryCategorytName"].ToString();
                        myprod.Title              = row["Title"].ToString();


                        list.specificStory.Add(myprod);
                    }
                    response.AddSpecificStoryList(list);

                    response.log.Add(numberOfRecords + " Records found");
                }
            }
            return(response);
        }
Esempio n. 5
0
        public response GetJakataMaster()
        {
            var dataTable = new System.Data.DataTable();

            dataTable = new System.Data.DataTable {
                TableName = "JakataMaster"
            };
            //var conString1 = ConfigurationManager.ConnectionStrings["LocalEvolution"];
            //string connString = conString1.ConnectionString;
            string connString = URLInfo.GetDataBaseConnectionString();


            System.IO.StringWriter writer = new System.IO.StringWriter();
            string   returnString         = "";
            response response             = new response();

            response.result = 0;
            using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connString))
            {
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetJakataMaster", con))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    con.Open();
                    var dataReader = cmd.ExecuteReader();
                    dataTable.Load(dataReader);
                    dataTable.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema, false);
                    returnString = writer.ToString();
                    int numberOfRecords = dataTable.Rows.Count;
                    response.result = numberOfRecords;



                    JakataMasterList list = new JakataMasterList();
                    foreach (System.Data.DataRow row in dataTable.Rows)
                    {
                        jakataMaster myprod = new jakataMaster();
                        myprod.ID    = row["ID"].ToString();
                        myprod.Title = row["Title"].ToString();


                        list.jakataMasterLists.Add(myprod);
                    }
                    response.AddJakataMasterList(list);

                    response.log.Add(numberOfRecords + " Records found");
                }
            }
            return(response);
        }
Esempio n. 6
0
        public response GetYouTube(int JakataID)
        {
            var dataTable = new System.Data.DataTable();

            dataTable = new System.Data.DataTable {
                TableName = "YouTube"
            };
            string connString = URLInfo.GetDataBaseConnectionString();

            System.IO.StringWriter writer = new System.IO.StringWriter();
            string   returnString         = "";
            response response             = new response();

            response.result = 0;
            using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connString))
            {
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetYouTube", con))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add("@JakataID", System.Data.SqlDbType.NVarChar).Value = JakataID;
                    con.Open();
                    var dataReader = cmd.ExecuteReader();
                    dataTable.Load(dataReader);
                    dataTable.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema, false);
                    returnString = writer.ToString();
                    int numberOfRecords = dataTable.Rows.Count;
                    response.result = numberOfRecords;



                    YouTubeList list = new YouTubeList();
                    foreach (System.Data.DataRow row in dataTable.Rows)
                    {
                        youTube myprod = new youTube();
                        myprod.ID       = row["ID"].ToString();
                        myprod.JakataID = row["JakataID"].ToString();
                        myprod.URL      = row["URL"].ToString();


                        list.youTubeLists.Add(myprod);
                    }
                    response.AddYouTubeList(list);

                    response.log.Add(numberOfRecords + " Records found");
                }
            }
            return(response);
        }
Esempio n. 7
0
        public static void WriteToXml(this System.Data.DataTable aDataTable, XmlNode aXmlNode)
        {
            if (aXmlNode == null || aDataTable == null)
            {
                return;
            }
            System.Text.StringBuilder aStringBuilder     = new System.Text.StringBuilder();
            XmlWriterSettings         aXmlWriterSettings = new XmlWriterSettings();

            aXmlWriterSettings.OmitXmlDeclaration = true;
            XmlWriter aXmlWriter = XmlWriter.Create(aStringBuilder, aXmlWriterSettings);

            aDataTable.WriteXml(aXmlWriter, System.Data.XmlWriteMode.WriteSchema);
            aXmlWriter.Close();
            aXmlNode.InnerText = aStringBuilder.ToString();
        }
Esempio n. 8
0
        public response GetStorySource()
        {
            var dataTable = new System.Data.DataTable();

            dataTable = new System.Data.DataTable {
                TableName = "StorySource"
            };
            string connString = URLInfo.GetDataBaseConnectionString();


            System.IO.StringWriter writer = new System.IO.StringWriter();
            string   returnString         = "";
            response response             = new response();

            response.result = 0;
            using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connString))
            {
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetStorySource", con))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    con.Open();
                    var dataReader = cmd.ExecuteReader();
                    dataTable.Load(dataReader);
                    dataTable.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema, false);
                    returnString = writer.ToString();
                    int numberOfRecords = dataTable.Rows.Count;
                    response.result = numberOfRecords;



                    StorySourceList list = new StorySourceList();
                    foreach (System.Data.DataRow row in dataTable.Rows)
                    {
                        storySource myprod = new storySource();
                        myprod.ID          = row["ID"].ToString();
                        myprod.StorySource = row["StorySource"].ToString();


                        list.storySourceLists.Add(myprod);
                    }
                    response.AddStorySourceList(list);

                    response.log.Add(numberOfRecords + " Records found");
                }
            }
            return(response);
        }
Esempio n. 9
0
 void CreateXml()
 {
     try
     {
         using (System.Data.DataTable dt = new System.Data.DataTable("manset"))
         {
             using (BAYMYO.UI.Web.CustomSqlQuery query = new BAYMYO.UI.Web.CustomSqlQuery(dt, "manset", "guncellemetarihi desc", "aktif=1"))
             {
                 query.Top = 25;
                 query.Execute();
                 dt.WriteXml(Server.MapPath(Settings.XmlPath + "manset.xml"), System.Data.XmlWriteMode.WriteSchema);
             }
         }
     }
     catch (Exception ex)
     {
         CustomizeControl1.MessageText = MessageBox.Show(DialogResult.Error, ex.Message);
     }
 }
Esempio n. 10
0
 void CreateXml()
 {
     try
     {
         using (System.Data.DataTable dt = new System.Data.DataTable("manset"))
         {
             using (BAYMYO.UI.Web.CustomSqlQuery query = new BAYMYO.UI.Web.CustomSqlQuery(dt, "manset", "kayittarihi desc", "aktif=1"))
             {
                 query.Top = 10;
                 query.Execute();
                 dt.WriteXml(Server.MapPath(Settings.XmlPath + "manset.xml"), System.Data.XmlWriteMode.WriteSchema);
             }
         }
     }
     catch (Exception ex)
     {
         pageNumberLiteral.Text = ex.Message;
     }
 }
Esempio n. 11
0
        public void TestListingBackupHeader()
        {
            DatabaseManager dbManager = new DatabaseManager();

            string connectionString = dbManager.GetConnectionString(".\\ADK", "master", "DIS", "Chin@soft!");

            Console.WriteLine(connectionString);

            System.Data.DataTable table = dbManager.GetBackupInformation("BackupDevice008", connectionString) as System.Data.DataTable;

            string result = "";

            using (System.IO.StringWriter writer = new System.IO.StringWriter())
            {
                table.WriteXml(writer, true);

                result = writer.ToString();
            }

            Console.WriteLine(result);
        }
Esempio n. 12
0
        } // End Function GetForeignKeyDependencies

        public void ExportKeyDependency()
        {
            System.Data.DataTable dt = GetForeignKeyDependencies();

            string strPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);

            strPath = System.IO.Path.Combine(strPath, "SRF_Export_sts");
            strPath = System.IO.Path.Combine(strPath, "DependencyOrder");
            if (!System.IO.Directory.Exists(strPath))
            {
                System.IO.Directory.CreateDirectory(strPath);
            }

            strPath = System.IO.Path.Combine(strPath, "Foreign_Key_Depencency_Order.xml");

            if (System.IO.File.Exists(strPath))
            {
                System.IO.File.Delete(strPath);
            }

            dt.WriteXml(strPath, System.Data.XmlWriteMode.WriteSchema, false);
        } // End Sub ExportKeyDependency
Esempio n. 13
0
        public static void exportTblScripts(DeviceFile.DeviceScripts[] fScripts, String filename)
        {
            DTBL tblScripts= new DTBL("Scripts");
            setupTblScripts( tblScripts);

            System.Data.DataRow myNewRow;

            for (int i = 0; i < fScripts.Length; i++)
            {
                myNewRow = tblScripts.NewRow();

                myNewRow["ScriptNumber"] = fScripts[i].ScriptNumber; //UInt16();
                myNewRow["ScriptName"] = fScripts[i].ScriptName; //String();
                myNewRow["ScriptVersion"] = fScripts[i].ScriptVersion; //UInt16();
                myNewRow["UNUSED1"] = fScripts[i].UNUSED1; //UInt32();
                myNewRow["ScriptLength"] = fScripts[i].ScriptLength; //UInt16();
                myNewRow["Script"] = fScripts[i].Script;  //Unit16[];
                myNewRow["Comment"] = fScripts[i].Comment; //String();

                tblScripts.Rows.Add(myNewRow);
            }

            tblScripts.WriteXml(filename, System.Data.XmlWriteMode.WriteSchema);
        }
Esempio n. 14
0
        public void StartLocating()
        {
            System.Data.DataTable dtStationCells = new System.Data.DataTable();

            //Create XML Datat for first time
            dtStationCells.TableName = "dt";
            dtStationCells.Columns.Add("Index", typeof(int));
            dtStationCells.Columns.Add("Name", typeof(string));
            dtStationCells.Columns.Add("Weight", typeof(double));
            dtStationCells.Columns.Add("Latitude", typeof(double));
            dtStationCells.Columns.Add("Longitude", typeof(double));
            dtStationCells.Columns.Add("RequestCount", typeof(int));

            MovementProbilityMatrix = new Matrix(NumberOfCells, NumberOfCells);

            Random rndi = new Random();
            //CreateShiraz Map Cells
            //29.5280603    29.57823449     29.72383715     29.69640358
            //52.55447388   52.62863159     52.47344971     52.40478516
            double latStart = 29.5280603, latEnd = 29.7238371, longStart = 52.4047851, longEnd = 52.6286315, currentLat = 0, currentLong = 0, latDistance = 0, longDistance = 0;

            currentLat   = latStart;
            currentLong  = longStart;
            longDistance = (longEnd - longStart) / 2;
            latDistance  = (latEnd - latStart) / (NumberOfCells / 2);
            for (int i = 0; i < NumberOfCells; i++)
            {
                int weight = rndi.Next(0, 100);
                //dtStationCells.Rows.Add(i, i.ToString(), weight, rndi.Next(295280603, 297238371) / (double)100000000, rndi.Next(524047851, 526286315) / (double)100000000, weight);
                dtStationCells.Rows.Add(i, i.ToString(), weight, currentLat, currentLong, weight);

                currentLat += latDistance;
                if (currentLat > latEnd)
                {
                    currentLat = latStart;
                }
                currentLong += longDistance;
                if (currentLong > longEnd)
                {
                    currentLong = longStart;
                }
            }
            dtStationCells.WriteXmlSchema(StationLocating.strRootResaultPath + "stationsSchema.xml");
            dtStationCells.WriteXml(StationLocating.strRootResaultPath + "stations.xml");

            //ReadPoints from Excel
            //Microsoft.Office.Interop.Excel.Application xlApp1 = new Microsoft.Office.Interop.Excel.Application();
            //Microsoft.Office.Interop.Excel.Workbook xlWorkBook1 = xlApp1.Workbooks.Open(Application.StartupPath + "\\Neighborhood_Labels.xls");
            //Microsoft.Office.Interop.Excel.Worksheet xlSheet1 = xlWorkBook1.Sheets[1];
            //Microsoft.Office.Interop.Excel.Range xlRange = xlSheet1.UsedRange;
            //NumberOfCells = xlRange.Rows.Count;
            //for (int i = 2; i <= xlRange.Rows.Count; i++)
            //{
            //    if (xlRange.Cells[i, 1] != null && xlRange.Cells[i, 1].Value2 != null)
            //        dtStationCells.Rows.Add(xlRange.Cells[i, 3].Value2, rndi.Next(0, 100), Convert.ToDouble(xlRange.Cells[i, 2].Value2), Convert.ToDouble(xlRange.Cells[i, 1].Value2));
            //}
            //dtStationCells.WriteXmlSchema(@"c:\stationsSchema.xml");
            //dtStationCells.WriteXml(@"c:\stations.xml");

            //Create Movement Probility Matrix and Save it
            MovementProbilityMatrix.FillMatrixWithEqalTotal();
            //MovementProbilityMatrix.PrintMatrix();
            //MovementProbilityMatrix.SaveMarixToJson("c:\\MovementProbilityMatrix.json");

            // read Movement Probility Matrix from file
            //MovementProbilityMatrix.ReadMatrixFromJson("c:\\MovementProbilityMatrix.json");


            //Read stations data from XML file
            //dtStationCells = new System.Data.DataTable();
            //dtStationCells.ReadXmlSchema(@"c:\stationsSchema.xml");
            //dtStationCells.ReadXml(@"c:\stations.xml");


            StationCells = new List <BikeSharingStations.StationCell>();

            for (int i = 0; i < dtStationCells.Rows.Count; i++)
            {
                StationCells.Add(new StationCell(Convert.ToInt32(dtStationCells.Rows[i]["Index"]), dtStationCells.Rows[i]["Name"].ToString(), (double)dtStationCells.Rows[i]["Weight"], (double)dtStationCells.Rows[i]["Latitude"], (double)dtStationCells.Rows[i]["Longitude"], Convert.ToInt32(dtStationCells.Rows[i]["RequestCount"])));
            }



            foreach (StationCell item in StationCells)
            {
                SumOfStationWeights += item.Weight;
            }

            const double crossoverProbability = 0.65;
            const double mutationProbability  = 0.08;
            const int    elitismPercentage    = 5;


            Microsoft.Office.Interop.Excel.Application xlApp      = new Microsoft.Office.Interop.Excel.Application();;
            Microsoft.Office.Interop.Excel.Workbook    xlWorkBook = xlApp.Workbooks.Open(StationLocating.strRootResaultPath + "StationsData2.xls");;
            object misValue = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Excel.Worksheet xlSheetFinalData = xlWorkBook.Sheets[1];

            for (RoundCount = 1; RoundCount <= 20; RoundCount++)
            {
                //create the population
                var    population   = new Population();//NumberOfChoromosomes, NumberOfCells, false, false);
                Random rndGeneIndex = new Random();
                Random rnd          = new Random();
                //create the chromosomes;
                for (var p = 0; p < NumberOfChoromosomes; p++)
                {
                    var chromosome = new Chromosome();
                    int NumberOfBikesInThisChoromosome = 0;
                    for (var g = 0; g < NumberOfCells; g++)
                    {
                        chromosome.Genes.Add(new Gene(0));
                    }

                    //int geneIndex = 0;
                    while (NumberOfBikesInThisChoromosome < MaximumNumberOfBikesInSystem)
                    {
                        int temp = rnd.Next(MaximumNumberOfbikeInEachStation / 2, MaximumNumberOfbikeInEachStation);
                        if (NumberOfBikesInThisChoromosome + temp > MaximumNumberOfBikesInSystem)
                        {
                            temp = MaximumNumberOfBikesInSystem - NumberOfBikesInThisChoromosome;
                        }
                        NumberOfBikesInThisChoromosome += temp;
                        chromosome.Genes[rndGeneIndex.Next(0, NumberOfCells)] = new Gene(temp);
                        //chromosome.Genes.Add(new Gene(temp));
                        //geneIndex++;
                    }
                    //chromosome.Genes.ShuffleFast();

                    int sumBikes = 0;
                    for (int i = 0; i < chromosome.Count; i++)
                    {
                        sumBikes += Convert.ToInt32(chromosome.Genes[i].RealValue);
                    }
                    if (sumBikes > MaximumNumberOfBikesInSystem)
                    {
                        sumBikes = 0;
                    }
                    population.Solutions.Add(chromosome);
                }


                //create the chromosomes;
                //for (var p = 0; p < NumberOfChoromosomes; p++)
                //{
                //    var chromosome = new Chromosome();
                //    for (var g = 0; g < NumberOfCells; g++)
                //    {
                //        chromosome.Genes.Add(new Gene(rnd.Next(0, MaximumNumberOfbikeInEachStation)));
                //    }
                //    chromosome.Genes.ShuffleFast();
                //    population.Solutions.Add(chromosome);
                //}

                //create the genetic operators
                var elite = new Elite(elitismPercentage);


                //create the crossover operator
                var crossover = new Crossover(crossoverProbability, true)
                {
                    CrossoverType = CrossoverType.SinglePoint
                };
                //crossover.ReplacementMethod = ReplacementMethod.DeleteLast;

                var mutation = new BinaryMutate(mutationProbability, true);

                //create the GA itself
                var ga = new GeneticAlgorithm(population, EvaluateFitness);

                //subscribe to the GAs Generation Complete event
                ga.OnGenerationComplete += ga_OnGenerationComplete;
                //add the operators to the ga process pipeline
                ga.Operators.Add(elite);
                ga.Operators.Add(crossover);
                ga.Operators.Add(mutation);

                //run the GA
                ga.Run(TerminateAlgorithm);

                Console.WriteLine("intFitnessCount : " + intFitnessCount.ToString());
                Console.WriteLine("intWrongFitnessCount : " + intWrongFitnessCount.ToString());
                //Export Resault to excel
                Microsoft.Office.Interop.Excel.Worksheet xlStationsDataSheet;
                xlWorkBook.Worksheets.Add();
                xlStationsDataSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                int excelColumnIndex = 1;
                xlStationsDataSheet.Name = string.Format("Round{0:00}", RoundCount);
                xlStationsDataSheet.Cells[1, excelColumnIndex] = "CellIndex";                       // Index
                xlStationsDataSheet.Cells[2, excelColumnIndex] = "StationName";                     // Name
                xlStationsDataSheet.Cells[3, excelColumnIndex] = "Latitude";                        // Latitude
                xlStationsDataSheet.Cells[4, excelColumnIndex] = "Longitude";                       // Longitude
                xlStationsDataSheet.Cells[5, excelColumnIndex] = "Weight";                          // Weight
                xlStationsDataSheet.Cells[6, excelColumnIndex] = "NumberOfBikes";                   // NumberOfBikes
                xlStationsDataSheet.Cells[7, excelColumnIndex] = "Station capacity";                // Station capacity
                xlStationsDataSheet.Cells[8, excelColumnIndex] = "Total Distance";                  // Avrage Of Accessibility
                xlStationsDataSheet.Cells[9, excelColumnIndex] = "Number of Bikes for Rebalancing"; // Number of Bikes for Rebalancing


                excelColumnIndex += 1;

                var Topchromosome = population.Solutions[0];
                ComputeAccessibility(Topchromosome);
                ComputeRebalancingCost(Topchromosome);
                SaveProbilityMartix(string.Format(StationLocating.strRootResaultPath + "ProbibilityMatrix-Round{0:00}.json", RoundCount), Topchromosome);
                double totalbikeinthissystem = 0;
                for (int i = 0; i < Topchromosome.Count; i++)
                {
                    if (Topchromosome.Genes[i].RealValue != 0)
                    {
                        xlStationsDataSheet.Cells[1, excelColumnIndex] = StationCells[i].Index;            // Index
                        xlStationsDataSheet.Cells[2, excelColumnIndex] = StationCells[i].Name;             // Name
                        xlStationsDataSheet.Cells[3, excelColumnIndex] = StationCells[i].Latitude;         // Latitude
                        xlStationsDataSheet.Cells[4, excelColumnIndex] = StationCells[i].Longitude;        // Longitude
                        xlStationsDataSheet.Cells[5, excelColumnIndex] = StationCells[i].Weight;           // Weight
                        xlStationsDataSheet.Cells[6, excelColumnIndex] = StationCells[i].NumberOfBikes;    // NumberOfBikes
                        xlStationsDataSheet.Cells[7, excelColumnIndex] = Topchromosome.Genes[i].RealValue; // Station capacity
                        xlStationsDataSheet.Cells[8, excelColumnIndex] = TotalDistance;                    // Avrage Of Accessibility
                        xlStationsDataSheet.Cells[9, excelColumnIndex] = NumberOfBikesToBeRebalance;       // Number of Bikes for Rebalancing
                        totalbikeinthissystem += Topchromosome.Genes[i].RealValue;
                        excelColumnIndex++;
                    }
                }

                xlSheetFinalData.Cells[1, 1] = "Round Count";
                xlSheetFinalData.Cells[1, 2] = "TotalDistance";
                xlSheetFinalData.Cells[1, 3] = "NumberOfBikesToBeRebalance";
                xlSheetFinalData.Cells[1, 4] = "Number of Bikes in system";
                xlSheetFinalData.Cells[1, 5] = "Number of stations";
                xlSheetFinalData.Cells[1, 6] = "Rebalancing is Computed";
                xlSheetFinalData.Cells[1, 7] = "fitnessValue";
                xlSheetFinalData.Cells[1, 8] = "AccessibilityFitness";
                xlSheetFinalData.Cells[1, 9] = "RebalancingFitness";

                xlSheetFinalData.Cells[RoundCount + 1, 1] = RoundCount;
                xlSheetFinalData.Cells[RoundCount + 1, 2] = TotalDistance;
                xlSheetFinalData.Cells[RoundCount + 1, 3] = NumberOfBikesToBeRebalance;                    // Number of Bikes for Rebalancing
                xlSheetFinalData.Cells[RoundCount + 1, 4] = totalbikeinthissystem;                         // Number of Bikes in system
                xlSheetFinalData.Cells[RoundCount + 1, 5] = excelColumnIndex - 2;                          // Number of stations
                xlSheetFinalData.Cells[RoundCount + 1, 6] = (RoundCount % 2 == 0) ? "True" : "False";
                xlSheetFinalData.Cells[RoundCount + 1, 7] = fitnessValue;                                  // Number of Bikes for Rebalancing
                xlSheetFinalData.Cells[RoundCount + 1, 8] = AccessibilityFitness;                          // Number of Bikes for Rebalancing
                xlSheetFinalData.Cells[RoundCount + 1, 9] = (RoundCount % 2 == 0)? RebalancingFitness : 0; // Number of Bikes for Rebalancing

                releaseObject(xlStationsDataSheet);

                xlWorkBook.Save();

                //xlWorkBook.SaveAs(string.Format("c:\\StationsData.xls"), Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            }

            xlWorkBook.SaveAs(string.Format(StationLocating.strRootResaultPath + "StationsData.xls"), Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

            releaseObject(xlSheetFinalData);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();

            MessageBox.Show("Excel file created , you can find the file " + StationLocating.strRootResaultPath);
        }
Esempio n. 15
0
        public static void DataToXML()
        {
            string table_schema = "geoip";
            string table_name   = "geoip_blocks_temp";

            table_schema = "public";
            table_name   = "t_sys_language_monthnames";


            using (System.Data.DataTable dt = new System.Data.DataTable())
            {
                dt.TableName = "record";

                using (System.Data.DataSet ds = new System.Data.DataSet(table_name))
                {
                    ds.Tables.Add(dt);
                    // dt.Namespace = "foo";

                    using (System.Data.Common.DbConnection con = Npgsql.NpgsqlFactory.Instance.CreateConnection())
                    {
                        con.ConnectionString = GetCS();

                        using (System.Data.Common.DbCommand cmd = con.CreateCommand())
                        {
                            cmd.CommandText = "SELECT * FROM " + table_schema + "." + table_name;

                            using (System.Data.Common.DbDataAdapter da = Npgsql.NpgsqlFactory.Instance.CreateDataAdapter())
                            {
                                da.SelectCommand = cmd;

                                if (con.State != System.Data.ConnectionState.Open)
                                {
                                    con.Open();
                                }

                                da.Fill(dt);

                                if (con.State != System.Data.ConnectionState.Open)
                                {
                                    con.Close();
                                }
                            } // End Using da
                        }     // End Using cmd
                    }         // End Using con

                    string exportFilename = System.IO.Path.Combine(@"d:\", table_name + ".xml");


                    //using (System.IO.Stream fs = System.IO.File.OpenWrite(exportFilename))
                    //{
                    //    using (System.IO.TextWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.UTF8))
                    //    {
                    //        // System.IO.StringWriter sw = new System.IO.StringWriter();
                    //        // dt.WriteXml(sw, System.Data.XmlWriteMode.IgnoreSchema);
                    //        dt.WriteXml(sw, System.Data.XmlWriteMode.IgnoreSchema);
                    //    } // End Using sw

                    //} // End Using fs


                    System.Xml.XmlWriterSettings xs = new System.Xml.XmlWriterSettings();
                    xs.Indent             = true;
                    xs.IndentChars        = "    ";
                    xs.NewLineChars       = System.Environment.NewLine;
                    xs.OmitXmlDeclaration = false;
                    // xs.Encoding = System.Text.Encoding.UTF8; // doesn't work with pgsql
                    xs.Encoding = new System.Text.UTF8Encoding(false);

                    // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                    using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(exportFilename, xs))
                    {
                        dt.WriteXml(writer, System.Data.XmlWriteMode.IgnoreSchema);
                    } // End Using writer

                    System.Console.WriteLine(dt.Rows.Count);
                } // End Using ds
            }     // End Using dt
        }         // End Sub DataToXML
Esempio n. 16
0
        public response GetSpecificStoryDropdownStatus(int ID)
        {
            var dataTable = new System.Data.DataTable();

            dataTable = new System.Data.DataTable {
                TableName = "JakataMaster"
            };
            string connString = URLInfo.GetDataBaseConnectionString();


            System.IO.StringWriter writer = new System.IO.StringWriter();
            string   returnString         = "";
            response response             = new response();

            response.result = 0;
            using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connString))
            {
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetSpecificStoryDropdownStatus", con))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add("@StoryImported", System.Data.SqlDbType.NVarChar).Value = ID;
                    con.Open();
                    var dataReader = cmd.ExecuteReader();
                    dataTable.Load(dataReader);
                    dataTable.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema, false);
                    returnString = writer.ToString();
                    int numberOfRecords = dataTable.Rows.Count;
                    response.result = numberOfRecords;

                    //JakataMasterList list = new JakataMasterList();
                    //foreach (DataRow row in dataTable.Rows)
                    //{
                    //    jakataMaster myprod = new jakataMaster();
                    //    myprod.ID = row["JakataID"].ToString();
                    //    myprod.Title = row["Title"].ToString();


                    //    list.jakataMasterLists.Add(myprod);
                    //}


                    ToDoList list = new ToDoList();
                    foreach (System.Data.DataRow row in dataTable.Rows)
                    {
                        toDo myprod = new toDo();
                        myprod.ID    = row["JakataID"].ToString();
                        myprod.Title = row["Title"].ToString();


                        list.toDoLists.Add(myprod);
                    }
                    //response.AddJakataMasterList(list);
                    response.AddToDoList(list);
                    //response.AddToDoList(list);



                    response.log.Add(numberOfRecords + " Records found");
                }
            }
            return(response);
        }
Esempio n. 17
0
        /// <summary>
        /// 保存地图文档
        /// </summary>
        public void Save()
        {
            //首先确认当前地图文档是否有效
            if (m_MapControl.CheckMxFile(m_MapControl.DocumentFilename))
            {
                ////创建一个新的地图文档实例
                //IMapDocument mapDoc = new MapDocument();
                ////打开当前地图文档
                //mapDoc.Open(m_MapControl.DocumentFilename, string.Empty);

                ////判断地图数据是否只读
                //if (mapDoc.get_IsReadOnly(m_MapControl.DocumentFilename))
                //{
                //    MessageBox.Show("地图文档只读,不能加载!");
                //    mapDoc.Close();
                //    return;
                //}

                ////替换地图目录
                //mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map);

                ////保存地图文档
                //mapDoc.Save(mapDoc.UsesRelativePaths,true);
                //mapDoc.Close();

                System.Data.DataTable dt = new System.Data.DataTable("GIS");
                dt.Columns.Add("name");
                dt.Columns.Add("value");
                dt.Columns.Add("params");
                System.Data.DataRow dr = dt.NewRow();
                string extent = Math.Round(m_MapControl.Extent.XMax, 2).ToString() + "," + Math.Round(m_MapControl.Extent.XMin, 2).ToString() + "," + Math.Round(m_MapControl.Extent.YMax, 2).ToString() + "," + Math.Round(m_MapControl.Extent.YMin, 2).ToString();
                dr = dt.NewRow();
                dr[0] = "extent";
                dr[1] = extent;
                dt.Rows.Add(dr);
                string Scale = Math.Round(m_MapControl.MapScale,0).ToString();
                dr = dt.NewRow();
                dr[0] = "Scale";
                dr[1] = Scale;
                dt.Rows.Add(dr);
                string ckScale = Math.Round(m_MapControl.ReferenceScale,0).ToString();
                dr = dt.NewRow();
                dr[0] = "ckScale";
                dr[1] = ckScale;
                dt.Rows.Add(dr);
                string Rotation = Math.Round(m_MapControl.Rotation,0).ToString();
                dr = dt.NewRow();
                dr[0] = "Rotation";
                dr[1] = Rotation;
                dt.Rows.Add(dr);
                for (int i = 0; i < m_MapControl.LayerCount; i++)
                {
                    ILayer player = m_MapControl.get_Layer(i);
                    if (player is IGroupLayer)
                    {
                        dr = dt.NewRow();
                        dr[0] = "layer";
                        dr[1] = player.Name;
                        dr[2] = player.Visible.ToString();
                        dt.Rows.Add(dr);
                        setgisxml(ref dt,player as IGroupLayer);
                    }
                    else
                    {
                        dr = dt.NewRow();
                        dr[0] = "layer";
                        dr[1] = player.Name;
                        dr[2] = player.Visible.ToString();
                        dt.Rows.Add(dr);
                    }
                }
                dt.WriteXml(Application.StartupPath + @"\gis.xml");
            }
            //else
            //    this.SaveAs();//新建后m_MapControl.DocumentFilename为空,故调用另存为进行保存
        }
Esempio n. 18
0
        //public response GetSpecificStory(Story myStoryies)
        public String GetSpecificStory(Story myStoryies)
        {
            var dataTable = new System.Data.DataTable();

            dataTable = new System.Data.DataTable {
                TableName = "Stories"
            };
            string connString = URLInfo.GetDataBaseConnectionString();

            System.IO.StringWriter writer = new System.IO.StringWriter();
            string   returnString         = "";
            response response             = new response();

            response.result = 0;
            string resultstring = "";

            SpecificStoryList list = new SpecificStoryList();



            using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connString))
            {
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetSearchStory", con))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;



                    //cmd.Add("@JakataID", myStory.JakataID);
                    //cmd.Add("@StoryCategorytName", 1);
                    //cmd.Add("@Title", myStory.Title);
                    //cmd.Add("@AnimalType", myStory.AnimalType);


                    if (myStoryies.Title > 0)
                    {
                        cmd.Parameters.Add("@Title", System.Data.SqlDbType.NVarChar).Value = myStoryies.Title;
                    }

                    if (myStoryies.JakataID > 0)
                    {
                        cmd.Parameters.Add("@JakataID", System.Data.SqlDbType.Int).Value = myStoryies.JakataID;
                    }

                    if (myStoryies.AnimalType != "0")
                    {
                        cmd.Parameters.Add("@AnimalType", System.Data.SqlDbType.NVarChar).Value = myStoryies.AnimalType;
                    }

                    if (myStoryies.MoralType > 0)
                    {
                        cmd.Parameters.Add("@MoralType", System.Data.SqlDbType.Int).Value = myStoryies.MoralType;
                    }

                    if (myStoryies.Comments != "0")
                    {
                        cmd.Parameters.Add("@Comments", System.Data.SqlDbType.NVarChar).Value = myStoryies.Comments;
                    }

                    if (myStoryies.Stories != "0")
                    {
                        cmd.Parameters.Add("@Stories", System.Data.SqlDbType.NVarChar).Value = myStoryies.Stories;
                    }


                    con.Open();
                    var dataReader = cmd.ExecuteReader();
                    dataTable.Load(dataReader);
                    dataTable.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema, false);
                    returnString = writer.ToString();

                    //return returnString;
                    int numberOfRecords = dataTable.Rows.Count;
                    response.result = numberOfRecords;



                    //SpecificStoryList list = new SpecificStoryList();
                    foreach (System.Data.DataRow row in dataTable.Rows)
                    {
                        //specificStory myprod = new specificStory();
                        resultstring = resultstring + row["ID"].ToString() + "|";


                        //list.specificStory.Add(myprod);
                    }
                    //response.AddSpecificStoryList(list);

                    //response.log.Add(numberOfRecords + " Records found");
                }
            }

            //return list;
            return(resultstring);
            //return response;
        }
Esempio n. 19
0
        /// <summary>
        /// 保存地图文档
        /// </summary>
        public void Save()
        {
            //首先确认当前地图文档是否有效
            if (m_MapControl.CheckMxFile(m_MapControl.DocumentFilename))
            {
                ////创建一个新的地图文档实例
                //IMapDocument mapDoc = new MapDocument();
                ////打开当前地图文档
                //mapDoc.Open(m_MapControl.DocumentFilename, string.Empty);

                ////判断地图数据是否只读
                //if (mapDoc.get_IsReadOnly(m_MapControl.DocumentFilename))
                //{
                //    MessageBox.Show("地图文档只读,不能加载!");
                //    mapDoc.Close();
                //    return;
                //}

                ////替换地图目录
                //mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map);

                ////保存地图文档
                //mapDoc.Save(mapDoc.UsesRelativePaths,true);
                //mapDoc.Close();


                System.Data.DataTable dt = new System.Data.DataTable("GIS");
                dt.Columns.Add("name");
                dt.Columns.Add("value");
                dt.Columns.Add("params");
                System.Data.DataRow dr = dt.NewRow();
                string extent          = Math.Round(m_MapControl.Extent.XMax, 2).ToString() + "," + Math.Round(m_MapControl.Extent.XMin, 2).ToString() + "," + Math.Round(m_MapControl.Extent.YMax, 2).ToString() + "," + Math.Round(m_MapControl.Extent.YMin, 2).ToString();
                dr    = dt.NewRow();
                dr[0] = "extent";
                dr[1] = extent;
                dt.Rows.Add(dr);
                string Scale = Math.Round(m_MapControl.MapScale, 0).ToString();
                dr    = dt.NewRow();
                dr[0] = "Scale";
                dr[1] = Scale;
                dt.Rows.Add(dr);
                string ckScale = Math.Round(m_MapControl.ReferenceScale, 0).ToString();
                dr    = dt.NewRow();
                dr[0] = "ckScale";
                dr[1] = ckScale;
                dt.Rows.Add(dr);
                string Rotation = Math.Round(m_MapControl.Rotation, 0).ToString();
                dr    = dt.NewRow();
                dr[0] = "Rotation";
                dr[1] = Rotation;
                dt.Rows.Add(dr);
                for (int i = 0; i < m_MapControl.LayerCount; i++)
                {
                    ILayer player = m_MapControl.get_Layer(i);
                    if (player is IGroupLayer)
                    {
                        dr    = dt.NewRow();
                        dr[0] = "layer";
                        dr[1] = player.Name;
                        dr[2] = player.Visible.ToString();
                        dt.Rows.Add(dr);
                        setgisxml(ref dt, player as IGroupLayer);
                    }
                    else
                    {
                        dr    = dt.NewRow();
                        dr[0] = "layer";
                        dr[1] = player.Name;
                        dr[2] = player.Visible.ToString();
                        dt.Rows.Add(dr);
                    }
                }
                dt.WriteXml(Application.StartupPath + @"\gis.xml");
            }
            //else
            //    this.SaveAs();//新建后m_MapControl.DocumentFilename为空,故调用另存为进行保存
        }