Пример #1
0
        } // End Sub ExportDatabase

        public override void ImportTableData()
        {
            string strBasePath = @"D:\Stefan.Steiger\Desktop\ValidationResults\SRGSSRReis_Export_sts";

            System.Data.DataTable dtTableInOrder = new System.Data.DataTable();
            dtTableInOrder.ReadXml(strBasePath = System.IO.Path.Combine(System.IO.Path.Combine(strBasePath, "DependencyOrder"), "Foreign_Key_Depencency_Order.xml"));

            foreach (System.Data.DataRow dr in dtTableInOrder.Rows)
            {
                string strDestTable = System.Convert.ToString(dr["TableName"]);
                System.Console.WriteLine(strDestTable);
                string strPath = System.IO.Path.Combine(strBasePath, "Tables");
                strPath = System.IO.Path.Combine(strPath, strDestTable + ".xml");

                System.Console.WriteLine(strPath);

                System.Data.DataTable dt = new System.Data.DataTable();
                dt.ReadXml(strPath);
                BulkCopy(strDestTable, dt);

                dt.Clear();
                dt.Dispose();
            } // Next dr


            dtTableInOrder.Clear();
            dtTableInOrder.Dispose();
        } // End Sub ImportTableData
Пример #2
0
 /// <summary>
 /// 获取表类型配置
 /// </summary>
 /// <param name="ClassName">类名</param>
 /// <param name="TableElementName">表元素名</param>
 /// <returns></returns>
 public System.Data.DataTable GetTableConfig(string ClassName, string TableElementName)
 {
     if (xn != null)
     {
         System.Xml.XmlNode xn1 = xn.SelectSingleNode(ClassName + "/" + TableElementName);
         if (xn1 != null)
         {
             System.Data.DataTable dt = new System.Data.DataTable(TableElementName);
             StringReader          sr = new StringReader(xn1.InnerXml);
             System.Xml.XmlReader  xr = System.Xml.XmlReader.Create(sr);
             dt.ReadXml(xr);
             return(dt);
         }
     }
     return(null);
 }
Пример #3
0
        public static void ReadFromXml(this System.Data.DataTable aDataTable, XmlNode aXmlNode)
        {
            if (aDataTable == null)
            {
                return;
            }
            aDataTable.Clear();
            if (aXmlNode == null)
            {
                return;
            }
            System.IO.StringReader aStringReader = new System.IO.StringReader(aXmlNode.InnerText);
            XmlReader aXmlReader = XmlReader.Create(aStringReader);

            aDataTable.ReadXml(aXmlReader);
        }
Пример #4
0
 public static System.Data.DataTable ConvertXMLFileToDataSet(string xmlData)
 {
     System.Xml.XmlTextReader reader = null;
     try {
         System.Data.DataTable xmlDS = new System.Data.DataTable();
         reader = new System.Xml.XmlTextReader(new System.IO.StringReader(xmlData));
         xmlDS.ReadXml(reader);
         return(xmlDS);
     } catch (System.Exception ex) {
         throw ex;
     } finally {
         if (reader != null)
         {
             reader.Close();
         }
     }
 }
