Exemple #1
0
        private void SwitchToPrinter(PrinterInfo printerInfo)
        {
            // Switch to new printer
            PrinterDetails.SwitchPrinters(printerInfo.ID);

            this.DialogWindow.CloseOnIdle();
        }
Exemple #2
0
        /// <summary>
        /// DropDownForPrinter
        /// Calls [usp_dropdown_PrinterAll]
        /// </summary>
        public override List <PrinterDetails> DropDownForPrinter(System.Int32?clientId)
        {
            SqlConnection cn  = null;
            SqlCommand    cmd = null;

            try {
                cn                 = new SqlConnection(this.ConnectionString);
                cmd                = new SqlCommand("usp_dropdown_PrinterAll", cn);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 30;
                cmd.Parameters.Add("@ClientId", SqlDbType.Int).Value = clientId;
                cn.Open();
                DbDataReader          reader = ExecuteReader(cmd);
                List <PrinterDetails> lst    = new List <PrinterDetails>();
                while (reader.Read())
                {
                    PrinterDetails obj = new PrinterDetails();
                    obj.PrinterId   = GetReaderValue_Int32(reader, "PrinterId", 0);
                    obj.PrinterName = GetReaderValue_String(reader, "PrinterName", "");
                    lst.Add(obj);
                    obj = null;
                }
                return(lst);
            } catch (SqlException sqlex) {
                //LogException(sqlex);
                throw new Exception("Failed to get Printers", sqlex);
            } finally {
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }
        }
Exemple #3
0
        /// <summary>
        /// Call [usp_selectAll_Printer_for_Client]
        /// </summary>
        /// <param name="clientId"></param>
        /// <returns></returns>
        public override List <PrinterDetails> GetListForClient(System.Int32?clientId)
        {
            SqlConnection cn  = null;
            SqlCommand    cmd = null;

            try
            {
                cn                 = new SqlConnection(this.ConnectionString);
                cmd                = new SqlCommand("usp_selectAll_Printer_for_Client", cn);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 30;
                cmd.Parameters.Add("@ClientId", SqlDbType.Int).Value = clientId;
                cn.Open();
                DbDataReader          reader = ExecuteReader(cmd);
                List <PrinterDetails> lst    = new List <PrinterDetails>();
                while (reader.Read())
                {
                    PrinterDetails obj = new PrinterDetails();
                    obj.PrinterId          = GetReaderValue_Int32(reader, "PrinterId", 0);
                    obj.PrinterName        = GetReaderValue_String(reader, "PrinterName", "");
                    obj.PrinterDescription = GetReaderValue_String(reader, "PrinterDescription", "");
                    obj.Inactive           = GetReaderValue_Boolean(reader, "Inactive", false);
                    obj.ClientNo           = GetReaderValue_Int32(reader, "ClientNo", 0);
                    obj.UpdatedBy          = GetReaderValue_Int32(reader, "UpdatedBy", 0);
                    obj.DLUP = GetReaderValue_DateTime(reader, "DLUP", DateTime.MinValue);
                    lst.Add(obj);
                    obj = null;
                }
                return(lst);
            }
            catch (SqlException sqlex)
            {
                //LogException(sqlex);
                throw new Exception("Failed to get Printers", sqlex);
            }
            finally
            {
                cmd.Dispose();
                cn.Close();
                cn.Dispose();
            }
        }
