コード例 #1
0
ファイル: Excel.cs プロジェクト: chigra1/PMC_Tool
        public BOM getInfoFromDatabaseforBomComponents(BOM bom, string column)
        {
            column = column + ":" + column;

            for (int i = 0; i < bom.item.Length; i++)
            {
                string item = bom.item[i].name;

                _Excel.Range colRange = ws.Columns[column];//get the range object where you want to search from

                _Excel.Range resultRange = colRange.Find(

                    What: item,

                    LookIn: _Excel.XlFindLookIn.xlValues,

                    LookAt: _Excel.XlLookAt.xlWhole,

                    SearchOrder: _Excel.XlSearchOrder.xlByRows,

                    SearchDirection: _Excel.XlSearchDirection.xlNext

                    );

                if (resultRange == null)
                {
                    //MessageBox.Show("Did not found " + item + " in column " + column.Substring(1));
                    Program.mainForm.addToErrorList = "Did not found " + item + " in Database file - column " + column.Substring(1);
                }

                else
                {
                    int row = resultRange.Row;

                    //ovo su podaci za taj item

                    if (ws.Cells[row, 28].Value2 == "HDT")
                    {
                        bom.item[i].HDTflag = true;
                        bom.numberOfHDTFlags++;
                    }

                    try//ako nije upisan mpq u stocku da bi preskocio null
                    {
                        bom.item[i].mpq = ws.Cells[row, 13].Value2;
                        if (bom.item[i].mpq == 0)
                        {
                            Program.mainForm.addToErrorList = "POQ is 0 for item: " + bom.item[i].name;
                        }
                    }
                    catch
                    {
                        Program.mainForm.addToErrorList = "POQ is not available for item: " + bom.item[i].name;
                    }

                    try//ako nije upisan moq u stocku da bi preskocio null
                    {
                        bom.item[i].moq = ws.Cells[row, 14].Value2;
                        if (bom.item[i].moq == 0)
                        {
                            Program.mainForm.addToErrorList = "MOQ is 0 for item: " + bom.item[i].name;
                        }
                    }
                    catch
                    {
                        Program.mainForm.addToErrorList = "MOQ is not available for item: " + bom.item[i].name;
                    }

                    try//ako nije upisan unit_price u stocku da bi preskocio null
                    {
                        bom.item[i].unit_price = ws.Cells[row, 17].Value2;
                        if (bom.item[i].unit_price == 0)
                        {
                            Program.mainForm.addToErrorList = "Unit price is 0 for item: " + bom.item[i].name;
                        }
                    }
                    catch
                    {
                        Program.mainForm.addToErrorList = "Unit price is not available for item: " + bom.item[i].name;
                    }

                    try//ako nije upisan Delivery Time u stocku da bi preskocio null
                    {
                        bom.item[i].delivery_time = (int)ws.Cells[row, 12].Value2;
                    }
                    catch
                    {
                        Program.mainForm.addToErrorList = "Delivery Time is not available for item: " + bom.item[i].name;
                    }

                    try//ako nije upisan description u stocku da bi preskocio null
                    {
                        bom.item[i].description = ws.Cells[row, 3].Value2.ToString();
                    }
                    catch
                    {
                        Program.mainForm.addToErrorList = "Description is not available for item: " + bom.item[i].name;
                    }
                    try//ako nije upisan chineseDescription da bi preskocio null
                    {
                        bom.item[i].chineseDescription = ws.Cells[row, 2].Value2.ToString();
                    }
                    catch
                    {
                        Program.mainForm.addToErrorList = "Chinese Description is not available for item: " + bom.item[i].name;
                    }
                    try//ako nije upisan dobavljac u stocku da bi preskocio null
                    {
                        bom.item[i].supplier = ws.Cells[row, 11].Value2.ToString();
                    }
                    catch
                    {
                        Program.mainForm.addToErrorList = "Supplier is not available for item: " + bom.item[i].name;
                    }
                }
            }

            return(bom);
        }
コード例 #2
0
ファイル: Excel.cs プロジェクト: chigra1/PMC_Tool
        public BOM CopyBOM(int MSmulti, string MSproduct, List <string> pcbaFilenames)
        {
            List <Assembly> assemblies = Program.mainForm.assemblies;

            int assembly_num = 0;
            //bool assembly = false;
            //MessageBox.Show( ws.UsedRange.Rows.Count.ToString());
            int number_of_rows = ws.UsedRange.Rows.Count;
            //MessageBox.Show(number_of_rows.ToString());
            //ukupan broj redova - 3
            int number_of_items = number_of_rows - 3;

            BOM bom = new BOM(number_of_items);

            for (int i = 4, z = 0; i <= number_of_rows; i++, z++)
            {
                bom.item[z].name    = ws.Cells[i, 2].Value2.ToString();
                bom.item[z].product = MSproduct;
                try//ako nije upisana kolicina u bomum da bi preskocio null
                {
                    bom.item[z].bomqty = Math.Round(ws.Cells[i, 6].Value2 * MSmulti, 1);
                }
                catch
                {
                    //MessageBox.Show("Component " + bom.item[z].name + " value in BOM is null!");
                    Program.mainForm.addToErrorList = bom.item[z].name + " value in BOM " + MSproduct + " is null!";
                }

                //for (int j = 0; j < pcbaFilenames.Count; j++)
                //{
                //    if (pcbaFilenames[j] == bom.item[z].name)
                //    {
                //        assemblies.Add(new Assembly(bom.item[z].name));
                //        assembly_num = assemblies.Count - 1;
                //        assemblies[assembly_num].ms_quantity = MSmulti;
                //    }
                //}


                if (i <= number_of_rows && i > 4)
                {
                    int level          = Convert.ToInt32(ws.Cells[i, 1].Value2.Replace(".", string.Empty));
                    int next_row_level = 0;
                    if (i < number_of_rows)
                    {
                        next_row_level = Convert.ToInt32(ws.Cells[i + 1, 1].Value2.Replace(".", string.Empty));
                    }


                    if (next_row_level > level)
                    {
                        int redni_br = SearchIfAssemblyExists(bom.item[z].name);
                        if (redni_br == -1)
                        {
                            assemblies.Add(new Assembly(bom.item[z].name));
                            assembly_num = assemblies.Count - 1;
                            //assembly = true;
                            assemblies[assembly_num].ms_quantity = MSmulti;
                            assemblies[assembly_num].row         = i;
                            assemblies[assembly_num].level       = level;
                            int sledeci_item = 1;

                            while (assemblies[assembly_num].level < Convert.ToInt32(ws.Cells[i + sledeci_item, 1].Value2.Replace(".", string.Empty)))
                            {
                                if (Convert.ToInt32(ws.Cells[i + sledeci_item, 1].Value2.Replace(".", string.Empty)) == assemblies[assembly_num].level + 1)
                                {
                                    assemblies[assembly_num].AddItem(ws.Cells[i + sledeci_item, 2].Value2, ws.Cells[i + sledeci_item, 6].Value2);
                                }
                                sledeci_item++;
                                if (i + sledeci_item > number_of_rows)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            assemblies[redni_br].ms_quantity += MSmulti;
                        }
                    }

                    //else if (next_row_level < level && assembly == true)
                    //{
                    //    assemblies[assembly_num].AddItem(bom.item[z].name, ws.Cells[i, 6].Value2);
                    //    assembly = false;
                    //}
                    //else
                    //{
                    //    if (assembly == true)
                    //    {
                    //        assemblies[assembly_num].AddItem(bom.item[z].name, ws.Cells[i, 6].Value2);
                    //    }

                    //}
                }
            }
            return(bom);
        }