Ejemplo n.º 1
0
        public void WebSocket_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            JsonTextParser       parser   = new JsonTextParser();
            JsonObjectCollection jsonData = (JsonObjectCollection)parser.Parse(e.Message);

            if (((JsonNumericValue)jsonData["ok"]).Value == 1)
            {
                //子窗口相关
                if (this.SubForm != null)
                {
                    if (this.SubForm is OrderDayReportForm && ((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_REPORT_DAY))
                    {
                        ((OrderDayReportForm)this.SubForm).ShowData(e.Message); //订单日报表
                    }
                    else if (this.SubForm is OrderMonthReportForm && ((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_REPORT_MONTH))
                    {
                        ((OrderMonthReportForm)this.SubForm).ShowData(e.Message); //订单月报表
                    }
                    else if (this.SubForm is ClientForm && ((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_CLIENT_LIST))
                    {
                        ((ClientForm)this.SubForm).ShowData(e.Message); //客户端管理
                    }
                    else if (this.SubForm is MenuClassForm && ((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_MENU_CLASS))
                    {
                        ((MenuClassForm)this.SubForm).ShowData(e.Message); //菜单分类
                    }
                    else if (this.SubForm is MenuForm && ((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_MENU_CLASS))
                    {
                        ((MenuForm)this.SubForm).ShowData(e.Message); //菜单列表的分类部分
                    }
                    else if (this.SubForm is MenuForm && ((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_MENU))
                    {
                        ((MenuForm)this.SubForm).ShowData(e.Message); //菜单列表的数据部分
                    }
                    else if (this.SubForm is MenuForm && ((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_BIG_IMAGE))
                    {
                        if (((MenuForm)this.SubForm).SubForm != null && ((MenuAddForm)((MenuForm)this.SubForm).SubForm).SubForm != null)
                        {
                            ((MenuBigImgViewForm)((MenuAddForm)((MenuForm)this.SubForm).SubForm).SubForm).ShowData(e.Message); //菜单显示图片
                        }
                    }
                    else if (this.SubForm is MenuForm && ((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_SELECTED_MENU_CLASS))
                    {
                        ((MenuForm)this.SubForm).MenuClassListSelectedWithID((int)((JsonNumericValue)jsonData["data"]).Value); //添加修改删除菜单数据后更新菜单数据列表
                    }
                }

                if (((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_TOMAIN) || ((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_GET_ONLINE_LIST))
                {
                    {
                        //发送获取在线列表的请求
                        jsonData = new JsonObjectCollection();
                        jsonData.Add(new JsonStringValue("cmd", AppConfig.SERV_ONLINE_LIST));
                        ConnHelper.SendString(jsonData.ToString());
                    }

                    {
                        //获取下单明细列表
                        jsonData = new JsonObjectCollection();
                        jsonData.Add(new JsonStringValue("cmd", AppConfig.SERV_ORDER_DETAIL));
                        ConnHelper.SendString(jsonData.ToString());
                    }
                }
                else if (((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_ONLINE_LIST))
                {
                    //显示在线列表

                    this.InformationDeskIndices = new List <int>();
                    this.ClientOrderStatusList  = new Dictionary <int, int>();
                    this.ClientStatusList       = new Dictionary <int, int>();
                    this.ClientNameList         = new Dictionary <int, string>();
                    this.OnlineList.Items.Clear();

                    JsonArrayCollection data = (JsonArrayCollection)jsonData["data"];
                    for (int i = 0; i < data.Count; i++)
                    {
                        JsonObjectCollection itemData = (JsonObjectCollection)data[i];

                        if (((JsonNumericValue)itemData["is_admin"]).Value == 1)
                        {
                            //服务台
                            ListViewItem item = new ListViewItem(new string[] { "", ((JsonStringValue)itemData["name"]).Value, ((JsonStringValue)itemData["ip"]).Value, Strings.MainFormInformationDeskName, Strings.MainFormInformationDeskStatus });
                            this.OnlineList.Items.Add(item);

                            this.InformationDeskIndices.Add(i);
                        }
                        else
                        {
                            //一般
                            string status = Strings.MainFormClientStatus;

                            if (itemData["o_status"].GetValue() != null)
                            {
                                float totalPrice = 0.0f;
                                if (itemData["total_price"].GetValue() != null)
                                {
                                    totalPrice = (float)((JsonNumericValue)itemData["total_price"]).Value;
                                }

                                if (((JsonNumericValue)itemData["o_status"]).Value == 0)
                                {
                                    status = string.Format(Strings.MainFormClientStatus0, totalPrice.ToString("f1"));
                                }
                                else if (((JsonNumericValue)itemData["o_status"]).Value == 1)
                                {
                                    status = string.Format(Strings.MainFormClientStatus1, totalPrice.ToString("f1"));
                                }

                                this.ClientOrderStatusList.Add(i, (int)((JsonNumericValue)itemData["o_status"]).Value);
                            }

                            this.ClientNameList.Add(i, ((JsonStringValue)itemData["name"]).Value);
                            this.ClientStatusList.Add(i, (int)((JsonNumericValue)itemData["status"]).Value);

                            ListViewItem item = new ListViewItem(new string[] { "", ((JsonStringValue)itemData["name"]).Value, ((JsonStringValue)itemData["ip"]).Value, Strings.MainFormClientClassName, status });
                            this.OnlineList.Items.Add(item);
                        }
                    }

                    if (this.ClientListSelectedIndex > -1)
                    {
                        this.OnlineList.Items[this.ClientListSelectedIndex].Selected = true;
                    }
                }
                else if (((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_ORDER_DETAIL))
                {
                    //下单明细列表

                    this.OrderDetailIDList     = new List <int>();
                    this.OrderDetailStatusList = new List <int>();
                    this.OrderDetailNameList   = new List <string>();

                    this.OrderDetailList.Items.Clear();
                    JsonArrayCollection data = (JsonArrayCollection)jsonData["data"];

                    for (int i = 0; i < data.Count; i++)
                    {
                        JsonObjectCollection itemData = (JsonObjectCollection)data[i];

                        string status = Strings.MainFormOrderDetailStatus0;
                        if ((int)((JsonNumericValue)itemData["status"]).Value == 1)
                        {
                            status = Strings.MainFormOrderDetailStatus1;
                        }

                        this.OrderDetailIDList.Add((int)((JsonNumericValue)itemData["id"]).Value);
                        this.OrderDetailStatusList.Add((int)((JsonNumericValue)itemData["status"]).Value);
                        this.OrderDetailNameList.Add(((JsonStringValue)itemData["menu_name"]).Value);

                        ListViewItem item = new ListViewItem(new string[] { "", ((JsonStringValue)itemData["c_name"]).Value, ((JsonStringValue)itemData["menu_name"]).Value, ((float)((JsonNumericValue)itemData["price"]).Value).ToString("f1"), ((int)((JsonNumericValue)itemData["quantity"]).Value).ToString(), Commons.UnixTimeFrom((long)((JsonNumericValue)itemData["add_time"]).Value).ToString("HH:mm:ss"), status });
                        this.OrderDetailList.Items.Add(item);
                    }

                    if (this.OrderDetailListSelectedIndex > -1)
                    {
                        this.OrderDetailList.Items[this.OrderDetailListSelectedIndex].Selected = true;
                    }
                }
            }
            else
            {
                MessageBox.Show(((JsonStringValue)jsonData["message"]).Value);
            }
        }
Ejemplo n.º 2
0
        public void ShowData(string jsonStr)
        {
            JsonTextParser       parser   = new JsonTextParser();
            JsonObjectCollection jsonData = (JsonObjectCollection)parser.Parse(jsonStr);

            if (((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_MENU_CLASS))
            {
                this.MenuClassData = (JsonArrayCollection)jsonData["data"];

                this.MenuClassList.Items.Clear();
                this.MenuClassList.Items.Add(Strings.MenuFormListFirst);
                this.MenuClassList.SelectedIndex = 0;

                this.MenuIDList = new List <int>();
                this.MenuIDList.Add(0);

                for (int i = 0; i < this.MenuClassData.Count; i++)
                {
                    JsonObjectCollection itemData = (JsonObjectCollection)this.MenuClassData[i];

                    this.MenuClassList.Items.Add(((JsonStringValue)itemData["name"]).Value);
                    this.MenuIDList.Add((int)((JsonNumericValue)itemData["id"]).Value);
                }

                //选定上一次所选定的索引
                //this.MenuClassList.SelectedIndex = this.PrevSelectedIndex;
            }
            else if (((JsonStringValue)jsonData["cmd"]).Value.Equals(AppConfig.CLIENT_WANT_MENU))
            {
                this.MenuData = (JsonArrayCollection)jsonData["data"];

                this.MenuDataList.Items.Clear();
                for (int i = 0; i < this.MenuData.Count; i++)
                {
                    JsonObjectCollection itemData = (JsonObjectCollection)this.MenuData[i];

                    ListViewItem item = new ListViewItem(new string[] { "", ((JsonStringValue)itemData["name"]).Value, ((JsonNumericValue)itemData["price"]).Value.ToString("f1"), ((JsonStringValue)itemData["mc_name"]).Value, Commons.UnixTimeFrom((long)((JsonNumericValue)itemData["add_time"]).Value).ToString("yyyy-MM-dd") });
                    this.MenuDataList.Items.Add(item);
                }
            }
        }