コード例 #1
0
ファイル: common.cs プロジェクト: lzk/windowVOP
        /// <summary> Get the support printer list.  </summary>
        /// <param name="listPrinters">Used to store the supported printers.</param>
        /// <returns> None. </returns>
        /// <remarks> If the port of printer isn't support, the printer will
        /// not store in the list. The printer in the list were sorted by
        /// name. The default printer will be the 1st element, if it is in the
        /// list.  </remarks>
        public static void GetSupportPrinters(List <string> listPrinters)
        {
            listPrinters.Clear();

            try
            {
                // If spooler was stopped, new PrintServer( null ) will throw
                // a exception.

                string strDefPrinter = "";

                PrinterSettings      settings      = new PrinterSettings();
                PrintServer          myPrintServer = new PrintServer(null);
                PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
                foreach (PrintQueue pq in myPrintQueues)
                {
                    PrintDriver queuedrv = pq.QueueDriver;
                    if (IsSupportPrinter(queuedrv.Name) == true)
                    {
                        if (EnumPortType.PT_UNKNOWN != (EnumPortType)dll.CheckPortAPI(pq.Name))
                        {
                            listPrinters.Add(pq.Name);
                        }
                    }
                    settings.PrinterName = pq.Name;
                    if (settings.IsDefaultPrinter)
                    {
                        strDefPrinter = pq.Name;
                    }
                }
            }
            catch
            {
            }
        }
コード例 #2
0
        private void GridPrint_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }
            if (e.ColumnIndex == 0)
            {
                int i = e.RowIndex;
                //SnEditEntity en = SnEditFactory.GetBySN(GridPrinting.Rows[j].Cells["colSn3"].Value.ToString());
                if (string.IsNullOrWhiteSpace(GridPrint.Rows[e.RowIndex].Cells["colSn"].Value as string))
                {
                    return;
                }

                string code  = "";
                string code1 = "";

                string str1 = "订单号:" + GridPrint.Rows[i].Cells["colOrderCode"].Value as string + " 工程:" + GridPrint.Rows[i].Cells["colProject"].Value as string;
                //string str2 = "   "+"间隔:" + en.TEMP1 + "   " + en.TEMP2;
                string str3 = "产品型号:" + GridPrint.Rows[i].Cells["colModel"].Value as string + " 产品系列:" + GridPrint.Rows[i].Cells["colSeries"].Value as string;
                //string str4 = "   "+"相序:" + en.TEMP3 + "   " + "备注一:" + en.TEMP4;
                // string str5 = "   "+"班组:" + en.TEAM_NAME + "    " + "备注二:" + en.TEMP5;
                string str6 = "SN:" + GridPrint.Rows[i].Cells["colSN"].Value as string;
                string str7 = "质检条码:" + GridPrint.Rows[i].Cells["colBarCode"].Value as string;



                StringBuilder project = new StringBuilder(10240);
                int           i1      = GETFONTHEX(str1, "宋体", "temp1", 0, 25, 15, 0, 0, project);
                //StringBuilder jg = new StringBuilder(10240);
                //int i2 = GETFONTHEX(str2, "宋体", "temp1", 10, 30, 20, 0, 0, jg);
                StringBuilder SO = new StringBuilder(10240);
                int           i3 = GETFONTHEX(str3, "宋体", "temp1", 0, 25, 15, 0, 0, SO);
                //StringBuilder xx = new StringBuilder(10240);
                //int i4 = GETFONTHEX(str4, "宋体", "temp1", 10, 30, 20, 0, 0, xx);
                //StringBuilder bz = new StringBuilder(10240);
                //int i5 = GETFONTHEX(str5, "宋体", "temp1", 10, 30, 20, 0, 0, bz);
                StringBuilder h  = new StringBuilder(10240);
                int           i6 = GETFONTHEX(str6, "宋体", "temp1", 0, 25, 15, 0, 0, h);

                StringBuilder bar = new StringBuilder(10240);
                int           i7  = GETFONTHEX(str7, "宋体", "temp1", 0, 25, 15, 0, 0, bar);


                if (string.IsNullOrEmpty(GridPrint.Rows[i].Cells["colBarCode"].Value as string))
                {
                    code1 = "^XA^FO200,65^BY2,2,50^BCN,100,N,N,N^FD" + GridPrint.Rows[i].Cells["colSN"].Value as string + "^FS" +
                            h.ToString() + "^MD30^LH120,10^FO100,165^XGtemp1,1,1^FS" +
                            project.ToString() + "^MD30^LH20,10^FO20,200^XGtemp1,1,1^FS" +
                            SO.ToString() + "^MD30^LH20,10^FO20,225^XGtemp1,1,1^FS" +
                            "^XZ";
                }
                else
                {
                    //code1 = "^XA^FO80,25^BY2,2,50^BCN,100,N,N,N^FD" + GridPrint.Rows[i].Cells["colSN"].Value as string + "^FS" +
                    //         h.ToString() + "^MD30^LH120,10^FO80,125^XGtemp1,1,1^FS" +
                    //         project.ToString() + "^MD30^LH30,10^FO20,160^XGtemp1,1,1^FS" +
                    //         SO.ToString() + "^MD30^LH30,10^FO20,185^XGtemp1,1,1^FS" +
                    //         "^FO80,225^BY2,2,50^BCN,100,N,N,N^FD" + GridPrint.Rows[i].Cells["colBarCode"].Value as string + "^FS" +
                    //         bar.ToString() + "^MD30^LH120,10^FO20,325^XGtemp1,1,1^FS" +
                    //         "^XZ";
                    code1 = "^XA^FO200,65^BY2,2,50^BCN,100,N,N,N^FD" + GridPrint.Rows[i].Cells["colSN"].Value as string + "^FS" +
                            h.ToString() + "^MD30^LH120,10^FO100,165^XGtemp1,1,1^FS" +
                            project.ToString() + "^MD30^LH20,10^FO50,240^XGtemp1,1,1^FS" +
                            SO.ToString() + "^MD30^LH20,10^FO50,265^XGtemp1,1,1^FS" +
                            "^FO50,305^BY2,2,50^BCN,100,N,N,N^FD" + GridPrint.Rows[i].Cells["colBarCode"].Value as string + "^FS" +
                            bar.ToString() + "^MD30^LH20,10^FO50,405^XGtemp1,1,1^FS" +
                            "^XZ";
                }

                DB.GetInstance().BeginTransaction();
                try
                {
                    PrintDriver.SendStringToPrinter("ZDesigner ZM400 200 dpi (ZPL)", code1);
                    string orderCode = GridPrint.Rows[i].Cells["colOrderCode"].Value as string;
                    DB.GetInstance().Execute("update DATA_PLAN_SN set SN_FLAG='P' where ORDER_CODE=@0", orderCode);
                    DB.GetInstance().CompleteTransaction();
                }
                catch (Exception ex)
                {
                    DB.GetInstance().AbortTransaction();
                    MessageBox.Show(ex.Message);
                }
                //initSnEdit();
            }
        }
