Exemple #1
0
        public SFPacket GetPrimaryOpData(string workOrder)
        {
            List <SFPacket> sfDataList = GetSFDataByOrdNo(workOrder);
            SFPacket        packetData = new SFPacket();

            foreach (SFPacket item in sfDataList)
            {
                if (!string.IsNullOrEmpty(item.item_no))
                {
                    packetData.item_no = item.item_no;
                }

                // get raw material
                if (item.oper_no == 0 && Helper.IsLike(item.comp_item_no, "A?????-????"))
                {
                    packetData.RawMaterial = item.comp_item_no;
                    packetData.PieceWeight = item.mat_qty_per_par;
                }

                if (Helper.IsLike(item.sfd_desc_1, "*PRIMARY*"))
                {
                    packetData.qty               = item.qty;
                    packetData.cyc_per           = item.cyc_per;
                    packetData.setup_std_lbr_hrs = item.setup_std_lbr_hrs;
                }
            }
            return(packetData);
        }
Exemple #2
0
        public static void popHydroProdSheet(string wbPath, SFPacket sfObj, bool isNewPath)
        {
            //Create COM Objects. Create a COM object for everything that is referenced
            Excel.Application xlApp       = new Excel.Application();
            Excel.Workbook    xlWorkbook  = xlApp.Workbooks.Open(wbPath);
            Excel._Worksheet  xlWorksheet = xlWorkbook.ActiveSheet;
            Excel.Range       xlClrRng;
            xlApp.Visible                    = true;
            xlApp.DisplayAlerts              = true;
            xlWorkbook.CheckCompatibility    = false;
            xlWorkbook.DoNotPromptForConvert = true;

            xlClrRng = xlWorksheet.Range["C6, C8, C10, J8, J10, K10, M4, M8, N10, X2"];

            foreach (Excel.Range c in xlClrRng.Cells)
            {
                if (c.MergeCells)
                {
                    c.MergeArea.ClearContents();
                }
                else
                {
                    c.ClearContents();
                }
            }

            //xlClrRng.ClearContents();
            if (sfObj.RawMaterial != null || sfObj.RawMaterial != "empty")
            {
                float barWeight = DataAccess.GetBarWeight(sfObj.RawMaterial);
                xlWorksheet.Range["N10"].Value = sfObj.RawMaterial;
                if (barWeight > 0)
                {
                    xlWorksheet.Range["M4"].Value = barWeight;
                }
            }



            xlWorksheet.Range["C6"].Value  = sfObj.item_no;
            xlWorksheet.Range["C8"].Value  = sfObj.ord_no;
            xlWorksheet.Range["C10"].Value = sfObj.qty;
            xlWorksheet.Range["J8"].Value  = (1 / sfObj.cyc_per) * 3600;
            //xlWorksheet.Range["M4"].Value = "TBD";
            xlWorksheet.Range["M8"].Value = sfObj.PieceWeight;
            //xlWorksheet.Range["N10"].Value = sfObj.RawMaterial;
            xlWorksheet.Range["X2"].Value = sfObj.setup_std_lbr_hrs;

            if (isNewPath)
            {
                wbPath = Helper.genNewProdSheetPath(sfObj.item_no);
                // create directory if it doesn't already exist
                System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(wbPath));
            }

            if (!System.IO.File.Exists(wbPath))
            {
                xlWorkbook.SaveAs(wbPath);
                DataAccess.InsertProdShtLoc(wbPath, sfObj.item_no);
            }
            else
            {
                xlWorkbook.Save();
            }

            xlWorkbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, @"C:\Dev\prodSheet18\temp\temp1.pdf", OpenAfterPublish: true);
            //cleanup
            GC.Collect();
            GC.WaitForPendingFinalizers();

            //rule of thumb for releasing com objects:
            //  never use two dots, all COM objects must be referenced and released individually
            //  ex: [somthing].[something].[something] is bad

            //release com objects to fully kill excel process from running in the background
            Marshal.ReleaseComObject(xlClrRng);
            Marshal.ReleaseComObject(xlWorksheet);

            //close and release
            xlWorkbook.Close();
            Marshal.ReleaseComObject(xlWorkbook);

            //quit and release
            xlApp.Quit();
            Marshal.ReleaseComObject(xlApp);
        }