Exemplo n.º 1
0
        //Load matrix file
        private void button9_Click(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            comboBox1.Items.Clear();
            comboBox2.Items.Clear();
            textBox1.Clear();
            textBox2.Clear();
            button7.Enabled = false;
            button8.Enabled = false;
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = "Text|*.txt";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        string       filename = openFileDialog1.FileName;
                        string       fileText = System.IO.File.ReadAllText(filename);
                        MatrixParser parser   = new MatrixParser();
                        new_graph = InputMatrixParser.ParseSquareMatrix(fileText, filename)[0].graph;
                        renderVerticles();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        //Load matrix to convert with rules
        private void button14_Click(object sender, EventArgs e)
        {
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = "Text|*.txt";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        string                filename  = openFileDialog1.FileName;
                        string                fileText  = System.IO.File.ReadAllText(filename);
                        MatrixParser          parser    = new MatrixParser();
                        List <FullMatrixData> parseData = InputMatrixParser.ParseSquareMatrix(fileText, filename);
                        matrixJsonGlobal  = parseData[0].matrixJson;
                        richTextBox3.Text = JsonConvert.SerializeObject(matrixJsonGlobal);

                        //GenerationRules ruleData = input_generator.Classes.RuleParser.ParseRules(parseData[0].yamlRules);
                        //input_generator.Classes.Generator.generateSquareMatrix(ruleData, parseData[0].matrixJson);
                        //richTextBox4.Text =
                        //System.IO.File.WriteAllText("generated-matrix.txt", matrixJson);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        private void CalculateTxtData()
        {
            System.Data.DataTable dtInfo   = new System.Data.DataTable();
            System.Data.DataTable dtMatrix = new System.Data.DataTable();
            ipList = new List <InfoParser>();
            mpList = new List <MatrixParser>();
            if (File.Exists(infoFile) && File.Exists(matrixFile))
            {
                splashScreenManager1.ShowWaitForm();
                splashScreenManager1.SetWaitFormCaption("正在加载数据");
                splashScreenManager1.SetWaitFormDescription(" 请等待。。。");

                dtInfo   = OpenCSV(infoFile, 0, 0, 0, 0, true);
                dtMatrix = OpenCSV(matrixFile, 0, 0, 0, 0, true);
                foreach (DataRow dr in dtInfo.Rows)
                {
                    if (dr[0].ToString() == "0")
                    {
                        continue;
                    }
                    else
                    {
                        InfoParser ip = new InfoParser();
                        ip.No    = dr[0].ToString();
                        ip.Value = dr[1].ToString();
                        ip.Name  = dr[2].ToString();
                        ipList.Add(ip);
                    }
                }
                foreach (DataRow dr in dtMatrix.Rows)
                {
                    MatrixParser mp = new MatrixParser();
                    mp.No       = dr[0].ToString();
                    mp.Value    = dr[1].ToString();
                    mp.Name     = dr[2].ToString();
                    mp.OldValue = dr[3].ToString();
                    mpList.Add(mp);
                }

                splashScreenManager1.SetWaitFormCaption("正在计算");
                FrmCalculation frmCal = new FrmCalculation(mpList, ipList);
                splashScreenManager1.CloseWaitForm();
                frmCal.Show();
            }
            else
            {
                MessageBox.Show("CSV文件不存在");
            }
        }
Exemplo n.º 4
0
        public void Parse_ValidParse_ElementEqualsExpected <TSet, TStruct, TParser> (
            TSet hack1,
            TStruct hack2,
            TParser hack3,
            MatrixParser <TSet, TStruct, TParser> parser,
            String inputString,
            Matrix <TSet, TStruct> expected)
            where TStruct : IStructure, new()
            where TParser : IParser <TSet>, new()
        {
            var result = parser.Parse(inputString);

            Assert.IsNotNull(result);

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 5
0
        private int ImportExcel(bool hasTitle, string fileName, string password)
        {
            Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
            Sheets   sheets;
            object   oMissiong = System.Reflection.Missing.Value;
            Workbook workbook  = null;

            System.Data.DataTable dt = new System.Data.DataTable();

            try
            {
                if (app == null)
                {
                    return(0);
                }
                workbook = app.Workbooks.Open(fileName, oMissiong, oMissiong, oMissiong, password, oMissiong,
                                              oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong);
                sheets = workbook.Worksheets;



                //将数据读入

                //worksheet 1
                Excel.Worksheet ws = (Worksheet)sheets.get_Item(3);

                int iRowCount = ws.UsedRange.Rows.Count;
                int iColCount = ws.UsedRange.Columns.Count;

                Range range;
                int   rowIdx = hasTitle ? 2 : 1;

                iRowCount = ws.UsedRange.Rows.Count;
                iColCount = ws.UsedRange.Columns.Count;

                List <MatrixParser> mpList = new List <MatrixParser>();
                for (int iRow = rowIdx; iRow <= iRowCount; iRow++)
                {
                    MatrixParser mp = new MatrixParser();
                    range       = (Range)ws.Cells[iRow, 1];
                    mp.No       = (range.Value2 == null) ? "" : range.Text.ToString();
                    range       = (Range)ws.Cells[iRow, 2];
                    mp.Value    = (range.Value2 == null) ? "" : range.Text.ToString();
                    range       = (Range)ws.Cells[iRow, 3];
                    mp.Name     = (range.Value2 == null) ? "" : range.Text.ToString();
                    range       = (Range)ws.Cells[iRow, 4];
                    mp.OldValue = (range.Value2 == null) ? "" : range.Text.ToString();
                    mpList.Add(mp);
                }

                //string matrix = JsonConvert.SerializeObject(mpList);


                return(mpList.Count);
            }
            catch (Exception ex)
            {
                string haha = ex.ToString();
                return(0);
            }
            finally
            {
                workbook.Close(false, oMissiong, oMissiong);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
                workbook = null;
                app.Workbooks.Close();
                app.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
            }
        }
Exemplo n.º 6
0
        private int SaveFileToDB(bool hasTitle, string fileName, string password)
        {
            Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
            Sheets   sheets;
            object   oMissiong = System.Reflection.Missing.Value;
            Workbook workbook  = null;

            System.Data.DataTable dt = new System.Data.DataTable();

            try
            {
                if (app == null)
                {
                    return(0);
                }
                workbook = app.Workbooks.Open(fileName, oMissiong, oMissiong, oMissiong, password, oMissiong,
                                              oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong);
                sheets = workbook.Worksheets;



                //将数据读入

                //worksheet 1
                Excel.Worksheet ws = (Worksheet)sheets.get_Item(1);
                if (ws == null)
                {
                    return(0);
                }

                string machineSourceCode = ((Excel.Range)ws.Cells[1, 1]).Text.ToString();
                string machineCode       = "";
                if (machineSourceCode.IndexOf("=") > 0)
                {
                    string[] machineCodes = machineSourceCode.Split('=');
                    if (machineCodes.Length == 2)
                    {
                        machineCode = machineCodes[1];
                    }
                }

                ws = (Worksheet)sheets.get_Item(2);
                string serialCode = ((Excel.Range)ws.Cells[3, 3]).Text.ToString();
                if (serialCode.IndexOf("_") > 0)
                {
                    string[] serialCodes = serialCode.Split('_');
                    if (serialCodes.Length == 2)
                    {
                        serialCode = serialCodes[1];
                    }
                }

                string sex = ((Excel.Range)ws.Cells[11, 3]).Text.ToString().ToLower();

                int iRowCount = ws.UsedRange.Rows.Count;
                int iColCount = ws.UsedRange.Columns.Count;

                //生成行数据 info
                List <InfoParser> ipList = new List <InfoParser>();
                Range             range;
                int rowIdx = hasTitle ? 2 : 1;
                for (int iRow = rowIdx; iRow <= iRowCount; iRow++)
                {
                    InfoParser ip = new InfoParser();
                    range    = (Range)ws.Cells[iRow, 1];
                    ip.No    = (range.Value2 == null) ? "" : range.Text.ToString();
                    range    = (Range)ws.Cells[iRow, 2];
                    ip.Value = (range.Value2 == null) ? "" : range.Text.ToString();
                    range    = (Range)ws.Cells[iRow, 3];
                    ip.Name  = (range.Value2 == null) ? "" : range.Text.ToString();
                    ipList.Add(ip);
                }

                //生成行数据 matrix
                ws        = (Worksheet)sheets.get_Item(3);
                iRowCount = ws.UsedRange.Rows.Count;
                iColCount = ws.UsedRange.Columns.Count;

                List <MatrixParser> mpList = new List <MatrixParser>();
                for (int iRow = rowIdx; iRow <= iRowCount; iRow++)
                {
                    MatrixParser mp = new MatrixParser();
                    range       = (Range)ws.Cells[iRow, 1];
                    mp.No       = (range.Value2 == null) ? "" : range.Text.ToString();
                    range       = (Range)ws.Cells[iRow, 2];
                    mp.Value    = (range.Value2 == null) ? "" : range.Text.ToString();
                    range       = (Range)ws.Cells[iRow, 3];
                    mp.Name     = (range.Value2 == null) ? "" : range.Text.ToString();
                    range       = (Range)ws.Cells[iRow, 4];
                    mp.OldValue = (range.Value2 == null) ? "" : range.Text.ToString();
                    mpList.Add(mp);
                }

                string info   = JsonConvert.SerializeObject(ipList);
                string matrix = JsonConvert.SerializeObject(mpList);

                modelSourceData.infoData    = info;
                modelSourceData.matrixData  = matrix;
                modelSourceData.serialCode  = serialCode;
                modelSourceData.machineCode = machineCode;
                modelSourceData.sex         = sex;
                int ret = dalSourceData.Add(modelSourceData);

                return(ret);
            }
            catch { return(0); }
            finally
            {
                workbook.Close(false, oMissiong, oMissiong);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
                workbook = null;
                app.Workbooks.Close();
                app.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
            }
        }
Exemplo n.º 7
0
        public void Extract_row_from_one_number_matrix()
        {
            var sut = new MatrixParser("1");

            Assert.Equal(new[] { 1 }, sut.Row(0));
        }
Exemplo n.º 8
0
        public void Extract_column_where_numbers_have_different_widths()
        {
            var sut = new MatrixParser("89 1903 3\n18 3 1\n9 4 800");

            Assert.Equal(new[] { 1903, 3, 4 }, sut.Column(1));
        }
Exemplo n.º 9
0
        public void Can_extract_column_from_non_square_matrix()
        {
            var sut = new MatrixParser("1 2 3\n4 5 6\n7 8 9\n8 7 6");

            Assert.Equal(new[] { 3, 6, 9, 6 }, sut.Column(2));
        }
Exemplo n.º 10
0
        public void Can_extract_column()
        {
            var sut = new MatrixParser("1 2 3\n4 5 6\n7 8 9");

            Assert.Equal(new[] { 3, 6, 9 }, sut.Column(2));
        }
Exemplo n.º 11
0
        public void Extract_column_from_one_number_matrix()
        {
            var sut = new MatrixParser("1");

            Assert.Equal(new[] { 1 }, sut.Column(0));
        }
Exemplo n.º 12
0
        public void Can_extract_row_from_non_square_matrix()
        {
            var sut = new MatrixParser("1 2 3\n4 5 6\n7 8 9\n8 7 6");

            Assert.Equal(new[] { 7, 8, 9 }, sut.Row(2));
        }
Exemplo n.º 13
0
        public void Extract_row_where_numbers_have_different_widths()
        {
            var sut = new MatrixParser("1 2\n10 20");

            Assert.Equal(new[] { 10, 20 }, sut.Row(1));
        }
Exemplo n.º 14
0
        public void Can_extract_row()
        {
            var sut = new MatrixParser("1 2\n3 4");

            Assert.Equal(new[] { 3, 4 }, sut.Row(1));
        }