示例#1
0
        private void ViewProductForm_Load(object sender, EventArgs e)
        {
            try
            {
                if (WorkMode.ProductsScan == _mode)
                {
                    if (BTPrintClass.PrintClass.ConnToPrinter(Program.Settings.TypedSettings[0].BTPrinterAddress)
                        != Calib.BluetoothLibNet.Def.BTERR_CONNECTED)
                    {

                        if (Program.Default.EnableWorkWOPrinter == 1)
                        {

                            using (BTConnectionErrorForm frm =
                                new BTConnectionErrorForm())
                            {
                                if (frm.ShowDialog() == DialogResult.Yes)
                                {
                                    BTPrintClass.PrintClass.Reconnect();
                                }
                                else
                                {
                                    this.Close();
                                    return;
                                }

                            }
                        }
                        else
                        {
                            this.Close();
                            return;
                        }
                    }
                    //ActionsClass.Action.BeginScan();


                }
                //ActionsClass.Action.BeginScan();
                ScanClass.Scaner.InitScan();

                /*
                foreach (Control c in this.Controls)
                {
                    c.GotFocus += new EventHandler(c_GotFocus);
                    c.LostFocus += new EventHandler(c_LostFocus);
                }*/
                /*this.textBox1.Focus();*/
                //System.Threading.Thread t = new System.Threading.Thread(
                //    new System.Threading.ThreadStart(Init));
                //t.Start();
                this.SuspendLayout();
                int w = this.Width / 4;
                this.label13.Width = w;
                this.label14.Width = w;
                this.label15.Width = w;
                this.navCodeTB.Focus();


                ScanClass.Scaner.OnScanned += new Scanned(Scanned);

                label5.Text = "";
                label6.Text = "";
                label7.Text = "";
                label8.Text = "";
                label9.Text = "";
                label17.Text = "";
                label20.Text = "";
                label21.Text = "";
                actionLabel.Text = "";
                navCodeTB.Text = "";
                Font f = this.actionLabel.Font;
                normalFont = f;
                System.Drawing.Font f1 =
                    new Font(f.Name, f.Size, FontStyle.Bold);
                boldFont = f1;

                this.actionLabel.Font = boldFont;
                this.ResumeLayout(true);



                ActionsClass.Action.OnActionCompleted += new ActionsClass.ActionCompleted(Action_OnActionCompleted);


                BTPrintClass.PrintClass.OnSetStatus += new SetStatus(PrintClass_OnSetStatus);
                BTPrintClass.PrintClass.OnSetError += new SetError(PrintClass_OnSetError);
                BTPrintClass.PrintClass.OnConnectionError += new ConnectionError(PrintClass_OnConnectionError);

                this.Refresh();
            }
            finally
            {
                _mEvt.Set();
            }

            //if (_mode ==
            //    WorkMode.ReturnBoxWProducts)
            //{
            //    //SearchBarcode(returnBoxScannedBarcode);
            //}

        }
示例#2
0
        void PrintClass_OnConnectionError()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    ConnectionError del = new ConnectionError(PrintClass_OnConnectionError);
                    this.Invoke(del);
                }
                else
                {
                    if (WorkMode.ProductsScan == _mode)
                    {
                        using (BTConnectionErrorForm frm =
                            new BTConnectionErrorForm())
                        {
                            if (frm.ShowDialog() == DialogResult.Yes)
                            {
                                BTPrintClass.PrintClass.Reconnect();
                            }

                        }
                    }

                }
            }
            catch (ObjectDisposedException)
            { }
        }
