Example #1
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     //Config.instance().writeConfigFile();
     if (ConfigurationManger.getCMInstance().IsConfigFull)
     {
         ConfigurationManger.getCMInstance().saveConfigFile(ConfigurationManger.getCMInstance().getConfig());
     }
 }
Example #2
0
 public static ConfigurationManger getCMInstance()
 {
     if (CMInstance == null)
     {
         CMInstance = new ConfigurationManger();
     }
     return(CMInstance);
 }
Example #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            init();

            /*if (dictionary.Count != 0)
             * {
             *  Configuration confi = new Configuration();
             *  confi.ExTemplates = Config.instance().templateDic;
             *  //confi.ExTemplates
             *  confi.B2Category = dictionary;
             *  ConfigurationManger.getCMInstance().saveConfigFile(confi);
             * }else*/
            {
                ConfigurationManger.getCMInstance().readConfigFile();
                ConfigurationManger.getCMInstance().saveConfigFile(ConfigurationManger.getCMInstance().getConfig());
            }
        }
        List <string> IgetFilesToParse.getFiles()
        {
            if (System.IO.Directory.Exists(ConfigurationManger.getCMInstance().getConfig().LastFolderDialogPath))
            {
                FBD.SelectedPath = ConfigurationManger.getCMInstance().getConfig().LastFolderDialogPath;
            }
            if (FBD.ShowDialog() == DialogResult.OK)
            {
                var folderPath = FBD.SelectedPath;
                ConfigurationManger.getCMInstance().getConfig().LastFolderDialogPath = folderPath;
                //writeConfigFile(FolderRootStart + "=" + folderBrowserDialog1.SelectedPath);

                RTB.AppendText("folder found! moving to parse it");
                RTB.BackColor = System.Drawing.Color.Green;
                var files = System.IO.Directory.GetFiles(folderPath).ToList();
                return(files);
            }
            else
            {
                RTB.BackColor = System.Drawing.Color.Red;
                RTB.AppendText("bad folder :( choose another one\n");
                return(new List <string>());
            }
        }
Example #5
0
        public List <string> getFiles()
        {
            if (System.IO.Directory.Exists(ConfigurationManger.getCMInstance().getConfig().LastFolderDialogPath))
            {
                FD.InitialDirectory = ConfigurationManger.getCMInstance().getConfig().LastFolderDialogPath;
            }
            var res = FD.ShowDialog();

            if (res == System.Windows.Forms.DialogResult.OK)
            {
                ConfigurationManger.getCMInstance().getConfig().LastFolderDialogPath = System.IO.Directory.GetParent(FD.FileName).ToString();
                List <string> retlist = new List <string>();
                var           file    = FD.FileName;
                retlist.Add(file);
                return(retlist);
            }
            else
            {
                RTB.BackColor = System.Drawing.Color.Red;
                RTB.AppendText("bad file :( choose another one\n");
                return(new List <string>());
            }
            //throw new NotImplementedException();
        }
