Exemple #1
0
        public Masterschedule CopyMasterschedule()
        {
            int number_of_rows = ws.UsedRange.Rows.Count;

            int number_of_items = number_of_rows - 8;

            //search "Product" and "Qty" column
            int number_of_columns = ws.UsedRange.Columns.Count;
            int productcolumn     = 6;
            int quantitycolumn    = 9;

            for (int i = 1; i <= number_of_columns; i++)
            {
                string temp = null;
                try
                {
                    temp = ws.Cells[8, i].Value.ToString();
                }
                catch { }
                if (temp != null)
                {
                    if (temp.Contains("Product"))
                    {
                        productcolumn = i;
                    }
                    if (temp.Contains("Qty."))
                    {
                        quantitycolumn = i;
                    }
                }
            }

            Masterschedule mstemp = new Masterschedule(number_of_items);//init strukture, pre je bilo numberOfMP

            //ponovo vrtimo da upisemo samo "Material purchase"
            for (int i = 0, z = 0, j = 9; i < number_of_items; i++, j++)
            {
                try
                {
                    //if (ws.Cells[j, 14].Value2.ToString() == "Material purchase")
                    //{
                    mstemp.item[z].product = ws.Cells[j, productcolumn].Value.ToString();         //changed from 7 to 6. deleted column B. 20.03.2022
                    //mstemp.item[z].status = ws.Cells[j, 14].Value2.ToString();
                    mstemp.item[z].quantity = Convert.ToInt32(ws.Cells[j, quantitycolumn].Value); //changed from 10 to 9 deleted column B. 20.03.2022
                    z++;
                    //}
                }
                catch
                {
                    MessageBox.Show("For item in row " + j.ToString() + " there is a null value for product name or quantity", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            return(mstemp);
        }
Exemple #2
0
        private void LoadMasterSchedule()
        {
            path = AppDomain.CurrentDomain.BaseDirectory + @"MasterSchedule\Masterschedule.xlsx";
            Excel excel = new Excel(path, 1);

            ms = excel.CopyMasterschedule();//kopiranje u strukturu MS samo onih sto imaju status "Material purchase"


            path = AppDomain.CurrentDomain.BaseDirectory + @"BOMs\";

            //proveravanje da li postoji BOM u stukturi i sabiranje istih
            for (int i = 0; i < ms.item.Length; i++)
            {
                int redniBroj = SearchIfBOMExistsInList(i);
                if (redniBroj == -1)
                {
                    MSproductName.Add(ms.item[i].product);
                    MSproductQty.Add(ms.item[i].quantity);
                    //MSproductStatus.Add(ms.item[i].status);
                }
                else
                {
                    MSproductQty[redniBroj] = ms.item[i].quantity + (int)MSproductQty[redniBroj];
                }
            }
            ms = new Masterschedule(MSproductName.Count);// vracanje liste u ms strukturu
            for (int z = 0; z < MSproductName.Count; z++)
            {
                try
                {
                    ms.item[z].product  = MSproductName[z].ToString();
                    ms.item[z].quantity = Convert.ToInt32(MSproductQty[z]);
                    //ms.item[z].status = MSproductStatus[z].ToString();
                }
                catch
                { }
            }
            MSproductName   = new List <object>();
            MSproductQty    = new List <object>();
            MSproductStatus = new List <object>();
            /////////////////////////////////////////


            //proveravanje da li postoji BOM u folderu i ubacivanje u novu listu
            for (int i = 0; i < ms.item.Length; i++)
            {
                string fullPathBOM = path + ms.item[i].product + ".xls";
                if (File.Exists(fullPathBOM) == false)
                {
                    Errors.Add("There is no " + ms.item[i].product + ".xls in BOMs folder!");
                    ms.item[i].found = false;
                }
                else
                {
                    MSproductName.Add(ms.item[i].product);
                    MSproductQty.Add(ms.item[i].quantity);
                    MSproductStatus.Add(ms.item[i].status);
                    ms.item[i].found = true;
                }
            }

            //ispis u datagridview pronadjenih i nepronadjenih bomova
            WriteToMasterScheduleDataGridView();


            /////////////////////////////////////
            ms = new Masterschedule(MSproductName.Count);// vracanje liste u ms strukturu samo pronadjenih bomova
            for (int z = 0; z < MSproductName.Count; z++)
            {
                ms.item[z].product  = MSproductName[z].ToString();
                ms.item[z].quantity = Convert.ToInt32(MSproductQty[z]);
                //ms.item[z].status = MSproductStatus[z].ToString();
                ms.item[z].found = true;
            }

            //ispis koliko ima pronadjenih bomova
            lbFoundBoms.Text = lbFoundBoms.Text + ms.item.Length.ToString();

            excel.Dispose();
        }