Exemple #1
0
        //调用python进行列车交路的勾画
        private async void 自动勾画交路ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //从数据库中导出勾画交路所需要的原始数据
            this.沪宁线高铁车次绘制ToolStripMenuItem_Click(sender, e);
            DataSet dataSet = new DataSet();

            try
            {
                SqlConnection connection =
                    new SqlConnection(
                        "Data Source=DESKTOP-49O35N0;Initial Catalog=GraduateProject;Integrated Security=True");
                connection.Open();
                string         sqlStr  = $"SELECT DISTINCT * FROM  dbo.OD为上海站和南京站的所有列车时刻表信息";
                SqlDataAdapter adapter = new SqlDataAdapter(sqlStr, connection);
                adapter.Fill(dataSet, "OD为上海站和南京站的所有列车时刻表信息");
                Console.WriteLine("数据库连接成功");
                GetSciEi.Excel.TableToExcel(dataSet.Tables["OD为上海站和南京站的所有列车时刻表信息"], @".\python\车底勾画\data\OD为上海站和南京站的所有列车时刻表信息.xlsx");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"数据库连接有误,错误信息{ex.Message}");
                throw;
            }

            await Task.Run(() =>
            {
                Directory.SetCurrentDirectory(@".\Python\车底勾画\");//设置python文件运行的路径
                Process process = new Process {
                    StartInfo = { FileName = @".\车底勾画.exe" }
                };                                                                         //启动python
                process.Start();
                process.WaitForExit();
                process.Dispose();
            });

            DirectoryInfo currentDirectoryInfoParent = Directory.GetParent(Directory.GetCurrentDirectory());//重新设置主程序运行的路径

            if (currentDirectoryInfoParent.Parent != null)
            {
                Directory.SetCurrentDirectory(currentDirectoryInfoParent.Parent.FullName);
            }

            JiaoLuForm jiaoluForm = new JiaoLuForm(this)
            {
                trainDiagraph = DeepClone(trainsDiagram),
                allTrains     = this.trains,//图里的所有列车集合
                dataFilePath  = @".\Python\车底勾画\data\交路勾画方案.xlsx"
            };

            jiaoluForm.Show(this);//窗体之间通信
        }
Exemple #2
0
        private async void 动车所能力限制交路勾画ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //从数据库中导出勾画交路所需要的原始数据
            this.沪宁线高铁车次绘制ToolStripMenuItem_Click(sender, e);//先画原始的列车运行图
            //算法计算引擎
            await Task.Run(() =>
            {
                Directory.SetCurrentDirectory(@".\能力限制下的交路自动勾画");    //设置当前的运行路径
                //新开一个线程进行交路的算法引擎的运行
                System.Diagnostics.Process p = new System.Diagnostics.Process
                {
                    StartInfo =
                    {
                        FileName = @".\test.exe",
                    }
                };
                p.Start();
                p.WaitForExit();
                p.Dispose();
            });

            //运行路径恢复
            DirectoryInfo currentDirectoryInfoParent = Directory.GetParent(Directory.GetCurrentDirectory());//重新设置主程序运行的路径

            if (currentDirectoryInfoParent.Parent != null)
            {
                Directory.SetCurrentDirectory(currentDirectoryInfoParent.FullName);
            }

            JiaoLuForm capacity_limited_form = new JiaoLuForm(this)
            {
                allTrains     = this.trains,
                dataFilePath  = @".\能力限制下的交路自动勾画\hello\交路勾画方案既定.xlsx",
                trainDiagraph = DeepClone(trainsDiagram)
            };

            capacity_limited_form.Show(this);
        }