示例#3
0
        public bool PrintLabel(ProductsDataSet.ProductsTblRow datarow,  ProductsDataSet.DocsTblRow docRow, uint shablonCode)
        {
            int counter = 0;
            try
            {
                tryagain:
                if (btPrint.mEvt.WaitOne(Program.Default.WaitPrintTimeDefault, false) == false)
                {
                    counter++;
                    btPrint.SetStatusEvent("Ожидание очереди печати {0} попытка...",counter);
                    if (counter < 5)
                        goto tryagain;
                }

                string fileContent = string.Empty;
                int fileLength = 0;
                byte[] bArray = null;
                //uint shablonCode = TSDUtils.ActionCodeDescription.ActionDescription.GetShablon(docRow.DocType, (uint)docRow.LabelCode);
                if (labelCollection.ContainsKey(shablonCode))
                {
                    bArray = labelCollection[shablonCode];
                    fileLength = bArray.Length;
                    fileContent = TSDUtils.CustomEncodingClass.Encoding.GetString(bArray);
                }
                else
                {
                    string labelName = System.IO.Path.Combine(Program.StartupPath, string.Format("LABEL_{0}.DEF", shablonCode));
                    if (System.IO.File.Exists(labelName))
                    {
                        using (System.IO.FileStream fs = System.IO.File.OpenRead(labelName))
                        {
                            fileLength = (int)fs.Length;
                            bArray = new byte[fileLength];
                            fs.Read(bArray, 0, fileLength);
                            fs.Close();
                        }
                        labelCollection.Add(shablonCode, bArray);
                    }

                }
                //no print shablon - error
                if (bArray == null)
                    return false;

                fileContent = TSDUtils.CustomEncodingClass.Encoding.GetString(bArray);
                //btPrint.SetStatusEvent(fileContent);
                int i = fileContent.IndexOf("MAGICSTRING");
                if (i >= 0)
                {
                    string s1 = fileContent.Substring(0, i);
                    byte[] bArray2 = ReplaceAttr(TSDUtils.CustomEncodingClass.Encoding.GetBytes(s1), datarow, docRow);
                    //fileContent = TSDUtils.CustomEncodingClass.Encoding.GetString(bArray2);
                    //btPrint.SetStatusEvent(s1);
                    //return;
                    bool result1 = Print(bArray2);

                    string s2 = fileContent.Substring(i + "MAGICSTRING".Length+2);
                    byte[] bArray3 = ReplaceAttr(TSDUtils.CustomEncodingClass.Encoding.GetBytes(s2), datarow, docRow);
                    //fileContent = TSDUtils.CustomEncodingClass.Encoding.GetString(bArray2);
                    //btPrint.SetStatusEvent(s2);
                    //return;

                    bool result2 = Print(bArray3);
                    bArray2 = null;
                    bArray3 = null;
                    return result1 & result2;

                }
                else
                {


                    byte[] bArray2 = ReplaceAttr(bArray, datarow, docRow);
                    //fileContent = TSDUtils.CustomEncodingClass.Encoding.GetString(bArray2);
                    //btPrint.SetStatusEvent(fileContent);
                    //return;
                    bool result2 = Print(bArray2);
                    return result2;
                }
                /*
                try
                {
                    if (btPrint.Connected)
                    {
                        btPrint.Print(bArray2);
                        return true; //success print
                    }
                    else
                    {

                        btPrint.ConnToPrinter(Program.Settings.TypedSettings[0].BTPrinterAddress);
                        if (btPrint.Connected)
                        {
                            btPrint.Print(bArray2);
                            return true; //success print
                        }

                    }
                }
                catch
                {
                    btPrint.SetErrorEvent("Ошибка связи BlueTooth. Ждите 5 сек...");
                    //BTPrintClass.PrintClass.Reconnect();
                    System.Threading.Thread.Sleep(5000);
                    //btPrint.ConnToPrinter(Program.Settings.TypedSettings[0].BTPrinterAddress);
                    btPrint.Print(bArray2);
                    return true; //success print
                }*/
            }
            catch (BTConnectionFailedException)
            {
                try
                {
                    using (BTConnectionErrorForm frm =
                            new BTConnectionErrorForm())
                    {
                        if (frm.ShowDialog() == System.Windows.Forms.DialogResult.Yes)
                        {
                            BTPrintClass.PrintClass.Reconnect();
                            PrintLabel(datarow, docRow, shablonCode);
                            return true; //success print
                        }

                    }
                }
                catch (Exception err) 
                { 
                    BTPrintClass.PrintClass.SetErrorEvent(err.ToString());
                    BTPrintClass.PrintClass.SetErrorEvent("Ошибка! Отключите принтер и подключите заново");
                    return false;
                }
            }
            catch (Exception err)
            {
                BTPrintClass.PrintClass.SetErrorEvent(err.ToString());
                BTPrintClass.PrintClass.SetErrorEvent("Отключите принтер и подключите заново");
                return false;
            }
            return false;

        }