예제 #1
0
        public bool writeConfig(ConfigClass cfg)
        {
            bool didErrorHappen = false;

            try
            {
                if (File.Exists(Path.GetFileName(savePath)))
                {
                    didErrorHappen = appendText(cfg);
                }
                else
                {
                    didErrorHappen = appendText(cfg);
                }
            }
            catch (Exception ex1)
            {
                didErrorHappen = true;
                errors         = ex1.Message;
            }
            return(didErrorHappen);
        }
        public List <ConfigClass> readLines()
        {
            string[]    items = new string[8];
            ConfigClass cfg;

            List <ArrayHolder> aList = new List <ArrayHolder>();
            List <ConfigClass> cList = new List <ConfigClass>();

            try
            {
                int         counter = -1;
                ArrayHolder arh     = null;
                foreach (string line in File.ReadLines(savePath))
                {
                    if (line.Contains("<Increment"))
                    {
                        if (line.Contains("<IncrementA>"))
                        {
                            aText = line.Replace("<IncrementA>", "");
                        }
                        else
                        {
                            bText = line.Replace("<IncrementB>", "");
                        }
                    }
                    else
                    {
                        counter++;
                        if (counter == 0)
                        {
                            arh = new ArrayHolder();
                        }
                        arh.items[counter] = line;
                        if (counter == 7)
                        {
                            counter = -1;
                            aList.Add(arh);
                        }
                    }
                }
                foreach (ArrayHolder ar in aList)
                {
                    cfg = new ConfigClass();
                    if (ar.items[0].Equals("<Group0>"))
                    {
                        //main group
                        cfg.GroupType = 0;
                        cfg.ClNum     = ar.items[1];
                        cfg.ClName    = ar.items[2];
                        cfg.MNum      = ar.items[3];
                        cfg.MName     = ar.items[4];
                        cfg.matsysnbr = ar.items[5];
                        cfg.clisysnbr = ar.items[6];
                        cList.Add(cfg);
                    }
                    else if (ar.items[0].Equals("<Group1>")) //group A
                    {
                        cfg.GroupType = 1;
                        cfg.ClNum     = ar.items[1];
                        cfg.ClName    = ar.items[2];
                        cfg.MNum      = ar.items[3];
                        cfg.MName     = ar.items[4];
                        cfg.matsysnbr = ar.items[5];
                        cfg.clisysnbr = ar.items[6];
                        cList.Add(cfg);
                    }
                    else if (ar.items[0].Equals("<Group2>")) //group B
                    {
                        cfg.GroupType = 2;
                        cfg.ClNum     = ar.items[1];
                        cfg.ClName    = ar.items[2];
                        cfg.MNum      = ar.items[3];
                        cfg.MName     = ar.items[4];
                        cfg.matsysnbr = ar.items[5];
                        cfg.clisysnbr = ar.items[6];
                        cList.Add(cfg);
                    }
                    else
                    {
                        errors = "Corruption";
                    }
                }
                return(cList);
            }
            catch (Exception ex1)
            {
                return(null);

                errors = ex1.Message;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //save
            string fName = "";

            saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            saveFileDialog1.Title            = "Save Config File";
            saveFileDialog1.CheckFileExists  = false;
            saveFileDialog1.CheckPathExists  = true;
            saveFileDialog1.DefaultExt       = "jcfg";
            saveFileDialog1.Filter           = "Juris Config Files (*.jcfg)|*.jcfg|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 1;
            saveFileDialog1.RestoreDirectory = true;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                fName = saveFileDialog1.FileName;
                ConfigClass  config;
                ConfigWriter write = new ConfigWriter(fName, textBoxA.Text, textBoxB.Text);
                if (File.Exists(fName))
                {
                    write.clearConfigFile();
                }
                foreach (DataGridViewRow row in dataGridView2.Rows)
                {
                    config           = new ConfigClass();
                    config.GroupType = 0;
                    config.ClNum     = row.Cells[0].Value.ToString();
                    config.ClName    = row.Cells[1].Value.ToString();
                    config.MNum      = row.Cells[2].Value.ToString();
                    config.MName     = row.Cells[3].Value.ToString();
                    config.matsysnbr = row.Cells[4].Value.ToString();
                    config.clisysnbr = row.Cells[5].Value.ToString();
                    write.writeConfig(config);
                }
                foreach (DataGridViewRow row in dataGridViewA.Rows)
                {
                    config           = new ConfigClass();
                    config.GroupType = 1;
                    config.ClNum     = row.Cells[0].Value.ToString();
                    config.MNum      = row.Cells[1].Value.ToString();
                    config.matsysnbr = row.Cells[2].Value.ToString();
                    config.clisysnbr = row.Cells[3].Value.ToString();
                    write.writeConfig(config);
                }
                foreach (DataGridViewRow row in dataGridViewB.Rows)
                {
                    config           = new ConfigClass();
                    config.GroupType = 2;
                    config.ClNum     = row.Cells[0].Value.ToString();
                    config.MNum      = row.Cells[1].Value.ToString();
                    config.matsysnbr = row.Cells[2].Value.ToString();
                    config.clisysnbr = row.Cells[3].Value.ToString();
                    write.writeConfig(config);
                }
                if (write.clearConfigFile() == true)
                {
                    MessageBox.Show("This file cannot be saved. Please contact Professional Services." + "\r\n" + "Details: " + write.errors, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                write.appendTextInc(textBoxA.Text, textBoxB.Text);
            }
        }