示例#1
0
 private void btnRefillPaper_Click(object sender, EventArgs e)
 {
     try
     {
         if (Convert.ToInt32(txtPaperCount.Text) > 25)
         {
             var MsgStat = new MessageAlerts();
             MsgStat.ExceptionMessage("Maximum No of Paper : 25");
         }
         else
         {
             var path = Properties.Settings.Default.AdminPath + "Admin.xml";
             var xDoc = XDocument.Load(path);
             var node = xDoc.Descendants("Admin").FirstOrDefault(cd => cd.Element("paper").Value != "");
             if (node.Name != null || node.Name != "")
             {
                 node.SetElementValue("paper", txtPaperCount.Text);
             }
             xDoc.Save(path);
             lblStatPaper.Text      = "Paper Count - Update";
             lblStatPaper.ForeColor = Color.PaleGreen;
             LoadPaperCount();
         }
     }
     catch (Exception ex)
     {
         var MsgAlert = new MessageAlerts();
         MsgAlert.ExceptionMessage(ex.Message);
     }
 }
示例#2
0
        private bool ValidateAdmin()
        {
            bool UserStat = false;

            if (lblAdminStatus.Text == "Not Admin")
            {
                if (txtCode.Text == "12345")
                {
                    groupBoxButtons.Enabled       = true;
                    lblAdminStatus.Text           = "Admin";
                    lblAdminStatusPaper.Text      = "Admin";
                    lblAdminStatusPaper.ForeColor = Color.PaleGreen;
                    lblAdminStatus.ForeColor      = Color.PaleGreen;
                    panel1.Hide();
                    UserStat = true;
                }
                else
                {
                    var MsgStat = new MessageAlerts();
                    MsgStat.ExceptionMessage("Incorrect Code");
                }
            }

            return(UserStat);
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (CheckReaminingPaperInDispenser() && !withPaper)
            {
                var MsgStat = new MessageAlerts();
                MsgStat.ExceptionMessage("No More paper left in the Dispenser");
                serialPort1.WriteLine("b");
                return;
            }

            ExecutePrint();
        }
示例#4
0
 private void frmAdmin_Load(object sender, EventArgs e)
 {
     try
     {
         lblAdminStatus.Text      = "Not Admin";
         lblAdminStatus.ForeColor = Color.Red;
         lblStatus.ForeColor      = Color.Red;
         groupBoxButtons.Enabled  = false;
         LoadDocument();
     }
     catch (Exception ex)
     {
         var MsgAlert = new MessageAlerts();
         MsgAlert.ExceptionMessage(ex.Message);
     }
 }
示例#5
0
        private OperateResult <Socket> ConnectServer( )
        {
            OperateResult <Socket> connectResult = CreateSocketAndConnect(EndPointServer, 10000);

            if (!connectResult.IsSuccess)
            {
                return(connectResult);
            }

            // 连接成功,发送数据信息
            OperateResult sendResult = SendStringAndCheckReceive(connectResult.Content, 1, ClientAlias);

            if (!sendResult.IsSuccess)
            {
                return(OperateResult.CreateFailedResult <Socket>(sendResult));
            }

            MessageAlerts?.Invoke(StringResources.Language.ConnectServerSuccess);
            return(connectResult);
        }
