コード例 #1
0
        public bool SavePrtToWorkbook(Workbook workbook, SldAsm asmPrd)
        {
            if (asmPrd.sldPrtList.Count <= 0 && asmPrd.sldStdList.Count <= 0 && asmPrd.sldBuyList.Count <= 0)
            {
                return(true);
            }
            int count       = asmPrd.sldPrtList.Count;
            int perPageSize = WiseUtil.prtPageSize;//
            int pageSize    = count / perPageSize + (count % perPageSize > 0 ? 1 : 0);

            bool insHead = true;

            //空行
            if (insHead)
            {
                SldPrt prt = new SldPrt();
                asmPrd.sldPrtList.Insert(0, prt);
                count++;
            }
            if (insHead)//插组件
            {
                SldPrt prt = new SldPrt();
                prt.name   = asmPrd.name;
                prt.number = asmPrd.number;
                prt.amout  = 1;
                asmPrd.sldPrtList.Insert(0, prt);
                count++;
            }
            //空行
            if (insHead)
            {
                SldPrt prt = new SldPrt();
                asmPrd.sldPrtList.Insert(0, prt);
                count++;
            }
            if (insHead && asmPrd.sldStdList.Count > 0)
            {
                SldPrt prt = new SldPrt();
                prt.name = WiseUtil.stdStr;
                int thisCount = asmPrd.sldStdList.Count;
                prt.amout = thisCount / WiseUtil.stdPageSize + (thisCount % WiseUtil.stdPageSize > 0 ? 1 : 0);
                asmPrd.sldPrtList.Insert(0, prt);
                count++;
            }
            if (insHead && asmPrd.sldBuyList.Count > 0)
            {
                SldPrt prt = new SldPrt();
                prt.name = WiseUtil.buyStr;
                int thisCount = asmPrd.sldBuyList.Count;
                prt.amout = thisCount / WiseUtil.buyPageSize + (thisCount % WiseUtil.buyPageSize > 0 ? 1 : 0);
                asmPrd.sldPrtList.Insert(0, prt);
                count++;
            }
            //最初count
            if (insHead && asmPrd.sldPrtList.Count > 0)
            {
                SldPrt prt = new SldPrt();
                prt.name = WiseUtil.prtStr;

                count++;//先加一个

                pageSize  = count / WiseUtil.prtPageSize + (count % prtPageSize > 0 ? 1 : 0);
                prt.amout = pageSize;
                asmPrd.sldPrtList.Insert(0, prt);
            }


            pageSize = count / perPageSize + (count % perPageSize > 0 ? 1 : 0);


            int rowStartIndex = 4;

            Sheets    sheets    = workbook.Worksheets;
            Worksheet worksheet = (Worksheet)sheets.get_Item(WiseUtil.prtStr);

            if (count <= 0)
            {
                worksheet.Delete();
                return(false);
            }
            List <SldPrt> .Enumerator iEnum = asmPrd.sldPrtList.GetEnumerator();
            Worksheet nextWorksheet         = null;

            for (int pageIndex = 0; pageIndex < pageSize; pageIndex++)
            {
                if (pageIndex < pageSize - 1)//最后一个不能再复制了,写sheet前复制,保证模板未被写
                {
                    worksheet.Copy(Type.Missing, worksheet);
                    nextWorksheet = worksheet.Next;
                }
                Range dyn = worksheet.Cells.get_Item("31", "A");// worksheet.Cells.get_Item("25", "A").set_Value(asmPrd.ztdm);
                worksheet.Range["A25"].Value = asmPrd.ztdm;
                worksheet.Range["A31"].Value = asmPrd.zjdm;
                worksheet.Range["E30"].Value = asmPrd.bzr;
                worksheet.Range["H30"].Value = asmPrd.bzsj;
                worksheet.Range["E31"].Value = asmPrd.pzr;
                worksheet.Range["H31"].Value = asmPrd.pzsj;
                worksheet.Range["K23"].Value = asmPrd.name;
                if (asmPrd.jdbj.IndexOf("S") >= 0)
                {
                    worksheet.Range["K29"].Value = "S";
                }
                else if (asmPrd.jdbj.IndexOf("A") >= 0)
                {
                    worksheet.Range["M29"].Value = "A";
                }
                else if (asmPrd.jdbj.IndexOf("B") >= 0)
                {
                    worksheet.Range["O29"].Value = "B";
                }
                else
                {
                    worksheet.Range["R29"].Value = asmPrd.jdbj;
                }
                worksheet.Range["K31"].Value = "共 " + pageSize + " 页";
                worksheet.Range["S31"].Value = "第 " + (pageIndex + 1) + " 页";
                worksheet.Range["W31"].Value = asmPrd.sbxh;
                int row = 0;
                while (iEnum.MoveNext())
                {
                    SldPrt prt        = iEnum.Current;
                    int    totalIndex = row + rowStartIndex;
                    worksheet.Range["B" + totalIndex].Value  = prt.materialNumber;
                    worksheet.Range["E" + totalIndex].Value  = prt.number;
                    worksheet.Range["J" + totalIndex].Value  = prt.name;
                    worksheet.Range["O" + totalIndex].Value  = prt.amout == 0 ? "" : prt.amout.ToString();
                    worksheet.Range["Q" + totalIndex].Value  = prt.material;
                    worksheet.Range["S" + totalIndex].Value  = prt.weight == 0 ? "" : prt.weight.ToString();
                    worksheet.Range["T" + totalIndex].Value  = prt.totalWeight == 0 ? "" : prt.totalWeight.ToString();
                    worksheet.Range["U" + totalIndex].Value  = prt.rawWeight == 0 ? "" : prt.rawWeight.ToString();
                    worksheet.Range["V" + totalIndex].Value  = prt.route;
                    worksheet.Range["AC" + totalIndex].Value = prt.remark;

                    row++;
                    if (row >= WiseUtil.prtPageSize)
                    {
                        break;
                    }
                }

                worksheet = nextWorksheet;
            }
            return(true);
        }
コード例 #2
0
        public SldBsp GetSldPrdInfoFromFile(IEdmVault5 poVault, string filePath)
        {
            IEdmFolder5 opParentFolder;
            //bspPrt = new SldBuy();
            IEdmFile5 poFile = poVault.GetFileFromPath(filePath, out opParentFolder);

            if (poFile == null)
            {
                return(null);
            }
            IEdmEnumeratorVariable5 enumVar = poFile.GetEnumeratorVariable();

            if (enumVar == null)
            {
                return(null);
            }
            IEdmVariableMgr5 varMgr = (IEdmVariableMgr5)poVault;

            if (varMgr == null)
            {
                return(null);
            }

            object tmpVar;
            string partType = "";

            if (varMgr.GetVariable("Part Type") != null && enumVar.GetVar("Part Type", "@", out tmpVar) && tmpVar != null)
            {
                partType = tmpVar.ToString();
            }
            if (partType == "自制件")
            {
                SldPrt prt = new SldPrt();
                prt.type = 1;
                object route = null;
                if (varMgr.GetVariable("工艺路线") != null)
                {
                    if (enumVar.GetVar("工艺路线", "@", out route) && route != null)
                    {
                        prt.route = route.ToString();
                    }
                }

                return(prt);
            }
            else if (partType == "标准件")
            {
                SldStd std = new SldStd();
                std.type = 2;
                return(std);
            }
            else if (partType == "外购件")
            {
                SldBuy buy = new SldBuy();
                buy.type = 3;
                return(buy);
            }
            else
            {
                SldBsp buy = new SldBsp();
                buy.type = 4;
                return(buy);
            }
        }