Ejemplo n.º 1
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 = "";
            }
        }
Ejemplo n.º 2
0
        private void DoDaFix()
        {
            switch (activeTab) // 0 client, 1 matter
            {
            case 0:

                if (checkClientBoxesForInfo())
                {
                    CliMat cm = new CliMat();
                    cm.clicode = textBoxClientText.Text;
                    cm.name    = textBoxCliName.Text.Replace("%", "").Replace("'", "");
                    cm.remarks = richTextBoxCliRemarks.Text.Replace("%", "").Replace("'", "").Replace("\"", "");
                    cm.branch  = textBoxCliBranch.Text.Replace("%", "").Replace("'", "");

                    processSingleClient(cm);
                    showFinish();
                }
                break;

            case 1:
                if (checkMatterBoxesForInfo())
                {
                    CliMat cm = new CliMat();
                    cm.clicode = textBoxClientMatter.Text;
                    cm.matcode = textBoxMatterText.Text;
                    cm.name    = "";
                    if (!string.IsNullOrEmpty(richTextBoxRemarksMatter.Text.Replace("%", "").Replace("'", "")))
                    {
                        cm.remarks = richTextBoxRemarksMatter.Text.Replace("%", "").Replace("'", "");
                    }
                    else
                    {
                        cm.remarks = "";
                    }
                    cm.branch = "";
                    cm.matsys = getMatSysNbr(cm.clicode, cm.matcode);
                    cm.clisys = getCliSysNbr(cm.clicode);
                    if (cm.clisys != 0 && cm.matsys != 0)
                    {
                        processSingleMatter(cm.matsys, cm.remarks);
                    }
                    else
                    {
                        ErrorLog er = new ErrorLog();
                        er.client  = cm.clicode;
                        er.matter  = cm.matcode;
                        er.message = "Cannot close matter because client/matter " + cm.clicode + "/" + cm.matcode + " does not exist. \r\n" + "\r\n";
                        errorList.Add(er);
                    }
                    showFinish();
                }    // 0 is simply a place holder for method...means nothing
                break;
            }


            errorList.Clear();
            clientFilePath                = "";
            matterFilePath                = "";
            textBoxClientText.Text        = "";
            textBoxCliBranch.Text         = "";
            textBoxCliName.Text           = "";
            richTextBoxCliRemarks.Text    = "";
            textBoxMatterText.Text        = "";
            richTextBoxRemarksMatter.Text = "";
            textBoxClientMatter.Text      = "";
        }