Exemple #4
0
        public virtual void PrintVouchersInternal(int allocationId, List <int> voucherNumbers)
        {
            try
            {
                if (string.IsNullOrEmpty(m_PrinterName))
                {
                    throw new ArgumentNullException("PrinterName", "Value can not be null or empty");
                }

                if (string.IsNullOrEmpty(m_ReportType2))
                {
                    throw new ArgumentNullException("ReportType2", "Value can not be null or empty");
                }

                if (string.IsNullOrEmpty(m_PrinterXmlFilePath))
                {
                    throw new ArgumentNullException("PrinterXmlFilePath", "Value can not be null or empty");
                }

                if (!File.Exists(m_PrinterXmlFilePath))
                {
                    throw new IOException("Can not find file");
                }

                AllocationId = allocationId;

                lock (this)
                {
                    while (ms_VPItems.IndexOf(this) != 0)
                    {
                        Monitor.Wait(this, 3000);
                    }
                }

                Printing = new VoucherNumberingAllocationPrinting.VoucherNumberingAllocationPrinting();
                Manager  = new PartyManagement.PartyManagement();

                Allocation = new Func <int, VoucherAllocation>((x) => Printing.RetrieveAllocation(x)).ReTry(allocationId);

                if (Allocation == null)
                {
                    throw new ArgumentNullException("Can not get allocation:".concat(allocationId));
                }

                Retailer = new Func <int, int, Retailer>((x, y) => Manager.RetrieveRetailerDetail(x, y)).ReTry(Allocation.CountryId, Allocation.RetailerId);

                if (Retailer == null)
                {
                    throw new ArgumentNullException("Can not find retailer:".concat(" CountryId: ", Allocation.CountryId, " RetailerId: ", Allocation.RetailerId));
                }

                Office = new Func <int, int, PtfOffice>((x, y) => Manager.RetrievePtfOfficeDetail(x, y)).ReTry(Retailer.CountryId, Retailer.PrinterBranchId);

                if (Office == null)
                {
                    throw new ArgumentNullException("Can not get office:".concat(" CountryId: ", Allocation.CountryId, " PrinterBranchId:", Retailer.PrinterBranchId));
                }

                var guid = CommTools.ToGuid(Allocation.CountryId, Allocation.RetailerId);

                PrinterDetails printer = null;
                CacheManager.Instance.Get <PrinterDetails>(guid, out printer,
                                                           () => new Func <int, int, PrinterDetails>((x, y) => Manager.GetPrinterInfo(x, y)).ReTry(Retailer.CountryId, Allocation.RetailerId));

                if (printer == null || printer.IsEmpty || UseLocalFormat)
                {
                    printer = new PrinterDetails
                    {
                        Name       = "Default",
                        Path       = m_PrinterName,
                        Type2      = m_ReportType2,
                        Xml        = File.ReadAllText(m_PrinterXmlFilePath),
                        IsoID      = Retailer.CountryId,
                        RetailerID = Allocation.RetailerId,
                    };
                }

                if (UseLocalPrinter)
                {
                    printer.Path = m_PrinterName;
                }

                #region LOCAL PRINTER
                //if (!PrintManager.GetInstalledPrinters().Contains(printer.Path, StringComparer.InvariantCultureIgnoreCase))
                //    throw new ApplicationException("Can not find printer ".concat(printer.Path));
                #endregion

                int countryId = Allocation.CountryId;

                InitPrinter("Initialization_".concat(Retailer.Name, DateTime.Now.Ticks));

                RangeFrom = Allocation.RangeFrom / 10;
                RangeTo   = Allocation.RangeTo / 10;

                //  VPrinting.Documents.VoucherPrintLayout250
                Type documentType = Type.GetType(printer.Type2);
                if (documentType == null)
                {
                    throw new ArgumentNullException("documentType", "Can not find type of: ".concat(printer.Type2));
                }

                XmlSerializer formatter = new XmlSerializer(documentType);
                var           layout    = formatter.ToObject <IVoucherLayout>(printer.Xml);
                if (layout == null)
                {
                    throw new ArgumentNullException("layout", "Can not create layout from xml");
                }
                layout.Init();

                CacheManager.Instance.Table[Strings.IVoucherLayout] = layout;

                CacheManager.Instance.Table[Strings.SubRangeFrom] = RangeFrom;

                var multyLines = new Queue <IList <IPrintLine> >();

                int index = 0;

                foreach (int voucher in voucherNumbers)
                {
                    CacheManager.Instance.Table[Strings.Index] = index++;

                    VoucherNo = voucher;

                    //Counting starts from 1 for us.
                    StrVoucherNo = new Func <int, int, bool, string>((x, y, z) => Printing.CreateVoucherNumber(x, y, z)).ReTry(countryId, voucher, false);

                    layout.Clear();
                    layout.DataBind(this, StrVoucherNo, voucher, false);

                    for (int count = 0; count < Repeat[countryId]; count++)
                    {
#if DEBUGGER
                        Debug.WriteLine(string.Format("{0}\t{1}\t{2}", countryId, Retailer.Name, voucher), Strings.VRPINT);
#endif

                        multyLines.Enqueue(new List <IPrintLine>(layout.PrintLines));
                        if (!SimulatePrint && !MultyPagePrint)
                        {
                            layout.PrintVouchers(printer.Path, StrVoucherNo, layout.FormLength, layout.DocumentInitialization, multyLines);
                        }

                        if (Test != null)
                        {
                            Test(this, EventArgs.Empty);
                        }

                        if (PrintOnce)
                        {
                            break;
                        }
                    }

                    if (PrintOnce)
                    {
                        break;
                    }
                }

                if (!SimulatePrint && MultyPagePrint && multyLines.Count > 0)
                {
                    layout.PrintVouchers(printer.Path, Strings.VRPINT, layout.FormLength, layout.DocumentInitialization, multyLines);
                }

                if (!SimulatePrint)
                {
                    new Action <int, int, int>((x, y, z) => Printing.LogVoucherAllocationPrinted(x, y, z)).ReTry(allocationId, Program.currentUser.UserID, Program.currentUser.CountryID);
                    new Action <int, bool, int>((x, y, z) => Printing.SetVoucherAllocationPrinted(x, y, z)).ReTry(allocationId, true, Program.currentUser.UserID);
                }
                //set the printed status to true
            }
            catch (Exception ex)
            {
                if (Error != null)
                {
                    Error(this, new ThreadExceptionEventArgs(ex));
                }
            }
            finally
            {
                if (Done != null)
                {
                    Done(this, EventArgs.Empty);
                }
            }
        }