コード例 #3
0
        private void UploadDiscreteDriver(DriverInf infFile, string driverName)
        {
            string discreteDriverRepo = GlobalSettings.Items[Setting.PrintDriverServer];

            PrintDriverPackage newDiscretePrintDriverPackage = new PrintDriverPackage();

            newDiscretePrintDriverPackage.Name = new DirectoryInfo(Path.GetDirectoryName(infFile.Location)).Name;

            //if this is a fax driver, ignore it
            if (driverName.Contains("fax", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
            {
                //if the driver package already exist just update the x86 or x64 driver inf file
                var discreteDriver = context.PrintDriverPackages.Include("PrintDrivers").FirstOrDefault(n => n.Name == newDiscretePrintDriverPackage.Name);

                if (discreteDriver != null)
                {
                    newDiscretePrintDriverPackage = discreteDriver;

                    if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTAMD64))
                    {
                        //passing only the path relative to the repository
                        newDiscretePrintDriverPackage.InfX64 = Path.Combine(newDiscretePrintDriverPackage.Name, Path.GetFileName(infFile.Location));
                    }

                    if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTx86))
                    {
                        //passing only the path relative to the repository
                        newDiscretePrintDriverPackage.InfX86 = Path.Combine(newDiscretePrintDriverPackage.Name, Path.GetFileName(infFile.Location));
                    }
                }
                else
                {
                    //this is a new upload, add the necessary details
                    newDiscretePrintDriverPackage.PrintDriverPackageId = SequentialGuid.NewGuid();

                    newDiscretePrintDriverPackage.InfX64 = string.Empty;
                    newDiscretePrintDriverPackage.InfX86 = string.Empty;

                    if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTAMD64))
                    {
                        //passing only the path relative to the repository
                        newDiscretePrintDriverPackage.InfX64 = Path.Combine(newDiscretePrintDriverPackage.Name, Path.GetFileName(infFile.Location));
                    }


                    if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTx86))
                    {
                        //passing only the path relative to the repository
                        newDiscretePrintDriverPackage.InfX86 = Path.Combine(newDiscretePrintDriverPackage.Name, Path.GetFileName(infFile.Location));
                    }

                    //the folder does not exist, add them up to the repository
                    if (Directory.Exists(Path.Combine(discreteDriverRepo, newDiscretePrintDriverPackage.Name)))
                    {
                        TraceFactory.Logger.Debug("Driver Package already exists");
                    }
                    else
                    {
                        //this will take sometime depending upon size of the driver package
                        FileSystem.CopyDirectory(Path.GetDirectoryName(infFile.Location), Path.Combine(discreteDriverRepo, newDiscretePrintDriverPackage.Name));
                    }


                    context.PrintDriverPackages.Add(newDiscretePrintDriverPackage);
                }

                PrintDriver newdiscreteDriver = null;

                newdiscreteDriver = context.PrintDrivers.FirstOrDefault(n => n.Name.Equals(driverName));
                if (newdiscreteDriver == null || !newdiscreteDriver.PrintDriverPackage.Name.EqualsIgnoreCase(newDiscretePrintDriverPackage.Name))
                {
                    newdiscreteDriver                    = new PrintDriver();
                    newdiscreteDriver.Name               = driverName;
                    newdiscreteDriver.PrintDriverId      = SequentialGuid.NewGuid();
                    newdiscreteDriver.PrintDriverPackage = newDiscretePrintDriverPackage;
                    newdiscreteDriver.PrintProcessor     = infFile.Drivers.FirstOrDefault().PrintProcessor;

                    context.PrintDrivers.Add(newdiscreteDriver);
                }
                context.SaveChanges();
            }
        }
