Exemple #1
0
        private void processMatterExcel()
        {
            OpenFileDialogOpen.InitialDirectory = @"C:\";
            OpenFileDialogOpen.Title            = "Browse CSV Files";
            OpenFileDialogOpen.DefaultExt       = "csv";
            OpenFileDialogOpen.Filter           = "csv files (*.csv)|*.csv|All files (*.*)|*.*";
            OpenFileDialogOpen.CheckFileExists  = true;
            OpenFileDialogOpen.CheckPathExists  = true;
            OpenFileDialogOpen.Multiselect      = false;

            List <CliMat> cliMatList = new List <CliMat>();

            if (OpenFileDialogOpen.ShowDialog() == DialogResult.OK)
            {
                int lineNum    = 0;
                var fileStream = new FileStream(OpenFileDialogOpen.FileName, FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        lineNum++;
                        if (lineNum > 1)     // ignore header line
                        {
                            TextFieldParser parser = new TextFieldParser(new StringReader(line));

                            // You can also read from a file
                            // TextFieldParser parser = new TextFieldParser("mycsvfile.csv");

                            parser.HasFieldsEnclosedInQuotes = true;
                            parser.SetDelimiters(",");

                            string[] fields;

                            while (!parser.EndOfData)
                            {
                                fields = parser.ReadFields();

                                CliMat cm = new CliMat();
                                cm.clicode = fields[0];
                                cm.matcode = fields[1];
                                cm.clisys  = getCliSysNbr(cm.clicode);
                                cm.matsys  = getMatSysNbr(cm.clicode, cm.matcode);
                                cm.remarks = fields[2].Replace("%", "").Replace("'", "");
                                cm.branch  = "";
                                cliMatList.Add(cm);
                            }

                            parser.Close();
                        }
                    }
                }



                //order all items by client and matter code
                var finalList = cliMatList.OrderBy(x => x.clicode).ThenBy(y => y.matcode).ToList();
                cliMatList.Clear();
                int total        = finalList.Count;
                int runningTotal = 0;
                foreach (CliMat cc in finalList)
                {
                    bool notUsed = true;
                    if (cc.clisys != 0 && cc.matsys != 0)
                    {
                        notUsed = processSingleMatter(cc.matsys, cc.remarks);
                    }
                    else
                    {
                        ErrorLog er = new ErrorLog();
                        er.client  = cc.clicode;
                        er.matter  = cc.matcode;
                        er.message = "Cannot close matter because client/matter " + cc.clicode + "/" + cc.matcode + " does not exist. \r\n" + "\r\n";
                        errorList.Add(er);
                    }
                }
                runningTotal++;
                UpdateStatus("Updating....", runningTotal, total);
                showFinish();
                errorList.Clear();
                clientFilePath = "";
                matterFilePath = "";
            }
        }
Exemple #2
0
        private void processClientExcel()
        {
            //parse data from file
            OpenFileDialogOpen.InitialDirectory = @"C:\";
            OpenFileDialogOpen.Title            = "Browse CSV Files";
            OpenFileDialogOpen.DefaultExt       = "csv";
            OpenFileDialogOpen.Filter           = "csv files (*.csv)|*.csv|All files (*.*)|*.*";
            OpenFileDialogOpen.CheckFileExists  = true;
            OpenFileDialogOpen.CheckPathExists  = true;
            OpenFileDialogOpen.Multiselect      = false;

            List <CliMat> cliMatList = new List <CliMat>();

            if (OpenFileDialogOpen.ShowDialog() == DialogResult.OK)
            {
                int lineNum    = 0;
                var fileStream = new FileStream(OpenFileDialogOpen.FileName, FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        lineNum++;
                        if (lineNum > 1) // ignore header line
                        {
                            TextFieldParser parser = new TextFieldParser(new StringReader(line));

                            // You can also read from a file
                            // TextFieldParser parser = new TextFieldParser("mycsvfile.csv");

                            parser.HasFieldsEnclosedInQuotes = true;
                            parser.SetDelimiters(",");

                            string[] fields;

                            while (!parser.EndOfData)
                            {
                                fields = parser.ReadFields();

                                CliMat cm = new CliMat();
                                cm.clicode = fields[0];
                                cm.name    = fields[1].Replace("%", "").Replace("'", "");
                                cm.clisys  = getCliSysNbr(cm.clicode);
                                //cm.remarks = fields[3].Replace("%", "").Replace("'", "").Replace('\u00A0', ' ');

                                string cleaned     = "";
                                string pattern     = @"[^\u0000-\u007F]+";
                                string replacement = " ";

                                Regex rgx = new Regex(pattern);
                                cleaned = rgx.Replace(fields[3].Replace("%", "").Replace("'", ""), replacement);

                                cm.remarks = cleaned;

                                cm.branch = fields[2].Replace("%", "").Replace("'", "");
                                cliMatList.Add(cm);
                            }

                            parser.Close();
                        }
                    }
                }
                //change tab defaults
                //order all items by client and matter code
                var finalList    = cliMatList.OrderBy(x => x.clicode).ToList();
                int total        = finalList.Count;
                int runningTotal = 0;
                foreach (CliMat cc in finalList)
                {
                    if (cc.clisys != 0)
                    {
                        processSingleClient(cc);
                    }
                    else
                    {
                        ErrorLog er = new ErrorLog();
                        er.client  = cc.clicode;
                        er.message = "Client " + cc.clicode + " does not appear to be a valid client. Check that the entered code matches what is displayed in Core exactly." + "\r\n" + "\r\n"; //still close client even with no matters
                        errorList.Add(er);
                    }
                    runningTotal++;
                    UpdateStatus("Updating....", runningTotal, total);
                }
                showFinish();
                errorList.Clear();
                clientFilePath = "";
                matterFilePath = "";
            }
        }