Ejemplo n.º 1
0
        public Form1.SubformType GetState(string id)
        {
            Form1.SubformType r = Form1.SubformType.UNDEF;
            try
            {
                string metaXML = projectBaseFolder + Path.DirectorySeparatorChar + id + Path.DirectorySeparatorChar + "meta.xml";
                if (File.Exists(metaXML))
                {
                    XmlDocument meta_xml = new XmlDocument();
                    meta_xml.Load(metaXML);
                    if (meta_xml.DocumentElement.GetElementsByTagName("state").Count == 1)
                    {
                        XmlNode stateXml = meta_xml.DocumentElement.GetElementsByTagName("state")[0];
                        string  state    = stateXml.InnerXml;
                        Enum.TryParse(state, out Form1.SubformType subform);
                        r = subform;
                    }
                }
            }
            catch (IOException e)
            {
                log_output = e.ToString();
                Form1.logWindow.Write_to_log(ref log_output);
            }

            return(r);
        }
Ejemplo n.º 2
0
        public void SaveData(string id, Form1.SubformType mySubformType, List <List <string> > data)
        {
            try
            {
                string fileName = fileNames[mySubformType];

                string metaXML = projectBaseFolder + Path.DirectorySeparatorChar + id + Path.DirectorySeparatorChar + "meta.xml";
                if (File.Exists(metaXML))
                {
                    if (data.Count > 1)
                    {
                        XmlDocument meta_xml = new XmlDocument();
                        meta_xml.Load(metaXML);
                        if (meta_xml.DocumentElement.GetElementsByTagName("state").Count == 0)
                        {
                            System.Xml.XmlElement state = meta_xml.CreateElement("state");
                            state.InnerXml = mySubformType.ToString();
                            System.Xml.XmlElement root = meta_xml.DocumentElement;
                            root.AppendChild(state);
                        }
                        else
                        {
                            XmlNode state = meta_xml.DocumentElement.GetElementsByTagName("state")[0];
                            state.InnerXml = mySubformType.ToString();
                        }
                        meta_xml.Save(metaXML);

                        Form1.myself.DeactivateActivateMenuItems(mySubformType);
                    }

                    string       writeFile      = projectBaseFolder + Path.DirectorySeparatorChar + id + Path.DirectorySeparatorChar + fileName;
                    Encoding     utf8WithoutBom = new UTF8Encoding(false);
                    StreamWriter sw             = new StreamWriter(writeFile, false, utf8WithoutBom);
                    int          lastColIndex   = data[0].Count;
                    foreach (List <string> row in data)
                    {
                        if (row != null)
                        {
                            foreach (string cell in row)
                            {
                                string sout = cell.Trim();
                                sout = sout.Replace(";", "###SEMICOLON###");
                                sw.Write(sout);
                                sw.Write(";");
                            }
                            sw.WriteLine();
                        }
                    }
                    sw.Close();
                }
            }
            catch (IOException e)
            {
                log_output = e.ToString();
                Form1.logWindow.Write_to_log(ref log_output);

                string msg = Form1.LocRM.GetString("String133");
                MessageBox.Show(msg, "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
Ejemplo n.º 3
0
        public void SaveData(string id, Form1.SubformType mySubformType, List <string[]> data)
        {
            List <List <string> > listData = new List <List <string> >();
            List <string>         row;

            foreach (string[] array in data)
            {
                row = new List <string>(array);
                listData.Add(row);
            }
            SaveData(id, mySubformType, listData);
        }
Ejemplo n.º 4
0
        public void DeregisterForm(string id, Form1.SubformType subformType)
        {
            UniqueForms deleteForm = new UniqueForms();
            bool        delete     = false;

            foreach (UniqueForms form in openFormsForEdit.Keys)
            {
                if (form.id == id && form.subformType == subformType)
                {
                    deleteForm = form;
                    delete     = true;
                }
            }
            if (delete)
            {
                openFormsForEdit.Remove(deleteForm);
            }
        }
Ejemplo n.º 5
0
        // returns false if form should be editable, true if form should be read only
        public bool RegisterForm(string id, Form1.SubformType subformType)
        {
            bool r = false;

            foreach (UniqueForms form in openFormsForEdit.Keys)
            {
                if (form.id == id && form.subformType != subformType)
                {
                    if (!r)
                    {
                        r = openFormsForEdit[form];
                    }
                }
            }
            UniqueForms newForm = new UniqueForms(id, subformType);

            openFormsForEdit[newForm] = !r;
            return(r);
        }
Ejemplo n.º 6
0
        public void SaveData(string id, Form1.SubformType mySubformType, DataGridView dataGrid)
        {
            List <List <string> > data = new List <List <string> >();
            int           lastColIndex = dataGrid.Columns.Count;
            List <string> newRow       = new List <string>();

            foreach (DataGridViewColumn col in dataGrid.Columns)
            {
                if (col.Index < lastColIndex - 1 && !col.ReadOnly)
                {
                    if (col != null)
                    {
                        newRow.Add(col.HeaderText);
                    }
                }
            }
            data.Add(newRow);
            foreach (DataGridViewRow row in dataGrid.Rows)
            {
                newRow = new List <string>();
                if (row != null)
                {
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        if (cell.ColumnIndex < lastColIndex - 1 && !cell.ReadOnly)
                        {
                            if (cell != null && cell.Value != null && cell.Value.ToString() != "")
                            {
                                newRow.Add(cell.Value.ToString().Trim());
                            }
                            else
                            {
                                newRow.Add("");
                            }
                        }
                    }
                    data.Add(newRow);
                }
            }
            SaveData(id, mySubformType, data);
        }
Ejemplo n.º 7
0
        public List <string[]> LoadData(string id, Form1.SubformType mySubformType, bool skipHeader = true)
        {
            string fileName = fileNames[mySubformType];

            List <string[]> returnData    = new List <string[]>();
            List <int>      skipEmptyCols = new List <int>();
            string          loadFile      = projectBaseFolder + Path.DirectorySeparatorChar + id + Path.DirectorySeparatorChar + fileName;

            if (File.Exists(loadFile))
            {
                try
                {
                    StreamReader sr   = new StreamReader(loadFile);
                    string       line = "";
                    string[]     inValues;
                    string[]     outValues;
                    int          count = 0;
                    while (true && line != null)
                    {
                        line = sr.ReadLine();
                        if (line != null)
                        {
                            inValues  = line.Split(';');
                            outValues = inValues;
                            bool all_zero = true;
                            int  index    = 0;
                            foreach (string value in inValues)
                            {
                                if (count == 0 && value == "")
                                {
                                    skipEmptyCols.Add(index);
                                }
                                if (value != "" && value != "0")
                                {
                                    all_zero = false;
                                }
                                if (!skipEmptyCols.Contains(index))
                                {
                                    outValues[index] = value.Replace("###SEMICOLON###", ";");
                                }
                                index++;
                            }
                            if (!all_zero && (count > 0 || !skipHeader))
                            {
                                returnData.Add(outValues);
                            }
                        }
                        count++;
                    }
                    sr.Close();
                }
                catch (IOException e)
                {
                    log_output = e.ToString();
                    Form1.logWindow.Write_to_log(ref log_output);
                }
            }
            List <string[]> finalReturnData = new List <string[]>();

            foreach (string[] row in returnData)
            {
                if (skipEmptyCols.Count > 0)
                {
                    int      endIndex = row.Length - skipEmptyCols.Count + 1;
                    string[] newRow   = new string[endIndex];
                    Array.Copy(row, newRow, endIndex);
                    finalReturnData.Add(newRow);
                }
                else
                {
                    finalReturnData.Add(row);
                }
            }
            return(finalReturnData);
        }
Ejemplo n.º 8
0
 public UniqueForms(string id, Form1.SubformType subformType)
 {
     this.id          = id;
     this.subformType = subformType;
 }