コード例 #4
0
ファイル: common.cs プロジェクト: lzk/windowVOP
        /// <summary> Get the support printer list.  </summary>
        /// <param name="listPrinters">Used to store the supported printers.</param>
        /// <returns> None. </returns>
        /// <remarks> If the port of printer isn't support, the printer will
        /// not store in the list. The printer in the list were sorted by
        /// name. The default printer will be the 1st element, if it is in the
        /// list.  </remarks>
        public static void GetSupportPrinters(List <string> listPrinters)
        {
            listPrinters.Clear();

            try
            {
                // If spooler was stopped, new PrintServer( null ) will throw
                // a exception.

                string strDefPrinter = "";

                PrinterSettings      settings      = new PrinterSettings();
                PrintServer          myPrintServer = new PrintServer(null);
                PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
                foreach (PrintQueue pq in myPrintQueues)
                {
                    PrintDriver queuedrv = pq.QueueDriver;
                    if (IsSupportPrinter(queuedrv.Name) == true)
                    {
                        if (EnumPortType.PT_UNKNOWN != (EnumPortType)dll.CheckPortAPI(pq.Name))
                        {
                            listPrinters.Add(pq.Name);
                        }
                    }
                    settings.PrinterName = pq.Name;
                    if (settings.IsDefaultPrinter)
                    {
                        strDefPrinter = pq.Name;
                    }
                }

                // Store the printer name list
                for (int i = 0; i < listPrinters.Count; i++)
                {
                    for (int j = i + 1; j < listPrinters.Count; j++)
                    {
                        if (-1 == string.Compare(listPrinters[j], listPrinters[i]))
                        {
                            // swrap the value
                            string t = listPrinters[i];
                            listPrinters[i] = listPrinters[j];
                            listPrinters[j] = t;
                        }
                    }
                }

                // If the default printer is in the support list, make it the
                // 1st item.
                int index = listPrinters.FindIndex(
                    delegate(string s)
                {
                    return(s == strDefPrinter);
                }
                    );

                if (index != -1 && index != 0)
                {
                    listPrinters.RemoveAt(index);
                    listPrinters.Insert(0, strDefPrinter);
                }
            }
            catch
            {
            }
        }