Exemple #5
0
        public HardwareTabPage(ThemeConfig theme)
        {
            this.theme   = theme;
            this.Padding = 0;
            this.AnchorAll();

            var allControls = new FlowLayoutWidget(FlowDirection.TopToBottom);

            var horizontalSplitter = new Splitter()
            {
                SplitterDistance   = UserSettings.Instance.LibraryViewWidth,
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground
            };

            horizontalSplitter.AnchorAll();

            horizontalSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = horizontalSplitter.SplitterDistance;
            };

            allControls.AddChild(horizontalSplitter);

            treeView = new InventoryTreeView(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Width   = 300,
                Margin  = 5
            };

            treeView.NodeMouseDoubleClick += (s, e) =>
            {
                if (e is MouseEventArgs mouseEvent &&
                    s is GuiWidget clickedWidget &&
                    mouseEvent.Button == MouseButtons.Left &&
                    mouseEvent.Clicks == 2)
                {
                    if (treeView?.SelectedNode.Tag is PrinterInfo printerInfo)
                    {
                        // Open printer
                        PrinterDetails.SwitchPrinters(printerInfo.ID);
                    }
                }
            };

            treeView.NodeMouseClick += (s, e) =>
            {
                if (e is MouseEventArgs mouseEvent &&
                    s is GuiWidget clickedWidget &&
                    mouseEvent.Button == MouseButtons.Right)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        var menu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                        var openMenuItem    = menu.CreateMenuItem("Open".Localize());
                        openMenuItem.Click += (s2, e2) =>
                        {
                            if (treeView?.SelectedNode.Tag is PrinterInfo printerInfo)
                            {
                                // Open printer
                                PrinterDetails.SwitchPrinters(printerInfo.ID);
                            }
                        };

                        menu.CreateHorizontalLine();

                        var deleteMenuItem    = menu.CreateMenuItem("Delete".Localize());
                        deleteMenuItem.Click += (s2, e2) =>
                        {
                            // Delete printer
                            StyledMessageBox.ShowMessageBox(
                                (deletePrinter) =>
                            {
                                if (deletePrinter)
                                {
                                    if (treeView.SelectedNode.Tag is PrinterInfo printerInfo)
                                    {
                                        ProfileManager.Instance.DeletePrinter(printerInfo.ID, true);
                                    }
                                }
                            },
                                "Are you sure you want to delete your currently selected printer?".Localize(),
                                "Delete Printer?".Localize(),
                                StyledMessageBox.MessageType.YES_NO,
                                "Delete Printer".Localize());
                        };


                        var systemWindow = this.Parents <SystemWindow>().FirstOrDefault();
                        systemWindow.ShowPopup(
                            new MatePoint(clickedWidget)
                        {
                            Mate    = new MateOptions(MateEdge.Left, MateEdge.Top),
                            AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
                        },
                            new MatePoint(menu)
                        {
                            Mate    = new MateOptions(MateEdge.Left, MateEdge.Top),
                            AltMate = new MateOptions(MateEdge.Right, MateEdge.Top)
                        },
                            altBounds: new RectangleDouble(mouseEvent.X + 1, mouseEvent.Y + 1, mouseEvent.X + 1, mouseEvent.Y + 1));
                    });
                }
            };

            treeView.ScrollArea.HAnchor = HAnchor.Stretch;

            treeView.AfterSelect += async(s, e) =>
            {
                if (treeView.SelectedNode.Tag is PrinterInfo printerInfo)
                {
                    horizontalSplitter.Panel2.CloseAllChildren();
                    horizontalSplitter.Panel2.AddChild(new PrinterDetails(printerInfo, theme)
                    {
                        HAnchor = HAnchor.MaxFitOrStretch,
                        VAnchor = VAnchor.Stretch,
                        Padding = theme.DefaultContainerPadding
                    });
                }
            };
            horizontalSplitter.Panel1.AddChild(treeView);

            horizontalSplitter.Panel2.AddChild(new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            });

            allControls.AnchorAll();

            this.AddChild(allControls);
        }