Example #1
0
        public RefComponents CreateComponents(string str1)
        {
            RefComponents TempComp = new RefComponents();

            if (str1 != string.Empty)
            {
                string numstr1 = Regex.Replace(str1, "[^0-9.]", string.Empty);
                int    num     = int.Parse(numstr1);
                string letter  = Regex.Replace(str1, @"[\d-]", string.Empty);

                TempComp.prefix = letter;
                TempComp.number = num;
            }

            return(TempComp);
        }
Example #2
0
        private void ExportDataToExcel()
        {
            string firstCellStr  = Cell1.Text.ToString();
            string secondCellStr = Cell2.Text.ToString();

            //creating strings for the users column inputs
            string QuantityCol        = QuantityTextBox.Text.ToString();
            string PartDescriptionCol = PartDescTextBox.Text.ToString();
            string ManufacturerCol    = ManufacturerTextBox.Text.ToString();
            string ManufacturerPNCol  = ManufacturerPNTextBox.Text.ToString();

            //splitting variables into separate parts
            RefComponents cell1Comps = CreateComponents(firstCellStr);
            RefComponents cell2Comps = CreateComponents(secondCellStr);

            //reading the excel range into a list of strings
            if (firstCellStr != string.Empty && secondCellStr == string.Empty)
            {
                RefStringList.Add(UnsortedExcelFile.ReadCell(cell1Comps.prefix[0], cell1Comps.number));
            }
            else if (firstCellStr != string.Empty && secondCellStr != string.Empty)
            {
                RefStringList = UnsortedExcelFile.ReadExcelRange(cell1Comps.prefix[0], cell1Comps.number, cell2Comps.prefix[0], cell2Comps.number);
            }
            else
            {
                SortedTextBox.Text = "Error, Invalid Entry";
            }

            //remove extra empty slots in list
            RefStringList = RefStringList.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();


            string QuantityCell, PartDescriptionCell, ManufacturerCell, ManufacturerPNCell;

            //find the cells that need to be copied and copy contents into strings

            if (Regex.IsMatch(QuantityCol, @"^[A-Z]+$"))
            {
                QuantityCell = UnsortedExcelFile.ReadCell(QuantityCol[0], cell1Comps.number);
            }
            else
            {
                QuantityCell = string.Empty;
            }

            if (Regex.IsMatch(PartDescriptionCol, @"^[A-Z]+$"))
            {
                PartDescriptionCell = UnsortedExcelFile.ReadCell(PartDescriptionCol[0], cell1Comps.number);
            }
            else
            {
                PartDescriptionCell = string.Empty;
            }

            if (Regex.IsMatch(ManufacturerCol, @"^[A-Z]+$"))
            {
                ManufacturerCell = UnsortedExcelFile.ReadCell(ManufacturerCol[0], cell1Comps.number);
            }
            else
            {
                ManufacturerCell = string.Empty;
            }

            if (Regex.IsMatch(ManufacturerPNCol, @"^[A-Z]+$"))
            {
                ManufacturerPNCell = UnsortedExcelFile.ReadCell(ManufacturerPNCol[0], cell1Comps.number);
            }
            else
            {
                ManufacturerPNCell = string.Empty;
            }

            if (QuantityCell == string.Empty &&
                PartDescriptionCell == string.Empty &&
                ManufacturerCell == string.Empty &&
                ManufacturerPNCell == string.Empty)
            {
                SortedTextBox.Text = "Invalid column entries.";
            }
            else
            {
                //print the copied contents into the new excel file in the correct columns
                SortedExcelFile.PasteCells(QuantityCell, PartDescriptionCell, ManufacturerCell, ManufacturerPNCell, rowCount, Convert.ToInt32(numericUpDownRowStart.Value));
                rowCount++;
            }
        }
Example #3
0
        public string Combine(RefComponents Temp)
        {
            string str = Temp.prefix + Temp.number.ToString();

            return(str);
        }