コード例 #5
0
        /// <summary>
        /// Copis the specified print driver package to the environment and adds all necessary database entires to the database.
        /// </summary>
        /// <param name="drivers">The package to be added.</param>
        /// <param name="basePath">The path of the print driver package network store.</param>
        /// <param name="overwrite">if set to <c>true</c>, overwrite existing files.</param>
        /// <returns></returns>
        public static void AddToFrameworkRepository(this PrintDeviceDriverCollection drivers, string basePath, bool overwrite = false)
        {
            if (drivers == null)
            {
                throw new ArgumentNullException("drivers");
            }

            using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
            {
                var dbDriverPackage = GetDatabaseDriverPackage(context, drivers, basePath, overwrite);

                CopyDrivers(drivers, basePath);

                // Return a new instance of PrintDriverPackage that contains the correct INF file locations.
                PrintDeviceDriverCollection reloadedDrivers = LoadDrivers(Path.Combine(basePath, drivers.Version), basePath);

                // Get a distinct list of x86 and x64 INF paths joined by the common driver name
                var infPathQuery =
                    (
                        from d1 in reloadedDrivers
                        where d1.Architecture == DriverArchitecture.NTAMD64
                        join d2 in reloadedDrivers on d1.Name equals d2.Name into driverItems
                        from d3 in driverItems
                        where d3.Architecture == DriverArchitecture.NTx86
                        select new { x64Path = d1.InfPath, x86Path = d3.InfPath }
                    ).Distinct();

                // For each distinct combination of INF paths, create a new entry in the print driver package table.
                // NOTE: that for now if more than one row is added for the same version, this could be a problem
                // as the backend won't support it.  But the database will be fixed in the future to support
                // multiple entries.
                foreach (var item in infPathQuery)
                {
                    // Create new database entries for this print driver package.
                    dbDriverPackage = new PrintDriverPackage
                    {
                        PrintDriverPackageId = SequentialGuid.NewGuid(),
                        Name   = reloadedDrivers.Version,
                        InfX86 = TrimPath(item.x86Path, basePath),
                        InfX64 = TrimPath(item.x64Path, basePath)
                    };

                    context.PrintDriverPackages.Add(dbDriverPackage);

                    var driverQuery =
                        (
                            from d in reloadedDrivers
                            select new { d.Name, Processor = d.PrintProcessor.ToLowerInvariant() }
                        ).Distinct();

                    foreach (var properties in driverQuery)
                    {
                        var printDriver = new PrintDriver
                        {
                            PrintDriverId      = SequentialGuid.NewGuid(),
                            PrintDriverPackage = dbDriverPackage,
                            Name           = properties.Name,
                            PrintProcessor = properties.Processor
                        };
                        dbDriverPackage.PrintDrivers.Add(printDriver);
                    }
                }

                context.SaveChanges();
            }
        }
コード例 #6
0
        private PrintDriverPackage UpdateRepositoryDatabase(DriverInf infFile, string driverName, string packageVersion, AssetInventoryContext context)
        {
            string driverRepo = PrintDriversManager.DriverRepositoryLocation;

            PrintDriverPackage printDriverPackage = new PrintDriverPackage();

            printDriverPackage.Name = packageVersion;   //new DirectoryInfo(Path.GetDirectoryName(infFile.Location)).Name;

            //if the driver package already exists just update the x86 or x64 driver inf file
            PrintDriverPackage existingDriverPackage = context.PrintDriverPackages.Include("PrintDrivers").FirstOrDefault(n => n.Name == printDriverPackage.Name);

            if (existingDriverPackage != null)
            {
                printDriverPackage = existingDriverPackage;

                if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTAMD64))
                {
                    //passing only the path relative to the repository
                    printDriverPackage.InfX64 = Path.Combine(printDriverPackage.Name, Path.GetFileName(infFile.Location));
                }

                if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTx86))
                {
                    //passing only the path relative to the repository
                    printDriverPackage.InfX86 = Path.Combine(printDriverPackage.Name, Path.GetFileName(infFile.Location));
                }
            }
            else
            {
                //this is a new upload, add the necessary details
                printDriverPackage.PrintDriverPackageId = SequentialGuid.NewGuid();

                printDriverPackage.InfX64 = string.Empty;
                printDriverPackage.InfX86 = string.Empty;

                if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTAMD64))
                {
                    //passing only the path relative to the repository
                    printDriverPackage.InfX64 = Path.Combine(printDriverPackage.Name, Path.GetFileName(infFile.Location));
                }


                if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTx86))
                {
                    //passing only the path relative to the repository
                    printDriverPackage.InfX86 = Path.Combine(printDriverPackage.Name, Path.GetFileName(infFile.Location));
                }

                context.PrintDriverPackages.Add(printDriverPackage);
            }

            PrintDriver newPrintDriver = context.PrintDrivers.FirstOrDefault(n => n.Name.Equals(driverName));

            if (newPrintDriver == null || !newPrintDriver.PrintDriverPackage.Name.EqualsIgnoreCase(printDriverPackage.Name))
            {
                newPrintDriver                    = new PrintDriver();
                newPrintDriver.Name               = driverName;
                newPrintDriver.PrintDriverId      = SequentialGuid.NewGuid();
                newPrintDriver.PrintDriverPackage = printDriverPackage;
                newPrintDriver.PrintProcessor     = infFile.Drivers.FirstOrDefault().PrintProcessor;

                context.PrintDrivers.Add(newPrintDriver);
            }

            return(printDriverPackage);
        }