示例#1
0
        private void lsDone_DoubleClick(object sender, EventArgs e)
        {
            if (lsDone.SelectedItems.Count < 1)
            {
                return;
            }
            ListViewItem act_item = lsDone.SelectedItems[0];
            CheRequest   req      = (CheRequest)act_item.Tag;

            if (req != null)
            {
                if (MessageBox.Show("重新打印已打印记录", "重新打印", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    return;
                }
                int res;
                if ((res = NewShuiKongInterface.SendRecipt(req)) != 0)
                {
                    MessageBox.Show(String.Format("税控脚本执行错误,错误码:{0:d} {1:s}", res, NewShuiKongInterface.getLastError()));
                    lbskStatus.Text = "最近操作:" + NewShuiKongInterface.getLastError();
                }
                else
                {
                    lbskStatus.Text = "最近操作:成功";
                }
            }
        }
示例#2
0
        private void _AddRequest(CheRequest req)
        {
            Boolean ref_req = false;

            if (mActList.Count == 0)
            {
                ref_req = true;
            }
            mActList.Add(req);
            lsReqs.BeginUpdate();
            DateTime tran_date;

            if (DateTime.TryParse(req.Time, out tran_date) == false)
            {
                tran_date = DateTime.Now;
            }
            String       brief_info = String.Format("{0:s} {1:s} 油枪{2:s}加{3:s}油{4:s}升", tran_date.ToShortTimeString(), req.LicenseNumber, req.Pump_Number, req.Product_Code, req.Product_Number);
            ListViewItem lvi        = new ListViewItem(new String[] { brief_info });

            lvi.Name = req.Order_Number;    /** it is key to search the item*/
            //lvi.ImageIndex = i;     //todo
            //lvi.Text = req.Order_Number;
            lvi.SubItems.Add(req.Customer_Text);
            lvi.SubItems.Add(req.Amount);
            lvi.Tag = req;
            this.lsReqs.Items.Insert(0, lvi);
            this.lsReqs.EndUpdate();
            if (ref_req)
            {
                this.Refresh();
            }
        }
示例#3
0
        public void AddRequest(CheDaoInterface req)
        {
            switch (req.message_type)
            {
            case CheDaoInterface.data_validation:
                CheRequest c_item = (CheRequest)req;
                this.Invoke((MethodInvoker) delegate
                {
                    this._AddRequest(c_item);    // run in UI thread
                });
                break;

            case CheDaoInterface.print_confirm:
                ChePActionRequest p_item = (ChePActionRequest)req;
                this.Invoke((MethodInvoker) delegate
                {
                    this.MoveToDoneList(p_item.Order_Number, p_item.Printed_Time, p_item.message_type);  // run in UI thread
                });
                break;

            case CheDaoInterface.delete_cmd:
                CheDeleteActionRequest d_item = (CheDeleteActionRequest)req;
                this.Invoke((MethodInvoker) delegate
                {
                    this.MoveToDoneList(d_item.Order_Number, d_item.Printed_Time, d_item.message_type);   // run in UI thread
                });
                break;

            default:
                Trace.WriteLineIf(Program.trace_sw.TraceError, "incorrect message request received " + req.message_type.ToString());
                break;
            }
        }
示例#4
0
 static CheDaoInterface create(LocalChePackage p)
 {
     Trace.WriteLineIf(Program.trace_sw.TraceVerbose, String.Format("incomming package {0:d} {1:s}", p.msg_type, p.rawXML), "message");
     if (p.msg_type == CheDaoInterface.data_validation)
     {
         Invoice_Request_Count++;
         return(CheRequest.create(p.rawXML, p.time_ticks));
     }
     if (p.msg_type == CheDaoInterface.scan_print || p.msg_type == CheDaoInterface.manual_print)
     {
         Print_Request_Count++;
         return(ChePrintRequest.create(p.msg_type, p.rawXML, p.time_ticks));
     }
     if (p.msg_type == CheDaoInterface.print_confirm)
     {
         Print_Act_Count++;
         return(ChePActionRequest.create(p.rawXML, p.time_ticks));//it is just a string
     }
     if (p.msg_type == CheDaoInterface.delete_cmd)
     {
         Print_Act_Count++;
         return(CheDeleteActionRequest.create(p.rawXML, p.time_ticks));//it is just a string
     }
     return(new SimpleRequest(p.msg_type));
 }
 bool ShuiKongInterface.SendRecipt(CheRequest req)
 {
     if (anch_wnd_handle != IntPtr.Zero)
     {
         Win32Locator.SetForeGWindow(anch_wnd_handle);
         if (this.first_editor_wnd_str != null)
         {
             IntPtr f_e = Win32Locator.locateWindow(this.first_editor_wnd_str, GetWndClassPostFix());
             if (f_e != IntPtr.Zero)
             {
                 Win32Locator.SetForeGWindow(f_e);
                 //SetFocus(f_e); the method doesn't work
             }
             else
             {
                 Trace.WriteLineIf(Program.trace_sw.TraceError, "did not find the window");
             }
         }
         for (int i = 0; i < this.max_send_ops; i++)
         {
             String str = actions[i].getValue(req);
             SendKeys.Send(str);
         }
         return(true);
     }
     return(false);
 }
示例#6
0
 /** just for the case: move one item to done list without print*/
 private void MoveToDoneList(String TransNo, String Printed_Time, int act_code)
 {
     ListViewItem[] list_items = lsReqs.Items.Find(TransNo, false);
     if (list_items.Length > 0)
     {
         lsReqs.Items.Remove(list_items[0]);
         this.lsDone.Items.Insert(0, list_items[0]).SubItems.Add(Printed_Time);
         this.mActList.Remove((CheRequest)list_items[0].Tag);
         this.mDoneList.Add((CheRequest)list_items[0].Tag);
         bool firstRec = false;
         if (mRecBuffer == null)
         {
             firstRec   = true;
             mRecBuffer = new StringWriter();
         }
         CheRequest rec = (CheRequest)list_items[0].Tag;
         if (rec != null)
         {
             mRecBuffer.Write((rec).toJsonString(act_code, firstRec));
         }
         if (mActList.Count == 0)
         {
             this.Refresh();
         }
     }
 }
 public static Boolean SendRecipt(CheRequest req)
 {
     if (mInterface != null)
     {
         return(mInterface.SendRecipt(req));
     }
     return(false);
 }
示例#8
0
        private void tsItemCopyLicense_Click(object sender, EventArgs e)
        {
            if (lsReqs.SelectedItems.Count < 1)
            {
                return;
            }
            ListViewItem act_item = lsReqs.SelectedItems[0];
            CheRequest   req      = (CheRequest)act_item.Tag;

            System.Windows.Forms.Clipboard.SetText(req.LicenseNumber);
        }
示例#9
0
        private void tsItemDelete_Click(object sender, EventArgs e)
        {
            if (lsReqs.SelectedItems.Count < 1)
            {
                return;
            }
            ListViewItem act_item = lsReqs.SelectedItems[0];
            CheRequest   req      = (CheRequest)act_item.Tag;

            CheDaoFactory.Handle_Internal_Package(CheDaoInterface.delete_cmd, Encoding.UTF8.GetBytes(req.Order_Number));
        }
 public static int SendRecipt(CheRequest req)
 {
     if (status != 0) { return -1; }
     Dictionary<String, String> rec = new Dictionary<string, string>();
     rec.Add("Customer_Text",req.Customer_Text);
     rec.Add("Product_Code", req.Product_Code);
     rec.Add("Product_Price",req.Product_Price);
     rec.Add("Amount", req.Amount);
     rec.Add("Product_Number", req.Product_Number);
     rec.Add("Product_Type", req.Product_Type);
     rec.Add("Pump_Number", req.Pump_Number);
     return ScriptExecuter.execute(rec);
 }
示例#11
0
        public static CheRequest create(string str, long _create_time)
        {
            XmlDocument   doc           = new XmlDocument();
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(CheRequest));

            try
            {
                CheRequest o = (CheRequest)xmlSerializer.Deserialize(new StringReader(str));
                o.create_time = _create_time;
                return(o);
            }
            catch (Exception e) {
                Trace.WriteLineIf(Program.trace_sw.TraceError, " decode XML error " + e.ToString());
                return(null);
            }
        }
 string ValueToBeSent.getValue(CheRequest req)
 {
     if (info != null)
     {
         Object o = info.GetValue(req, null);
         if (o != null)
         {
             return(o.ToString() + next_key);
         }
         else
         {
             return(next_key);
         }
     }
     return("");
 }