Example #6
0
        private bool init()
        {
            if (firstround)//try creating missing files , should be done only once
            {
                string missingfile = currentdir + @"\" + config;
                config = missingfile;
                List <string> missl = new List <string>();
                if (!System.IO.File.Exists(missingfile))
                {
                    TextBox1.BackColor = Color.Yellow;
                    TextBox1.AppendText(string.Format("config file is missing !! [{0}]\n creating new one", currentdir + @"\" + config));
                    missl.Add(missingfile);
                }
                missingfile   = currentdir + @"\" + missingValues;
                missingValues = missingfile;
                if (!System.IO.File.Exists(missingfile))
                {
                    TextBox1.AppendText(string.Format("missing values file is missing !! [{0}]\n creating new one", currentdir + @"\" + config));
                    missl.Add(missingfile);
                }
                missingfile = currentdir + @"\" + dic;
                dic         = missingfile;
                if (!System.IO.File.Exists(missingfile))
                {
                    TextBox1.AppendText(string.Format("dictionary file is missing !! [{0}]\n creating new one", currentdir + @"\" + config));
                    missl.Add(missingfile);
                }

                foreach (var item in missl)
                {
                    System.IO.File.Create(item);
                }
                firstround = false;
            }
            /////////////////////////////////read config file /////////////////////////////////////////////////
            //ReadConfigFile();
            ///////////////////////////////////////////////////////////////////////////////////////////////////
            if (!System.IO.File.Exists(missingValues))
            {
                System.IO.File.Create(missingValues);
            }

            ConfigurationManger.getCMInstance().readConfigFile();

            /*read missing vlaues if there unanswered categories break else add them to dictionary and clear file !!!*/

            /*if (System.IO.File.ReadAllText(missingValues).
             *      Replace('\t',' ').Replace('\r',' ').
             *          Replace('\n',' ').Trim().Length == 0){*/

            List <BwithoutCategory> BwoC = new List <BwithoutCategory>();

            ConfigurationManger.getCMInstance().getConfig().BussinessWithoutCategory.ForEach(x => {
                if (string.IsNullOrEmpty(x.category))
                {
                    BwoC.Add(x);
                }
                else/* adding filled categories to B2Category dictionary */
                {
                    ConfigurationManger.getCMInstance().getConfig().B2Category.Add(x.name, x.category);
                }
            });

            if (BwoC.Count == 0)
            {
                /*no empty categories !! we can now remove the list */
                ConfigurationManger.getCMInstance().getConfig().BussinessWithoutCategory.Clear();
                result = currentdir + @"\" + result;
                return(true);
            }
            else
            {
                TextBox1.BackColor = Color.Red;
                TextBox1.AppendText("missing category are not empty is not empty !!!");
                TextBox1.AppendText("1) go over it and fill missing categories!!");
                TextBox1.AppendText("2) give High5 to yourself");
                TextBox1.AppendText("3) try again");
                return(false);
            }
        }
Example #7
0
        private void handleFiles(List <string> files)
        {
            List <string> excels = new List <string>();

            //fill up dictionary

            /*dictionary = new Dictionary<string, string>();
             * foreach (var r in System.IO.File.ReadAllLines(dic))
             * {
             *  if (!string.IsNullOrEmpty(r))
             *  {
             *      var words = r.Split('=').ToList();
             *
             *      if (words.Count == 2 && !dictionary.ContainsKey(words[0]))
             *      {
             *          dictionary.Add(words[0], words[1]);
             *      }
             *  }
             * }*/

            //get all excels
            string exten;

            foreach (var f in files)
            {
                exten = System.IO.Path.GetExtension(f);
                if (exten == ".xlsx" || exten == ".xls")
                {
                    excels.Add(f);
                }
            }

            if (excels.Count == 0)
            {
                TextBox1.AppendText("no excel files found in folder !!\n");
                TextBox1.BackColor = Color.Green;
                return;
            }



            //iterate over excels;
            foreach (var ex in excels)
            {
                var excel = Read_From_Excel.getExcelFile(ex);
                TextBox1.BackColor = Color.Green;
                TextBox1.AppendText(string.Format("reading excel:[{0}]\n", ex));

                //calc MD5 for excel template ////////
                string template = "";
                foreach (var w in excel[0])
                {
                    template += w;
                }
                var MD5 = Read_From_Excel.CalculateMD5Hash(template);
                //////////////////////////////////////
                var    configuration = ConfigurationManger.getCMInstance().getConfig();
                credit cval;
                //if (!Config.instance().templateDic.TryGetValue(MD5, out cval))

                if (!configuration.ExTemplates.TryGetValue(MD5, out cval))
                {/*temp solution !!*/
                    configuration.ExTemplates.Add(MD5, new credit(-1, -1, -1));
                    //writeConfigFile(Exceltemplate + "=" + MD5 + "," + "?????" + "\n");

                    TextBox1.BackColor = Color.Red;
                    TextBox1.AppendText(string.Format("missing template in config file[{0}] !!!\n", config));
                    TextBox1.AppendText("better call Matan Integration Inc. [052-7758661]\n");
                    return;
                }
                else//template found
                {
                    List <string> r;
                    //var excelRanged = excel.GetRange(cval.StartRow, excel.Count - 1);
                    for (int i = cval.StartRow; i < excel.Count; i++)
                    //foreach (var r in excel.GetRange(1,excel.Count-1))
                    {
                        r = excel[i];
                        if (r.Count < cval.sum || r.Count < cval.nameIndex)
                        {
                            continue;
                        }
                        string category;
                        if (!configuration.B2Category.TryGetValue(r[cval.nameIndex], out category))
                        {
                            configuration.BussinessWithoutCategory.Add(new BwithoutCategory(r[cval.nameIndex]));
                            //writeFile(FILES_TO_WRITE.MISSING, r[cval.nameIndex]);
                            //TextBox1.BackColor = Color.Yellow;
                            TextBox1.AppendText(string.Format("missing category for [{0}] !!!\n\n", r[cval.nameIndex]));
                        }
                        else//value found in dectionary
                        {
                            if (cval.namesToExclude.Contains(category))
                            {
                                continue;//leave current iteration , exclude filter triggered
                            }
                            if (!CategoryResultDic.ContainsKey(category))
                            {
                                CategoryResultDic.Add(category, new creditResult());
                            }
                            double dSum = Convert.ToDouble(r[cval.sum]);
                            if (dSum > 0)
                            {
                                CategoryResultDic[category].category = category;
                                CategoryResultDic[category].relatedRows.Add(r);
                                CategoryResultDic[category].sum += dSum;
                            }
                        }
                    }
                    TextBox1.BackColor = Color.WhiteSmoke;


                    TextBox1.AppendText("parsing finished\n");

                    System.IO.File.WriteAllText(result, "");
                    foreach (var pair in CategoryResultDic)
                    {
                        TextBox1.AppendText(string.Format("Category\n{0}\n", pair.Value.category));
                        TextBox1.AppendText(string.Format("final sum\n{0}\n", pair.Value.sum));
                        writeFile(FILES_TO_WRITE.RESULT, pair.Value);
                    }
                }
            }
        }