示例#6
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         var path = Properties.Settings.Default.AdminPath + "Admin.xml";
         var xDoc = XDocument.Load(path);
         var node = xDoc.Descendants("Admin").FirstOrDefault(cd => cd.Element("multiplier").Value != "");
         if (node.Name != null || node.Name != "")
         {
             node.SetElementValue("multiplier", txtMultiplier.Text);
         }
         xDoc.Save(path);
         lblStatus.Text      = "File Has been updated";
         lblStatus.ForeColor = Color.PaleGreen;
     }
     catch (Exception ex)
     {
         var MsgAlert = new MessageAlerts();
         MsgAlert.ExceptionMessage(ex.Message);
     }
 }
 private void ComputationSummary_Load(object sender, EventArgs e)
 {
     try
     {
         withPaper = false;
         InitializeSerialPort();
         LoadDocument();
         if (CheckReaminingPaperInDispenser())
         {
             MessageBox.Show("Paper is less than the assigned value", "Transaction Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             if (serialPort1.IsOpen)
             {
                 serialPort1.WriteLine(Convert.ToString(1000));
             }
         }
     }
     catch (Exception ex)
     {
         var MsgAlerts = new MessageAlerts();
         MsgAlerts.ExceptionMessage(ex.Message);
     }
 }
示例#8
0
 /// <summary>
 /// 连接服务器之前的消息提示,如果是重连的话,就提示10秒等待信息
 /// </summary>
 private void AwaitToConnect( )
 {
     if (ConnectFailedCount == 0)
     {
         MessageAlerts?.Invoke(StringResources.Language.ConnectingServer);
     }
     else
     {
         int count = 10;
         while (count > 0)
         {
             if (IsQuie)
             {
                 return;
             }
             count--;
             MessageAlerts?.Invoke(string.Format(StringResources.Language.ConnectFailedAndWait, count));
             Thread.Sleep(1000);
         }
         MessageAlerts?.Invoke(string.Format(StringResources.Language.AttemptConnectServer, ConnectFailedCount));
     }
 }
 /// <summary>
 /// 连接服务器之前的消息提示,如果是重连的话,就提示10秒等待信息
 /// </summary>
 private void AwaitToConnect( )
 {
     if (ConnectFailedCount == 0)
     {
         // English Version : Connecting Server...
         MessageAlerts?.Invoke("正在连接服务器...");
     }
     else
     {
         int count = 10;
         while (count > 0)
         {
             if (IsQuie)
             {
                 return;
             }
             count--;
             // English Version : Disconnected, wait [count] second to restart
             MessageAlerts?.Invoke("连接断开,等待" + count + "秒后重新连接");
             Thread.Sleep(1000);
         }
         MessageAlerts?.Invoke("正在尝试第" + ConnectFailedCount + "次连接服务器...");
     }
 }
示例#10
0
        private void btnPrintDocument_Click(object sender, EventArgs e)
        {
            PdfPrint.Status result = PdfPrint.Status.OK;


            if (printDialog.ShowDialog() == DialogResult.OK)
            {
                //Open ComputeSummary form
                var CompSum = new ComputationSummary();

                //Returns a value of number of copies to be printed
                CompSum.txtNoOfCopies.Text = Convert.ToString(printDialog.PrinterSettings.Copies);
                CompSum.txtNoOfPages.Text  = Convert.ToString(pdfViewer1.NumberOfPages);
                //Returns a boolean value if the item to be printed is colored or grayscale
                PrintColor = printDialog.PrinterSettings.DefaultPageSettings.Color;

                decimal costPerImage = 0;
                //Compute Cost
                var cal = new PrintCalculation();
                if (!pdfPrinting.ExcelFormat)
                {
                    costPerImage = cal.CalculateImageInFile(pdfPrinting.FileInDocFormat);
                }


                if (PrintColor == true)
                {
                    //Return a value of cost per page and if colored
                    CompSum.txtTotalAmount.Text = Convert.ToString(costPerImage + ((printDialog.PrinterSettings.Copies * 2) * pdfViewer1.NumberOfPages));
                    CompSum.txtColored.Text     = "Yes";
                }
                else
                {
                    //Return a value of cost per page and if not colored
                    CompSum.txtTotalAmount.Text = Convert.ToString(costPerImage + ((printDialog.PrinterSettings.Copies * 1) * pdfViewer1.NumberOfPages));
                    CompSum.txtColored.Text     = "No";
                }

                CompSum.FileLocFromMain = FileLoc;
                CompSum.ShowDialog();
                if (CompSum.PrintSuccess)
                {
                    pdfViewer1.CloseDocument();
                    btnPrintDocument.Enabled = false;
                }
            }
            else
            {
                pdfViewer1.CloseDocument();
                result = PdfPrint.Status.PRINTING_CANCELLED;
            }

            if (result == PdfPrint.Status.OK)
            { /*MessageBox.Show("Done Successfully", "Printing Transaction Status", MessageBoxButtons.OK, MessageBoxIcon.Information);*/
            }
            else if (result == PdfPrint.Status.PRINTING_CANCELLED)
            {
                var MsgAlerts = new MessageAlerts();
                MsgAlerts.ExceptionMessage(pdfPrinting.DecodeStatusCode(result));
            }
            else
            {
                var MsgAlerts = new MessageAlerts();
                MsgAlerts.ExceptionMessage("Error." + pdfPrinting.DecodeStatusCode(result));
            }
        }
        private void SetText(string text)
        {
            try
            {
                // InvokeRequired required compares the thread ID of the
                // calling thread to the thread ID of the creating thread.
                // If these threads are different, it returns true.
                if (this.textBox1.InvokeRequired)
                {
                    StringArgReturningVoidDelegate d = new StringArgReturningVoidDelegate(SetText);
                    this.Invoke(d, new object[] { text });
                }
                else
                {
                    //var val = text.Split('\r');
                    var val = text;

                    //Thread.Sleep(300);
                    if (val == "1")
                    {
                        InsertedCoin            = InsertedCoin + 1;
                        this.txtCurrentBal.Text = Convert.ToString(InsertedCoin);
                        this.textBox1.Text      = text;

                        var TAmount = Convert.ToInt32(txtTotalAmount.Text);
                        var TCurBal = Convert.ToInt32(txtCurrentBal.Text);

                        if (TAmount >= TCurBal)
                        {
                            ErrorCount = false;
                            //InsertedCoin = TCurBal + Convert.ToInt32(textBox1.Text);
                            //txtCurrentBal.Text = Convert.ToString(InsertedCoin);
                            if (Convert.ToInt32(txtCurrentBal.Text) == TAmount)
                            {
                                if (CheckReaminingPaperInDispenser())
                                {
                                    btnDispense.Enabled  = false;
                                    btnWithPaper.Enabled = true;
                                }
                                else
                                {
                                    btnDispense.Enabled  = true;
                                    btnWithPaper.Enabled = true;
                                    //btnPrint.Enabled = true;
                                }
                            }
                        }
                        else
                        {
                            //btnDispense.Enabled = true;
                            if (!ErrorCount)
                            {
                                ErrorCount = true;
                                MessageBox.Show("Balance is now sufficient", "Transaction Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        //if (textBox1.Text != "")
                        //{

                        //    var TAmount = Convert.ToInt32(txtTotalAmount.Text);
                        //    var TCurBal = Convert.ToInt32(txtCurrentBal.Text);

                        //    if (TAmount > TCurBal )
                        //    {

                        //        //InsertedCoin = TCurBal + Convert.ToInt32(textBox1.Text);
                        //        //txtCurrentBal.Text = Convert.ToString(InsertedCoin);
                        //        InsertedCoin = InsertedCoin + 1;
                        //        if(Convert.ToInt32(txtCurrentBal.Text) == TAmount)
                        //        {
                        //            btnDispense.Enabled = true;
                        //        }

                        //    }else
                        //    {
                        //        btnDispense.Enabled = true;
                        //        MessageBox.Show("Balance is now sufficient","Transaction Notice",MessageBoxButtons.OK,MessageBoxIcon.Information);
                        //    }
                        //}
                        //else
                        //{
                        //    if(InsertedCoin == 1)
                        //        txtCurrentBal.Text = "1";
                        //}
                    }
                    else if (val == "b")
                    {
                        btnPrint.Enabled     = true;
                        btnDispense.Enabled  = false;
                        btnWithPaper.Enabled = false;
                    }
                }
                //for (int i = 1; i < val.Length; i++)
                //{

                //}
            }
            catch (Exception ex)
            {
                var Alerts = new MessageAlerts();
                Alerts.ExceptionMessage(ex.ToString());
            }
        }
示例#12
0
        private void ThreadLogin()
        {
            lock (lock_connecting)
            {
                if (Is_Client_Connecting)
                {
                    return;
                }
                Is_Client_Connecting = true;
            }


            if (Connect_Failed_Count == 0)
            {
                MessageAlerts?.Invoke("正在连接服务器...");
            }
            else
            {
                int count = 10;
                while (count > 0)
                {
                    if (IsQuie)
                    {
                        return;
                    }
                    MessageAlerts?.Invoke("连接断开,等待" + count-- + "秒后重新连接");
                    Thread.Sleep(1000);
                }
                MessageAlerts?.Invoke("正在尝试第" + Connect_Failed_Count + "次连接服务器...");
            }


            stateone.HeartTime = DateTime.Now;
            LogNet?.WriteDebug(LogHeaderText, "Begin Connect Server, Times: " + Connect_Failed_Count);


            OperateResult result = new OperateResult();

            if (!CreateSocketAndConnect(out Socket socket, EndPointServer, result))
            {
                Connect_Failed_Count++;
                Is_Client_Connecting = false;
                LoginFailed?.Invoke(Connect_Failed_Count);
                LogNet?.WriteDebug(LogHeaderText, "Connected Failed, Times: " + Connect_Failed_Count);
                // 连接失败,重新连接服务器
                ReconnectServer();
                return;
            }

            // 连接成功,发送数据信息
            if (!SendStringAndCheckReceive(
                    socket,
                    1,
                    ClientAlias,
                    result
                    ))
            {
                Connect_Failed_Count++;
                Is_Client_Connecting = false;
                LogNet?.WriteDebug(LogHeaderText, "Login Server Failed, Times: " + Connect_Failed_Count);
                LoginFailed?.Invoke(Connect_Failed_Count);
                // 连接失败,重新连接服务器
                ReconnectServer();
                return;
            }

            // 登录成功
            Connect_Failed_Count = 0;
            stateone.IpEndPoint  = (IPEndPoint)socket.RemoteEndPoint;
            stateone.LoginAlias  = ClientAlias;
            stateone.WorkSocket  = socket;
            stateone.WorkSocket.BeginReceive(stateone.BytesHead, stateone.AlreadyReceivedHead,
                                             stateone.BytesHead.Length - stateone.AlreadyReceivedHead, SocketFlags.None,
                                             new AsyncCallback(HeadReceiveCallback), stateone);

            // 发送一条验证消息
            // SendBytes(stateone, CommunicationCode.CommandBytes(CommunicationCode.Hsl_Protocol_Check_Secends));
            byte[] bytesTemp = new byte[16];
            BitConverter.GetBytes(DateTime.Now.Ticks).CopyTo(bytesTemp, 0);
            SendBytes(stateone, NetSupport.CommandBytes(HslProtocol.ProtocolCheckSecends, 0, KeyToken, bytesTemp));


            stateone.HeartTime = DateTime.Now;
            Is_Client_Start    = true;
            LoginSuccess?.Invoke();

            LogNet?.WriteDebug(LogHeaderText, "Login Server Success, Times: " + Connect_Failed_Count);

            Is_Client_Connecting = false;

            Thread.Sleep(1000);
        }
        private void ThreadLogin()
        {
            lock (lock_connecting)
            {
                if (IsClientConnecting)
                {
                    return;
                }
                IsClientConnecting = true;
            }


            if (ConnectFailedCount == 0)
            {
                // English Version : Connecting Server...
                MessageAlerts?.Invoke("正在连接服务器...");
            }
            else
            {
                int count = 10;
                while (count > 0)
                {
                    if (IsQuie)
                    {
                        return;
                    }
                    // English Version : Disconnected, wait [count--] second to restart
                    MessageAlerts?.Invoke("连接断开,等待" + count-- + "秒后重新连接");
                    Thread.Sleep(1000);
                }
                MessageAlerts?.Invoke("正在尝试第" + ConnectFailedCount + "次连接服务器...");
            }


            stateone.HeartTime = DateTime.Now;
            LogNet?.WriteDebug(ToString( ), "Begin Connect Server, Times: " + ConnectFailedCount);

            OperateResult <Socket> connectResult = CreateSocketAndConnect(EndPointServer, 10000);

            if (!connectResult.IsSuccess)
            {
                ConnectFailedCount++;
                IsClientConnecting = false;
                LoginFailed?.Invoke(ConnectFailedCount);
                LogNet?.WriteDebug(ToString( ), "Connected Failed, Times: " + ConnectFailedCount);
                // 连接失败,重新连接服务器
                ReconnectServer( );
                return;
            }



            // 连接成功,发送数据信息
            OperateResult sendResult = SendStringAndCheckReceive(connectResult.Content, 1, ClientAlias);

            if (!sendResult.IsSuccess)
            {
                ConnectFailedCount++;
                IsClientConnecting = false;
                LogNet?.WriteDebug(ToString( ), "Login Server Failed, Times: " + ConnectFailedCount);
                LoginFailed?.Invoke(ConnectFailedCount);
                // 连接失败,重新连接服务器
                ReconnectServer( );
                return;
            }

            // 登录成功
            ConnectFailedCount  = 0;
            stateone.IpEndPoint = (IPEndPoint)connectResult.Content.RemoteEndPoint;
            stateone.LoginAlias = ClientAlias;
            stateone.WorkSocket = connectResult.Content;
            stateone.WorkSocket.BeginReceive(stateone.BytesHead, stateone.AlreadyReceivedHead,
                                             stateone.BytesHead.Length - stateone.AlreadyReceivedHead, SocketFlags.None,
                                             new AsyncCallback(HeadBytesReceiveCallback), stateone);


            byte[] bytesTemp = new byte[16];
            BitConverter.GetBytes(DateTime.Now.Ticks).CopyTo(bytesTemp, 0);
            SendBytes(stateone, HslProtocol.CommandBytes(HslProtocol.ProtocolCheckSecends, 0, Token, bytesTemp));


            stateone.HeartTime = DateTime.Now;
            IsClientStart      = true;
            LoginSuccess?.Invoke( );
            LogNet?.WriteDebug(ToString( ), "Login Server Success, Times: " + ConnectFailedCount);
            IsClientConnecting = false;
            Thread.Sleep(1000);
        }