示例#13
0
        public static int SendRecipt(CheRequest req)
        {
            if (status != 0)
            {
                return(-1);
            }
            Dictionary <String, String> rec = new Dictionary <string, string>();

            rec.Add("Customer_Text", req.Customer_Text);
            rec.Add("Product_Code", req.Product_Code);
            rec.Add("Product_Price", req.Product_Price);
            rec.Add("Amount", req.Amount);
            rec.Add("Product_Number", req.Product_Number);
            rec.Add("Product_Type", req.Product_Type);
            rec.Add("Pump_Number", req.Pump_Number);
            return(ScriptExecuter.execute(rec));
        }
示例#14
0
        private void timer_event()
        {
            Random r = new Random();

            mTestCounter++;
            if (mTestCounter > r.Next(10))
            {
                mTestCounter = 0;
                if (lsReqs.Items.Count > 0)
                {
                    int          index    = r.Next(lsReqs.Items.Count);
                    ListViewItem act_item = lsReqs.Items[index];
                    CheRequest   req      = (CheRequest)act_item.Tag;
                    CheDaoFactory.Handle_Internal_Package(CheDaoInterface.delete_cmd, Encoding.UTF8.GetBytes(req.Order_Number));
                }
            }
        }
        public bool SendRecipt(CheRequest req)
        {
            Boolean res = false;
            IntPtr  wnd_ptr;

            if (anch_wnd_handle != null)
            {
                Win32Locator.SetForeGWindow(anch_wnd_handle);
            }
            else
            {
                return(false);
            }
            foreach (String wnd_str in mFieldMap.Keys)
            {
                res = false;
                if (wnd_str != null)
                {
                    wnd_ptr = Win32Locator.locateWindow(wnd_str, GetWndClassPostFix());
                    if (wnd_ptr == null)
                    {
                        break;
                    }
                    String text = mFieldMap[wnd_str].GetValue(req, null).ToString();
                    try
                    {
                        SendMessage(wnd_ptr, WM_SETTEXT, IntPtr.Zero, text);
                        int r = Marshal.GetLastWin32Error();
                        if (r != 0)
                        {
                            Trace.WriteLineIf(Program.trace_sw.TraceError, String.Format("sendmessage with error code:{0:d}", res), "error");
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLineIf(Program.trace_sw.TraceError, "Send Text Failed with " + e.ToString(), "error");
                        break;
                    }
                }
                res = true;
            }
            return(res);
        }
示例#16
0
        private byte[] GenInvoicePackage()
        {
            CheRequest req = new CheRequest();
            String order_no = "RND"+ new Random().Next().ToString() ;
            req.Order_Number = order_no;
            req.Print_Number = "PR" + order_no;
            req.Product_Code = "94";
            req.Product_Price = "4.5";
            req.Product_Number = "10";
            req.Customer_Text = "中国石化";
            req.Amount = "100";
            req.LicenseNumber = "粤AXX434";
            req.Time = DateTime.Now.ToString();
            req.Pump_Number = "3";
            ChePrintRequest p_req = new ChePrintRequest();
            p_req.Order_Number = order_no;
            p_req.Print_Type = "1";

            byte[] res = GenerateBytes(1, req);
            byte[] rsp = GenerateBytes(2, p_req);
            InvoiceList.Add(rsp);
            return res;
        }
示例#17
0
        private void lsReqs_DoubleClick(object sender, EventArgs e)
        {//note other functions call it directly, don't use sender or e
            if (lsReqs.SelectedItems.Count < 1)
            {
                return;
            }
            ListViewItem act_item = lsReqs.SelectedItems[0];
            CheRequest   req      = (CheRequest)act_item.Tag;

            if (req != null)
            {
                int res;
                if ((res = NewShuiKongInterface.SendRecipt(req)) != 0)
                {
                    MessageBox.Show(String.Format("税控脚本执行错误,错误码:{0:d} {1:s}", res, NewShuiKongInterface.getLastError()));
                    lbskStatus.Text = "最近操作:" + NewShuiKongInterface.getLastError();
                }
                else
                {
                    CheDaoFactory.Handle_Internal_Package(CheDaoInterface.print_confirm, Encoding.UTF8.GetBytes(req.Order_Number));
                    lbskStatus.Text = "最近操作:成功";
                }
            }
        }
示例#18
0
        /**
         *  make sure the function is re-entriable.
         **/
        static CheDaoInterface _HandlePackage(LocalChePackage p)
        {
            CheDaoInterface msg = create(p);

            if (msg != null)
            {
                switch (msg.message_type)
                {
                case CheDaoInterface.data_validation:
                    lock (mPendingList)
                    {
                        CheRequest item = (CheRequest)msg;
                        try
                        {
                            //put to pending list
                            mPendingList.Add(item.Order_Number, item);
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLineIf(Program.trace_sw.TraceError, "Insert CheRequest Failed, maybe the key already exist " + e.Message, "error");
                            msg.Result = 2;     //2:其它不符;
                        }
                    }
                    break;

                case CheDaoInterface.clean_cmd:    //delete the item one hour later
                    int bypass_counter = 0;
                    lock (mPendingList)
                    {
                        Dictionary <String, CheRequest> newPendingList = new Dictionary <String, CheRequest>();
                        foreach (String str in mPendingList.Keys)
                        {
                            CheRequest c_item = mPendingList[str];
                            DateTime   c_date = new DateTime(c_item.create_time);
                            if (c_date.AddMinutes(AppConfig.GetLifeTimeOfRec()) > DateTime.Now)
                            {
                                newPendingList.Add(str, c_item);
                            }
                            else
                            {
                                bypass_counter++;
                            }
                        }
                        mPendingList = newPendingList;
                    }
                    Trace.WriteLineIf(Program.trace_sw.TraceVerbose, "clean up the internal cache and bypass " + bypass_counter.ToString());
                    break;

                case CheDaoInterface.scan_print:
                case CheDaoInterface.manual_print:
                    lock (mPendingList)
                    {
                        ChePrintRequest p_item = (ChePrintRequest)msg;
                        if (mPendingList.ContainsKey(p_item.Order_Number))
                        {
                            CheRequest w_item = mPendingList[p_item.Order_Number];
                            mPendingList.Remove(p_item.Order_Number);
                            Program.NewRequest(w_item);     // to be print
                        }
                        else
                        {
                            Trace.WriteLineIf(Program.trace_sw.TraceError, "invalide print request, no key exist", "error");
                            msg.Result = 2;    //2:已开票;
                        }
                    }
                    break;

                case CheDaoInterface.print_confirm:
                    Program.NewRequest(msg);     //internal message
                    break;

                case CheDaoInterface.delete_cmd:
                    Program.NewRequest(msg);     //internal message
                    break;

                default:
                    msg = null;
                    break;
                }
                try
                {
                    lock (bk_stream)
                    {
                        if (msg != null)
                        {
                            p.save(bk_stream);              // just save the valid msg
                        }
                    }
                }
                catch (Exception e)
                {
                    save_error_count++;
                    Trace.WriteLineIf(Program.trace_sw.TraceError, "Write backup stream failed " + e.Message, "error");
                }
            }
            return(msg);
        }
 public static Boolean SendRecipt(CheRequest req)
 {
     if (mInterface != null) return mInterface.SendRecipt(req);
     return false;
 }
 string ValueToBeSent.getValue(CheRequest req)
 {
     if (info != null)
     {
         Object o = info.GetValue(req, null);
         if (o != null) return o.ToString() + next_key;
         else return next_key;
     }
     return "";
 }
 string ValueToBeSent.getValue(CheRequest req)
 {
     return(text + next_key);
 }
 bool ShuiKongInterface.SendRecipt(CheRequest req)
 {
     if (anch_wnd_handle != IntPtr.Zero)
     {
         Win32Locator.SetForeGWindow(anch_wnd_handle);
         if (this.first_editor_wnd_str != null) {
             IntPtr f_e = Win32Locator.locateWindow(this.first_editor_wnd_str, GetWndClassPostFix());
             if (f_e != IntPtr.Zero)
             {
                 Win32Locator.SetForeGWindow(f_e);
                 //SetFocus(f_e); the method doesn't work
             }
             else {
                 Trace.WriteLineIf(Program.trace_sw.TraceError,"did not find the window");
             }
         }
         for (int i = 0; i < this.max_send_ops; i++)
         {
                 String str = actions[i].getValue(req);
                 SendKeys.Send(str);
         }
         return true;
     }
     return false;
 }
        public bool SendRecipt(CheRequest req)
        {
            Boolean res = false;
            IntPtr wnd_ptr;
            if (anch_wnd_handle != null)
            {
                Win32Locator.SetForeGWindow(anch_wnd_handle);
            }
            else {
                return false;
            }
            foreach (String wnd_str in mFieldMap.Keys) {
                res = false;
                if (wnd_str != null) {
                    wnd_ptr = Win32Locator.locateWindow(wnd_str, GetWndClassPostFix());
                    if (wnd_ptr == null) break;
                    String text = mFieldMap[wnd_str].GetValue(req, null).ToString();
                    try
                    {

                        SendMessage(wnd_ptr, WM_SETTEXT, IntPtr.Zero, text);
                        int r = Marshal.GetLastWin32Error();
                        if (r != 0)
                        {
                            Trace.WriteLineIf(Program.trace_sw.TraceError, String.Format("sendmessage with error code:{0:d}", res), "error");
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLineIf(Program.trace_sw.TraceError, "Send Text Failed with " + e.ToString(), "error");
                        break;
                    }
                }
                res = true;
            }
            return res;
        }
示例#24
0
 private void _AddRequest(CheRequest req)
 {
     Boolean ref_req = false;
     if (mActList.Count == 0)
         ref_req = true;
     mActList.Add(req);
     lsReqs.BeginUpdate();
     DateTime tran_date;
     if (DateTime.TryParse(req.Time,out tran_date) == false) {
         tran_date = DateTime.Now;
     }
     String brief_info = String.Format("{0:s} {1:s} 油枪{2:s}加{3:s}油{4:s}升", tran_date.ToShortTimeString(),req.LicenseNumber, req.Pump_Number, req.Product_Code, req.Product_Number);
     ListViewItem lvi = new ListViewItem(new String[] { brief_info});
     lvi.Name = req.Order_Number;    /** it is key to search the item*/
     //lvi.ImageIndex = i;     //todo
     //lvi.Text = req.Order_Number;
     lvi.SubItems.Add(req.Customer_Text);
     lvi.SubItems.Add(req.Amount);
     lvi.Tag = req;
     this.lsReqs.Items.Insert(0,lvi);
     this.lsReqs.EndUpdate();
     if (ref_req) this.Refresh();
 }
 string ValueToBeSent.getValue(CheRequest req)
 {
     return text + next_key;
 }