Пример #5
0
        public static int Main(string[] args)
        {
            if (args == null)
            {
                return(-1);
            }
            if (args.Length < 2)
            {
                return(-1);
            }

            string tmpPath     = args[0];
            string printerPath = args[1];

            if (System.IO.Directory.Exists(tmpPath) == false)
            {
                return(-1);
            }

            if (string.IsNullOrEmpty(printerPath))
            {
                return(-1);
            }

            //string tmpPath = @"C:\TempDev";
            //string printerPath = @"CR_FX DocuCentre-II C2200 PCL 6";

            Utils.TEMP_PATH = tmpPath;

            string rpath = System.IO.Path.Combine(tmpPath, "Report");

            if (System.IO.Directory.Exists(rpath) == false)
            {
                System.IO.Directory.CreateDirectory(rpath);
            }

            rpath = System.IO.Path.Combine(rpath, printerPath);
            if (System.IO.Directory.Exists(rpath) == false)
            {
                return(-1);
            }

            string rrpath = System.IO.Path.Combine(rpath, "Result");

            if (System.IO.Directory.Exists(rrpath) == false)
            {
                System.IO.Directory.CreateDirectory(rrpath);
            }
            string rtpath = System.IO.Path.Combine(rpath, "Temp");

            if (System.IO.Directory.Exists(rtpath) == false)
            {
                System.IO.Directory.CreateDirectory(rtpath);
            }
            string repath = System.IO.Path.Combine(rpath, "Error");

            if (System.IO.Directory.Exists(repath) == false)
            {
                System.IO.Directory.CreateDirectory(repath);
            }

            try
            {
                foreach (System.IO.FileInfo fi in new System.IO.DirectoryInfo(rrpath).GetFiles())
                {
                    if (fi.LastAccessTime < DateTime.Now.AddMonths(-3))
                    {
                        fi.Delete();
                    }
                }
                foreach (System.IO.FileInfo fi in new System.IO.DirectoryInfo(rtpath).GetFiles())
                {
                    if (fi.LastAccessTime < DateTime.Now.AddMonths(-3))
                    {
                        fi.Delete();
                    }
                }
                foreach (System.IO.FileInfo fi in new System.IO.DirectoryInfo(repath).GetFiles())
                {
                    if (fi.LastAccessTime < DateTime.Now.AddMonths(-3))
                    {
                        fi.Delete();
                    }
                }
            }
            catch
            {
            }


            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(rpath);
            System.IO.FileInfo[]    fs  = dir.GetFiles().OrderBy(x => x.CreationTime).ToArray();
            while (fs.Length > 0)
            {
                System.IO.FileInfo f = fs[0];

                try
                {
                    using (CrystalReportGenerator rpt = new CrystalReportGenerator())
                    {
                        ReportInfo rInfo = null;
                        using (System.IO.StreamReader rd = new System.IO.StreamReader(f.FullName))
                        {
                            rInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <ReportInfo>(rd.ReadLine());
                            rpt.LoadReport(rInfo.TemplatePath);

                            string txt = rd.ReadLine();
                            while (txt != null && txt != "")
                            {
                                string[] sp = txt.Split(";".ToCharArray());
                                if (sp.Length > 0)
                                {
                                    if (sp[0] == "PARAM" && sp.Length >= 2)
                                    {
                                        string data = "";
                                        for (int idx = 1; idx < sp.Length; idx++)
                                        {
                                            if (idx > 1)
                                            {
                                                data += ";";
                                            }
                                            data += sp[idx];
                                        }

                                        ReportParameter p = Newtonsoft.Json.JsonConvert.DeserializeObject <ReportParameter>(data);
                                        if (p != null)
                                        {
                                            rpt.SetParameter(p.Name, p.Value);
                                        }
                                    }
                                    else if (sp[0] == "SOURCE" && sp.Length >= 3)
                                    {
                                        string name = sp[1];

                                        string data = "";
                                        for (int idx = 2; idx < sp.Length; idx++)
                                        {
                                            if (idx > 2)
                                            {
                                                data += ";";
                                            }
                                            data += sp[idx];
                                        }

                                        System.Data.DataTable table = new System.Data.DataTable(name);
                                        using (System.IO.StringReader srd = new System.IO.StringReader(data))
                                        {
                                            table.ReadXml(srd);
                                        }

                                        rpt.SetDataSource(name, table);
                                    }
                                    else if (sp[0] == "SUBSOURCE" && sp.Length >= 4)
                                    {
                                        string sname = sp[1];
                                        string name  = sp[2];

                                        string data = "";
                                        for (int idx = 3; idx < sp.Length; idx++)
                                        {
                                            if (idx > 3)
                                            {
                                                data += ";";
                                            }
                                            data += sp[idx];
                                        }

                                        System.Data.DataTable table = new System.Data.DataTable(name);
                                        using (System.IO.StringReader srd = new System.IO.StringReader(data))
                                        {
                                            table.ReadXml(srd);
                                        }

                                        rpt.SetSubReportDataSource(sname, name, table);
                                    }
                                }

                                txt = rd.ReadLine();
                            }
                        }

                        string           output = null;
                        ReportOutputType type   = (ReportOutputType)rInfo.OutputType;
                        if (type == ReportOutputType.PRINTER)
                        {
                            if (rInfo.PrintCopy == 0)
                            {
                                rInfo.PrintCopy = 1;
                            }

                            rpt.Print(rInfo.PrinterName, rInfo.PrintCopy, rInfo.PrinterPaperSource);
                        }
                        else
                        {
                            output = rpt.Export(rInfo.OutputFileName, type);

                            string rrfpath = System.IO.Path.Combine(rrpath, f.Name);
                            using (System.IO.StreamWriter wr = new System.IO.StreamWriter(rrfpath, true))
                            {
                                wr.WriteLine(output);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utils.WriteLog(ex);
                }

                int count = 0;
                while (count < 10)
                {
                    try
                    {
                        string dest = System.IO.Path.Combine(rtpath, f.Name);
                        if (System.IO.File.Exists(dest))
                        {
                            System.IO.File.Delete(dest);
                        }

                        f.MoveTo(dest);
                        break;
                    }
                    catch (Exception ex)
                    {
                        Utils.WriteLog(ex);

                        count++;
                        System.Threading.Thread.Sleep(1000);
                    }
                }

                fs = dir.GetFiles().OrderBy(x => x.CreationTime).ToArray();
            }

            return(0);
        }
Пример #6
0
        public void StartSimulation()
        {
            try
            {
                for (int RoundCount = 1; RoundCount <= 20; RoundCount++)
                {
                    TotalDistanceOfUserWalk      = 0;
                    TotalDistanceOfBikeRides     = 0;;
                    AvailableBikesInTruck        = 0;
                    TotoalNumberOfbikesForPickup = 0;
                    EventID    = 1;
                    GlobalTime = 0;

                    ReadData(RoundCount);

                    List <FutureEvent> FutureEventList = new List <FutureEvent>();
                    int MissRequestCount = 0;
                    int HitRequestCount  = 0;
                    int RebalancingCount = 0;
                    // For each cell in the list creat events and add new events to the FutureEventList
                    //Read stations data from XML file
                    System.Data.DataTable dtStationCells = new System.Data.DataTable();
                    dtStationCells.ReadXmlSchema(StationLocating.strRootResaultPath + "stationsSchema.xml");
                    dtStationCells.ReadXml(StationLocating.strRootResaultPath + "stations.xml");

                    double total1 = 0;

                    foreach (System.Data.DataRow dr in dtStationCells.Rows)
                    {
                        double neareststationDistance;
                        int    neareststationindex = FindNearestStation(Convert.ToDouble(dr["Latitude"]), Convert.ToDouble(dr["Longitude"]), out neareststationDistance);
                        StationList[neareststationindex].Weight      += Convert.ToDouble(dr["Weight"]) * neareststationDistance;
                        StationList[neareststationindex].totalWeight += Convert.ToDouble(dr["Weight"]);
                        StationList[neareststationindex].RequestCount++;
                    }

                    foreach (System.Data.DataRow dr in dtStationCells.Rows)
                    {
                        double neareststationDistance;
                        int    neareststationindex = FindNearestStation(Convert.ToDouble(dr["Latitude"]), Convert.ToDouble(dr["Longitude"]), out neareststationDistance);
                        StationList[neareststationindex].Weight      += Convert.ToDouble(dr["Weight"]) * neareststationDistance;
                        StationList[neareststationindex].totalWeight += Convert.ToDouble(dr["Weight"]);
                        StationList[neareststationindex].RequestCount++;
                    }

                    foreach (var item in StationList)
                    {
                        item.Weight = item.Weight / item.totalWeight;
                        Console.WriteLine(string.Format("Station Index : {0}  Weight : {1}  Request : {2}", item.Index, item.Weight, item.RequestCount));
                        item.RequestCount = 0;
                    }

                    Console.WriteLine("--------------------------------------------------*");

                    PrintStationStatus();

                    foreach (System.Data.DataRow dr in dtStationCells.Rows)
                    {
                        Troschuetz.Random.Distributions.Discrete.PoissonDistribution rnd = new Troschuetz.Random.Distributions.Discrete.PoissonDistribution();
                        rnd.Lambda = 100 - Convert.ToDouble(dr["Weight"]);
                        int t = 0;
                        while (t < 1440) // OneDay = 1440 minute
                        {
                            t += rnd.Next() * 5;
                            FutureEventList.Add(new FutureEvent(EventID++, t, EventType.CustomerRequest, Convert.ToDouble(dr["Latitude"]), Convert.ToDouble(dr["Longitude"])));
                        }
                    }



                    //for (int GlobalTime = 0; GlobalTime < 1440; GlobalTime++)
                    //{
                    //    foreach (var item in FutureEventList.Where(e => e.StartTime == GlobalTime).OrderBy(e => e.EventId).ToList())
                    //    {
                    //        Console.WriteLine(string.Format("ID: {0} Start: {1} Lat:{2} Long:{3}", item.EventId, item.StartTime, item.Latitud, item.Longitud));
                    //    }
                    //}


                    for (int GlobalTime = 0; GlobalTime < 1440; GlobalTime++)
                    {
                        List <FutureEvent> events = FutureEventList.Where(e => e.StartTime == GlobalTime).OrderBy(e => e.EventId).ToList();
                        //List<FutureEvent> events =  FutureEventList.OrderBy(e => new { e.StartTime, e.EventId }).ToList();

                        foreach (FutureEvent fe in events)
                        {
                            Random rndNextStation = new Random();

                            #region CustomerRequest Event

                            if (fe.EventType == EventType.CustomerRequest)
                            {
                                double NearestStationDistance = 0;// (km)
                                int    NearestStationIndex    = FindNearestStation(fe.Latitud, fe.Longitud, out NearestStationDistance);

                                if (NearestStationIndex == -1)
                                {
                                    MissRequestCount++;
                                }
                                else
                                {
                                    FutureEvent ne = new FutureEvent();
                                    ne.StationIndex = NearestStationIndex;
                                    ne.StartTime    = fe.StartTime + Convert.ToInt32(Math.Round((NearestStationDistance / WalkSpeed) * 60, 0)); // t = s / v -> time = distance  / speed , Average speed of walking for age of 20-50 is 3.6 km/h
                                    ne.EventType    = EventType.BikeRentStart;
                                    FutureEventList.Add(ne);
                                }
                            }

                            #endregion

                            #region BikeRentStart Event

                            else if (fe.EventType == EventType.BikeRentStart)
                            {
                                // If there is no Available Bike then Add Miss Count And go to next event
                                if (StationList[fe.StationIndex].AvailebleBikes <= 0)
                                {
                                    MissRequestCount++;
                                    PrintStationStatus();
                                    continue;
                                }

                                HitRequestCount++;

                                StationList[fe.StationIndex].AvailebleBikes -= 1;
                                StationList[fe.StationIndex].RequestCount++;
                                Console.WriteLine("1 Bike Pickedup from station " + fe.StationIndex);


                                //Find Next Station based on Movement Probility Matrix
                                double NextStationProbibility = rndNextStation.Next(0, 100) / 100.0;
                                int    NextStationIndex       = -1;
                                double tempTotalProbility     = 0;
                                for (int j = 0; j < MovementProbilityMatrix.Width; j++)
                                {
                                    //x >= 1 && x <= 100
                                    if (NextStationProbibility >= tempTotalProbility && NextStationProbibility < tempTotalProbility + MovementProbilityMatrix[fe.StationIndex, j])
                                    {
                                        NextStationIndex = j;
                                        break;
                                    }
                                    else
                                    {
                                        tempTotalProbility += MovementProbilityMatrix[fe.StationIndex, j];
                                    }
                                }

                                MovementCountMatrix[fe.StationIndex, NextStationIndex] += 1;
                                FutureEvent ne = new FutureEvent();
                                ne.EventType = EventType.BikeRentFinish;

                                ne.StationIndex = NextStationIndex;
                                double DistanceToNextStation = StationList[fe.StationIndex].GetDistanceFromPosition(StationList[NextStationIndex].Latitude, StationList[NextStationIndex].Longitude);
                                TotalDistanceOfBikeRides += DistanceToNextStation;
                                ne.StartTime              = fe.StartTime + Convert.ToInt32(Math.Round((DistanceToNextStation / BikeSpeed) * 60, 0)); // t = s / v -> time = distance / speed , Average speed of bikes is 15 km/h

                                FutureEventList.Add(ne);

                                if (StationList[fe.StationIndex].AvailebleBikes <= 0)
                                {
                                    FutureEvent re = new FutureEvent();
                                    re.EventType    = EventType.Rebalancing;
                                    re.StationIndex = fe.StationIndex;
                                    re.StartTime    = fe.StartTime + 1;
                                    FutureEventList.Add(re);
                                }
                            }

                            #endregion

                            #region BikeRentFinish Event

                            else if (fe.EventType == EventType.BikeRentFinish)
                            {
                                StationList[fe.StationIndex].AvailebleBikes += 1;
                                Console.WriteLine("1 Bike withdraw in station " + fe.StationIndex);

                                if (StationList[fe.StationIndex].AvailebleBikes >= StationList[fe.StationIndex].Capasity)
                                {
                                    FutureEvent re = new FutureEvent();
                                    re.EventType    = EventType.Rebalancing;
                                    re.StationIndex = fe.StationIndex;
                                    re.StartTime    = fe.StartTime + 1;
                                    FutureEventList.Add(re);
                                }
                            }

                            #endregion

                            #region Rebalancing Event

                            else if (fe.EventType == EventType.Rebalancing)
                            {
                                //?? Reblancing To which stations should be done? one station or multiple station ?
                                //e.StartTime = DateTime.Now;  // #### distance and duration to next station Should be determined in here
                                //e.Distance = 0;  // #### distance and duration to next station Should be determined in here

                                RebalancingCount++;

                                foreach (var item in StationList) //Pickup Extra Bikes from each station
                                {
                                    if (item.AvailebleBikes > item.NumberOfBikes)
                                    {
                                        int NumberOfbikesForPickup = item.AvailebleBikes - item.NumberOfBikes;
                                        Console.WriteLine(NumberOfbikesForPickup.ToString() + " Bike Pickedup from station " + item.Index.ToString() + " for rebalancing" + " AvailebleBikes:" + item.AvailebleBikes + " NumberOfBikes: " + item.NumberOfBikes);
                                        TotoalNumberOfbikesForPickup += NumberOfbikesForPickup;
                                        AvailableBikesInTruck        += NumberOfbikesForPickup;
                                        item.AvailebleBikes           = item.NumberOfBikes;
                                    }
                                }

                                foreach (var item in StationList.OrderByDescending(s => s.NumberOfBikes - s.AvailebleBikes)) // withdraw bilke in each station which is needed
                                {
                                    if (AvailableBikesInTruck > 0)
                                    {
                                        if (item.AvailebleBikes < item.NumberOfBikes)
                                        {
                                            if (AvailableBikesInTruck >= item.NumberOfBikes - item.AvailebleBikes)
                                            {
                                                AvailableBikesInTruck -= item.NumberOfBikes - item.AvailebleBikes;
                                                Console.WriteLine((item.NumberOfBikes - item.AvailebleBikes).ToString() + " Bike withdraw in station " + item.Index.ToString() + " for rebalancing" + " AvailebleBikes:" + item.AvailebleBikes + " NumberOfBikes: " + item.NumberOfBikes);
                                                item.AvailebleBikes = item.NumberOfBikes;
                                            }
                                            else
                                            {
                                                Console.WriteLine(AvailableBikesInTruck.ToString() + " Bike withdraw in station " + item.Index.ToString() + " for rebalancing" + " AvailebleBikes:" + item.AvailebleBikes + " NumberOfBikes: " + item.NumberOfBikes);

                                                item.AvailebleBikes    = AvailableBikesInTruck;
                                                AvailableBikesInTruck -= AvailableBikesInTruck;
                                            }
                                        }
                                    }
                                }
                            }

                            #endregion
                        }
                    }

                    foreach (var item in StationList)
                    {
                        Console.WriteLine(string.Format("Station Index : {0}  Weight : {1}  Request : {2}", item.Index, item.Weight, item.RequestCount));
                    }

                    #region Export Resault

                    xlResaultDataSheet.Cells[1, 10] = "TotalDistanceOfUserWalk";
                    xlResaultDataSheet.Cells[1, 11] = "TotalDistanceOfBikeRides";
                    xlResaultDataSheet.Cells[1, 12] = "MissRequestCount";
                    xlResaultDataSheet.Cells[1, 13] = "HitRequestCount";
                    xlResaultDataSheet.Cells[1, 14] = "NumberOfBikesMoved";
                    xlResaultDataSheet.Cells[1, 15] = "RebalancingCount";

                    xlResaultDataSheet.Cells[RoundCount + 1, 10] = TotalDistanceOfUserWalk;
                    xlResaultDataSheet.Cells[RoundCount + 1, 11] = TotalDistanceOfBikeRides;
                    xlResaultDataSheet.Cells[RoundCount + 1, 12] = MissRequestCount;
                    xlResaultDataSheet.Cells[RoundCount + 1, 13] = HitRequestCount;
                    xlResaultDataSheet.Cells[RoundCount + 1, 14] = TotoalNumberOfbikesForPickup;
                    xlResaultDataSheet.Cells[RoundCount + 1, 15] = RebalancingCount;

                    xlStationsDataSheet.Cells[10, 1] = "SimulationRequestCount";

                    foreach (var item in StationList)
                    {
                        xlStationsDataSheet.Cells[10, item.Index + 2] = item.RequestCount;
                    }

                    Console.WriteLine("MovementProbilityMatrix : ------------------------------- " + RoundCount.ToString());
                    MovementProbilityMatrix.PrintMatrix();
                    Console.WriteLine("MovementCountMatrix : ------------------------------- " + RoundCount.ToString());
                    MovementCountMatrix.PrintMatrix();

                    MovementCountMatrix.FillMatrixWithEqalTotal();
                    #endregion
                }

                xlWorkBook.SaveAs(StationLocating.strRootResaultPath + "StationsData3.xls");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #7
0
		/// <summary>
		/// 获取表类型配置
		/// </summary>
		/// <param name="ClassName">类名</param>
		/// <param name="TableElementName">表元素名</param>
		/// <returns></returns>
		public System.Data.DataTable GetTableConfig(string ClassName, string TableElementName)
		{
			if (xn != null)
			{
				System.Xml.XmlNode xn1 = xn.SelectSingleNode(ClassName + "/" + TableElementName);
				if (xn1 != null)
				{
					System.Data.DataTable dt = new System.Data.DataTable(TableElementName);
					StringReader sr = new StringReader(xn1.InnerXml);
					System.Xml.XmlReader xr = System.Xml.XmlReader.Create(sr);
					dt.ReadXml(xr);
					return dt;
				}
			}
			return null;
		}
Пример #8
0
 public static System.Data.DataTable ConvertXMLFileToDataSet(string xmlData)
 {
     System.Xml.XmlTextReader reader = null;
     try {
         System.Data.DataTable xmlDS = new System.Data.DataTable();
         reader = new System.Xml.XmlTextReader(new System.IO.StringReader(xmlData));
         xmlDS.ReadXml(reader);
         return xmlDS;
     } catch (System.Exception ex) {
         throw ex;
     } finally {
         if (reader != null) reader.Close();
     }
 }