Пример #1
0
        private void dgvCases_CellValidated(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                this.SuspendLayout();
                this.dgvCases.SuspendLayout();

                List <string> cases = new List <string>();

                for (int i = 0; i < dgvCases.Rows.Count - 1; i++)
                {
                    if (i != e.RowIndex)
                    {
                        cases.Add(dgvCases.Rows[i].Cells[e.ColumnIndex].Value.ToString());
                    }
                }

                if (cases.Contains(dgvCases.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()) || Helper.HasRestrictedCasePrefix(dgvCases.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()))
                {
                    dgvCases.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightPink;
                }


                this.dgvCases.ResumeLayout(false);
                this.ResumeLayout(false);
                this.dgvCases.ClearSelection();
            }
        }
Пример #2
0
        /*
         *
         * This particular function is very specific in how it pastes data based on specific client requests.
         *
         * in this case I don't care about all the cells that come out of the columns.
         * All we really want is the first column.  This should accomodate pasting using ALT, or
         * selecting all rows and columns and then pasting.
         */
        private void PasteClipboard()
        {
            bool   dataFormatCorrect = true;
            bool   excludedDupes     = false;
            bool   excludedPrefixes  = false;
            string strCaseName       = string.Empty;
            string strClipboardData  = string.Empty;

            string[] rowSplitter = { "\r\n", "\r", "\n" };

            this.SuspendLayout();
            dgvCases.SuspendLayout();

            // get text from clipboard
            try
            {
                strClipboardData = ((IDataObject)Clipboard.GetDataObject()).GetData(DataFormats.Text).ToString();
            }
            catch { }

            if (!string.IsNullOrEmpty(strClipboardData))
            {
                // split clipboard data into lines and add each as row in datagridview
                foreach (string strRow in strClipboardData.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries))
                {
                    // 132 character matches input file.
                    if (strRow.Length == 132)
                    {
                        // checking obligor, owed, paid, and balance columns
                        if (!strRow.Substring(78, 14).Contains("$") || !strRow.Substring(93, 14).Contains("$") ||
                            !strRow.Substring(108, 14).Contains("$") || strRow.Substring(28, 25).Trim().Length < 1)
                        {
                            dataFormatCorrect = false;
                            continue;
                        }

                        strCaseName = strRow.Substring(0, 18).Trim();
                    }
                    else if (strRow.Trim().Length <= 18 && strRow.Trim().Length > 0 && !strRow.ToLower().Contains("rows selected"))
                    {
                        strCaseName = strRow.Trim();
                    }
                    else
                    {
                        dataFormatCorrect = false;
                        continue;
                    }

                    // does the case already exist
                    if (CaseExists(strCaseName))
                    {
                        excludedDupes = true;
                        continue;
                    }

                    // does the case have an excluded prefix
                    if (Helper.HasRestrictedCasePrefix(strCaseName))
                    {
                        excludedPrefixes = true;
                        continue;
                    }

                    // adding case
                    PlanCase plancase = (PlanCase)bindingCases.AddNew();
                    plancase.CaseName = strCaseName;
                    if (strCaseName.ToUpper().Contains("NT") || strCaseName.ToUpper().Contains("ST"))
                    {
                        plancase.CAPP = true;
                    }
                }

                bindingCases.ResetBindings(false);
            }

            dgvCases.ResumeLayout(false);
            this.ResumeLayout(false);

            if (excludedDupes || excludedPrefixes || !dataFormatCorrect)
            {
                string strMessage = "";

                if (excludedDupes)
                {
                    strMessage += "Duplicate case(s) encountered.\n";
                }

                if (excludedPrefixes)
                {
                    strMessage += "Case(s) encountered that had an excluded prefix.\n";
                }

                if (!dataFormatCorrect)
                {
                    strMessage += "*Clipboard line(s) encountered that do not match a recognizable format:\n\n"
                                  + "1.  a line exactly 132 characters.\n"
                                  + "2.  a line that is 19 characters or less.\n\n"
                                  + "*This message should be expected if pasting an entire file and not specific rows.";
                }

                MessageBox.Show(this, strMessage, "Cases", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }