Ejemplo n.º 1
0
        public IActionResult OnPostGetNews()
        {
            JObject result = new JObject();

            string        nt_id = Request.Form["nt_id"];
            string        n_id  = Request.Form["n_id"];
            List <string> query = new List <string>()
            {
                n_id
            };

            if (!m_incAdmin.OpString.DecideNull(query.ToArray()))
            {
                if (!m_incAdmin.OpString.DetectSql(query.ToArray(), Config.g_illegal))
                {
                    Models detail = m_incAdmin.GetNews(nt_id, n_id);
                    detail.g_news.n_content = m_incAdmin.OpString.unEscape(detail.g_news.n_content);

                    result.Add("detail", m_incAdmin.OpString.ToJson(detail));
                }
                else
                {
                    result.Add("error", SysError.GetErrorString("SYS001"));
                }
            }
            else
            {
                result.Add("error", SysError.GetErrorString("SYS002"));
            }

            return(new JsonResult(result.ToString()));
        }
        /// <summary>
        /// 发送充电枪控制命令
        /// </summary>
        /// <returns></returns>
        public string APP0006(string cp_code, int cp_guncode, string condition)
        {
            Dictionary <string, object> tcpClientDic = Config.g_tcpClientDic[cp_code];

            string outputData = "";

            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                         "<condition name=\"SEND002\">" + SysError.GetErrorString("SEND002") + "</condition>";
            try
            {
                if (m_incTCPSend003.DW0013(cp_code, cp_guncode, condition))
                {
                    outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                                 "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                                 "<condition name=\"SEND000\">" + SysError.GetErrorString("SEND000") + "</condition>";
                }
            }
            catch (Exception e)
            {
                outputData = "<error name=\"API001\">" + SysError.GetErrorString("API001") + "</error>" +
                             "<callback name=\"SYS003\">" + SysError.GetErrorString("SYS003") + "</callback>" +
                             "<condition name=\"SEND002\">" + SysError.GetErrorString("SEND002") + "</condition>" +
                             "<exception>" + e.Message + "</exception>";
            }
            outputData = "<root>" + outputData + "</root>";
            return(outputData);
        }
        /// <summary>
        /// 修改充电站后更新充电站数据
        /// </summary>
        /// <returns></returns>
        public string WEB0002(long cs_id)
        {
            string outputData = "";

            try
            {
                List <Models> list = m_incChargeStation.GetChargeStation(cs_id);
                for (int i = 0; i < list.Count; i++)
                {
                    Listener_ChargeStation_Data mod = GetChargeStation(cs_id);
                    mod.name  = list[i].G_ChargeStation.cs_name;
                    mod.csid  = (long)list[i].G_ChargeStation.cs_id;
                    mod.pid   = list[i].G_Province.p_id;
                    mod.cid   = list[i].G_City.c_id;
                    mod.did   = list[i].G_District.d_id;
                    mod.place = list[i].G_Province.p_name + list[i].G_City.c_name + list[i].G_District.d_name;
                }
                outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                             "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                             "<condition name=\"MANAGE000\">" + SysError.GetErrorString("MANAGE000") + "</condition>";
            }
            catch (Exception e)
            {
                outputData = "<error name=\"API001\">" + SysError.GetErrorString("API001") + "</error>" +
                             "<callback name=\"SYS003\">" + SysError.GetErrorString("SYS003") + "</callback>" +
                             "<condition name=\"MANAGE001\">" + e.Message + "</condition>" +
                             "<exception>" + e.Message + "</exception>";
            }
            outputData = "<root>" + outputData + "</root>";
            return(outputData);
        }
Ejemplo n.º 4
0
        public IActionResult OnPostGetMessage()
        {
            JObject result = new JObject();

            string        m_id  = Request.Form["m_id"];
            List <string> query = new List <string>()
            {
                m_id
            };

            if (!m_incAdmin.OpString.DecideNull(query.ToArray()))
            {
                if (!m_incAdmin.OpString.DetectSql(query.ToArray(), Config.g_illegal))
                {
                    Models detail = m_incAdmin.GetMessage(m_id);

                    result.Add("detail", m_incAdmin.OpString.ToJson(detail));
                }
                else
                {
                    result.Add("error", SysError.GetErrorString("SYS001"));
                }
            }
            else
            {
                result.Add("error", SysError.GetErrorString("SYS002"));
            }

            return(new JsonResult(result.ToString()));
        }
Ejemplo n.º 5
0
        public IActionResult OnPostGetMessageList()
        {
            JObject result = new JObject();

            string        page  = Request.Form["page"];
            string        limit = Request.Form["limit"];
            List <string> query = new List <string>()
            {
                page, limit
            };

            if (!m_incAdmin.OpString.DecideNull(query.ToArray()))
            {
                if (!m_incAdmin.OpString.DetectSql(query.ToArray(), Config.g_illegal))
                {
                    long          total = 0;
                    List <Models> list  = m_incAdmin.GetMessageList(page, limit, ref total);

                    result.Add("list", m_incAdmin.OpString.ToJsonArray(list.ToList <object>()));
                    result.Add("total", total);
                }
                else
                {
                    result.Add("error", SysError.GetErrorString("SYS001"));
                }
            }
            else
            {
                result.Add("error", SysError.GetErrorString("SYS002"));
            }

            return(new JsonResult(result.ToString()));
        }
        /// <summary>
        /// 获取充电桩枪状态
        /// </summary>
        /// <returns></returns>
        public string APP0003(string cp_code, long u_uname)
        {
            string outputData = "";

            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                         "<condition name=\"CP001\">" + SysError.GetErrorString("CP001") + "</condition>";
            if (Config.g_tcpClientDic.ContainsKey(cp_code))
            {
                try
                {
                    Dictionary <string, object> tcpClientDic = Config.g_tcpClientDic[cp_code];
                    if (tcpClientDic.ContainsKey("chargemod") && tcpClientDic.ContainsKey("data"))
                    {
                        int chargemod = (int)tcpClientDic["chargemod"];
                        switch (chargemod)
                        {
                        case 1:
                        {
                            Listener_ChargePile_Data_AC data = (Listener_ChargePile_Data_AC)tcpClientDic["data"];
                            List <bool?> guncondition        = data.gundata.Select(a => a.guncondition).ToList();
                            guncondition.RemoveAt(0);
                            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                                         "<condition name=\"SELECT000\">" + SysError.GetErrorString("SELECT000") + "</condition>" +
                                         "<list>" +
                                         "<guncondition>" + string.Join("|", guncondition) + "</guncondition>" +
                                         "</list>";
                        }
                        break;

                        case 2:
                        {
                            Listener_ChargePile_Data_DC data = (Listener_ChargePile_Data_DC)tcpClientDic["data"];
                            List <bool?> guncondition        = data.gundata.Select(a => a.guncondition).ToList();
                            guncondition.RemoveAt(0);
                            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                                         "<condition name=\"SELECT000\">" + SysError.GetErrorString("SELECT000") + "</condition>" +
                                         "<list>" +
                                         "<guncondition>" + string.Join("|", guncondition) + "</guncondition>" +
                                         "</list>";
                        }
                        break;
                        }
                    }
                }
                catch (Exception e)
                {
                    outputData = "<error name=\"API001\">" + SysError.GetErrorString("API001") + "</error>" +
                                 "<callback name=\"SYS003\">" + SysError.GetErrorString("SYS003") + "</callback>" +
                                 "<condition name=\"SELECT002\">" + SysError.GetErrorString("SELECT002") + "</condition>" +
                                 "<exception>" + e.Message + "</exception>";
                }
            }
            outputData = "<root>" + outputData + "</root>";
            return(outputData);
        }
Ejemplo n.º 7
0
        public IActionResult OnPostAddMessage()
        {
            JObject result = new JObject();

            string        m_name    = Request.Form["m_name"];
            string        m_email   = Request.Form["m_email"];
            string        m_content = Request.Form["m_content"];
            List <string> list      = new List <string>()
            {
                m_name, m_content
            };

            if (!m_inc.OpString.DecideNull(list.ToArray()))
            {
                list.Add(m_email);
                if (!m_inc.OpString.DetectSql(list.ToArray()))
                {
                    if (!m_inc.HasMessageToday())
                    {
                        g_message mod = new g_message();
                        mod.m_name    = m_name;
                        mod.m_email   = m_email;
                        mod.m_content = m_content;
                        mod.m_ip      = m_inc.OpMemory.IPAddress;
                        if (m_inc.AddMessage(mod))
                        {
                            result.Add("success", SysError.GetErrorString("MESSAGE000"));
                        }
                        else
                        {
                            result.Add("error", SysError.GetErrorString("MESSAGE001"));
                        }
                    }
                    else
                    {
                        result.Add("error", SysError.GetErrorString("MESSAGE002"));
                    }
                }
                else
                {
                    result.Add("error", SysError.GetErrorString("SYS001"));
                }
            }
            else
            {
                result.Add("error", SysError.GetErrorString("SYS002"));
            }

            return(new JsonResult(result.ToString()));
        }
        /// <summary>
        /// 发送结束充电请求
        /// </summary>
        /// <returns></returns>
        public string APP0004(long cs_id, string cp_code, long u_uname, long u_id, int cp_guncode)
        {
            Dictionary <string, object> tcpClientDic = Config.g_tcpClientDic[cp_code];

            string outputData = "";

            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                         "<condition name=\"SEND002\">" + SysError.GetErrorString("SEND002") + "</condition>";
            try
            {
                string version = tcpClientDic["version"].ToString();
                switch (version)
                {
                case "002":
                {
                    m_incTCPSend002.DW0006(cs_id, cp_code, cp_guncode);
                }
                break;

                case "003":
                {
                    m_incTCPSend003.DW0006(cs_id, cp_code, cp_guncode);
                }
                break;

                default:
                    throw new Exception();
                }
                outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                             "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                             "<condition name=\"SEND000\">" + SysError.GetErrorString("SEND000") + "</condition>";
            }
            catch (Exception e)
            {
                outputData = "<error name=\"API001\">" + SysError.GetErrorString("API001") + "</error>" +
                             "<callback name=\"SYS003\">" + SysError.GetErrorString("SYS003") + "</callback>" +
                             "<condition name=\"SEND002\">" + SysError.GetErrorString("SEND002") + "</condition>" +
                             "<exception>" + e.Message + "</exception>";
            }
            outputData = "<root>" + outputData + "</root>";
            return(outputData);
        }
Ejemplo n.º 9
0
        public IActionResult OnPostSaveMessage()
        {
            JObject result = new JObject();

            string        m_id     = Request.Form["m_id"];
            string        m_isread = Request.Form["m_isread"];
            List <string> query    = new List <string>()
            {
                m_id, m_isread
            };

            if (!m_incAdmin.OpString.DecideNull(query.ToArray()))
            {
                if (!m_incAdmin.OpString.DetectSql(query.ToArray(), Config.g_illegal))
                {
                    g_message mod = new g_message();
                    mod.m_id = int.Parse(m_id);
                    g_message mod2 = new g_message();
                    mod2.m_isread = bool.Parse(m_isread);
                    if (m_incAdmin.EditMessage(mod, mod2))
                    {
                        result.Add("success", SysError.GetErrorString("EDIT000"));
                    }
                    else
                    {
                        result.Add("error", SysError.GetErrorString("EDIT001"));
                    }
                }
                else
                {
                    result.Add("error", SysError.GetErrorString("SYS001"));
                }
            }
            else
            {
                result.Add("error", SysError.GetErrorString("SYS002"));
            }

            return(new JsonResult(result.ToString()));
        }
Ejemplo n.º 10
0
        private void Get_SysLogList(string strSql)
        {
            SysError  bllSysError = new SysError();
            int       Counts      = this.NetPagerParameter.RecordCount;
            DataTable db          = bllSysError.GetListSP(this.NetPagerParameter.PageSize, this.NetPagerParameter.CurrentPageIndex, out Counts, new string[]
            {
                strSql
            }).Tables[0];

            this.NetPagerParameter.RecordCount    = Counts;
            this.NetPagerParameter.CustomInfoHTML = string.Format("<div class=\"results\"><span>当前第{0}/{1}页 共{2}条记录 每页{3}条</span></div>", new object[]
            {
                this.NetPagerParameter.CurrentPageIndex,
                this.NetPagerParameter.PageCount,
                this.NetPagerParameter.RecordCount,
                this.NetPagerParameter.PageSize
            });
            this.gvwSysLogList.DataSource = db;
            this.gvwSysLogList.DataBind();
            PageBase.BindSerialGridView(this.gvwSysLogList, false, this.NetPagerParameter.PageSize * (this.NetPagerParameter.CurrentPageIndex - 1));
            PageBase.BindNullSGridView(this.gvwSysLogList);
        }
Ejemplo n.º 11
0
        public IActionResult OnPostLogin()
        {
            JObject result = new JObject();

            string        a_uname    = Request.Form["a_uname"];
            string        a_pwd      = Request.Form["a_pwd"];
            string        isremember = Request.Form["isremember"];
            List <string> query      = new List <string>()
            {
                a_uname, a_pwd
            };

            if (!m_incAdmin.OpString.DecideNull(query.ToArray()))
            {
                query.Add(isremember);
                if (!m_incAdmin.OpString.DetectSql(query.ToArray(), Config.g_illegal))
                {
                    if (m_incAdmin.Login(a_uname, a_pwd, string.IsNullOrEmpty(isremember)? false : bool.Parse(isremember)))
                    {
                        result.Add("success", SysError.GetErrorString("LOGIN000"));
                    }
                    else
                    {
                        result.Add("error", SysError.GetErrorString("LOGIN001"));
                    }
                }
                else
                {
                    result.Add("error", SysError.GetErrorString("SYS001"));
                }
            }
            else
            {
                result.Add("error", SysError.GetErrorString("SYS002"));
            }

            return(new JsonResult(result.ToString()));
        }
Ejemplo n.º 12
0
        public IActionResult OnPostDelNewsType()
        {
            JObject result = new JObject();

            string        nt_id = Request.Form["nt_id"];
            List <string> query = new List <string>()
            {
                nt_id
            };

            if (!m_incAdmin.OpString.DecideNull(query.ToArray()))
            {
                if (!m_incAdmin.OpString.DetectSql(query.ToArray(), Config.g_illegal))
                {
                    g_newstype mod = new g_newstype();
                    mod.nt_id = int.Parse(nt_id);
                    if (m_incAdmin.DelNewsType(mod))
                    {
                        result.Add("success", SysError.GetErrorString("DEL000"));
                    }
                    else
                    {
                        result.Add("error", SysError.GetErrorString("DEL001"));
                    }
                }
                else
                {
                    result.Add("error", SysError.GetErrorString("SYS001"));
                }
            }
            else
            {
                result.Add("error", SysError.GetErrorString("SYS002"));
            }

            return(new JsonResult(result.ToString()));
        }
        /// <summary>
        /// 添加充电站后更新充电站数据
        /// </summary>
        /// <returns></returns>
        public string WEB0001(long cs_id, Dispatcher dispatcher)
        {
            string outputData = "";

            try
            {
                List <Models> list = m_incChargeStation.GetChargeStation(cs_id);
                for (int i = 0; i < list.Count; i++)
                {
                    Listener_ChargeStation_Data mod = new Listener_ChargeStation_Data();
                    mod.name     = list[i].G_ChargeStation.cs_name;
                    mod.csid     = (long)list[i].G_ChargeStation.cs_id;
                    mod.pid      = list[i].G_Province.p_id;
                    mod.cid      = list[i].G_City.c_id;
                    mod.did      = list[i].G_District.d_id;
                    mod.place    = list[i].G_Province.p_name + list[i].G_City.c_name + list[i].G_District.d_name;
                    mod.cpsum_ac = "0";
                    mod.cpsum_dc = "0";
                    dispatcher.Invoke(new Action(delegate()
                    {
                        Config.g_dataList.Add(mod);
                    }));
                }
                outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                             "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                             "<condition name=\"MANAGE000\">" + SysError.GetErrorString("MANAGE000") + "</condition>";
            }
            catch (Exception e)
            {
                outputData = "<error name=\"API001\">" + SysError.GetErrorString("API001") + "</error>" +
                             "<callback name=\"SYS003\">" + SysError.GetErrorString("SYS003") + "</callback>" +
                             "<condition name=\"MANAGE001\">" + e.Message + "</condition>" +
                             "<exception>" + e.Message + "</exception>";
            }
            outputData = "<root>" + outputData + "</root>";
            return(outputData);
        }
Ejemplo n.º 14
0
        public IActionResult OnPostSaveNews()
        {
            JObject result = new JObject();

            string        n_id       = Request.Form["n_id"];
            string        nt_id      = Request.Form["nt_id"];
            string        n_title    = Request.Form["n_title"];
            string        n_content  = m_incAdmin.OpString.Escape(Request.Form["n_content"]);
            string        n_filename = Request.Form["n_filename"];
            IFormFile     file1      = Request.Form.Files["file1"];
            string        n_url      = Request.Form["n_url"];
            string        n_top      = Request.Form["n_top"];
            string        n_examine  = Request.Form["n_examine"];
            List <string> query      = new List <string>()
            {
                nt_id, n_title, n_content, n_top, n_examine
            };

            if (!m_incAdmin.OpString.DecideNull(query.ToArray()))
            {
                query.AddRange(new string[] { n_id, n_filename, n_url });
                if (!m_incAdmin.OpString.DetectSql(query.ToArray(), Config.g_illegal))
                {
                    DateTime n_addtime = (string)Request.Form["n_addtime"] == null ? DateTime.Now : DateTime.Parse(Request.Form["n_addtime"]);
                    string   imgpath   = string.Format("{0}News/{1}/img/", Config.g_filepath, n_addtime.ToString("yyyy-MM-dd"));
                    if (string.IsNullOrEmpty(n_id))
                    {
                        if (file1 != null && file1.Length > 0)
                        {
                            try
                            {
                                n_filename = m_incAdmin.OpFile.UploadFile(file1, imgpath, Config.g_imgtype, Config.g_imgmax);
                            }
                            catch (Exception e)
                            {
                                result.Add("error", e.Message);
                                return(new JsonResult(result.ToString()));
                            }
                        }

                        g_news mod = new g_news();
                        mod.nt_id      = int.Parse(nt_id);
                        mod.n_title    = n_title;
                        mod.n_content  = n_content;
                        mod.n_filename = n_filename;
                        mod.n_url      = n_url;
                        mod.n_top      = int.Parse(n_top);
                        mod.n_examine  = bool.Parse(n_examine);
                        mod.n_addtime  = n_addtime;
                        if (m_incAdmin.AddNews(mod))
                        {
                            result.Add("success", SysError.GetErrorString("ADD000"));
                        }
                        else
                        {
                            result.Add("error", SysError.GetErrorString("ADD001"));
                        }
                    }
                    else
                    {
                        if (file1 != null && file1.Length > 0)
                        {
                            try
                            {
                                string n_filename_old = n_filename;
                                n_filename = m_incAdmin.OpFile.UploadFile(file1, imgpath, Config.g_imgtype, Config.g_imgmax);
                                m_incAdmin.OpFile.DelFile(imgpath + n_filename_old);
                            }
                            catch (Exception e)
                            {
                                result.Add("error", e.Message);
                                return(new JsonResult(result.ToString()));
                            }
                        }

                        g_news mod = new g_news();
                        mod.n_id = int.Parse(n_id);
                        g_news mod2 = new g_news();
                        mod2.nt_id      = int.Parse(nt_id);
                        mod2.n_title    = n_title;
                        mod2.n_content  = n_content;
                        mod2.n_filename = n_filename;
                        mod2.n_url      = n_url;
                        mod2.n_top      = int.Parse(n_top);
                        mod2.n_examine  = bool.Parse(n_examine);
                        if (m_incAdmin.EditNews(mod, mod2))
                        {
                            result.Add("success", SysError.GetErrorString("EDIT000"));
                        }
                        else
                        {
                            result.Add("error", SysError.GetErrorString("EDIT001"));
                        }
                    }
                }
                else
                {
                    result.Add("error", SysError.GetErrorString("SYS001"));
                }
            }
            else
            {
                result.Add("error", SysError.GetErrorString("SYS002"));
            }

            return(new JsonResult(result.ToString()));
        }
        /// <summary>
        /// 发送充电请求
        /// </summary>
        /// <returns></returns>
        public string APP0001(long cs_id, string cp_code, long u_uname, long u_id, int cp_guncode, int calmod, string cal)
        {
            string outputData = "";

            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                         "<condition name=\"SEND002\">" + SysError.GetErrorString("SEND002") + "</condition>";
            try
            {
                Dictionary <string, object> tcpClientDic = Config.g_tcpClientDic[cp_code];
                if (Config.g_tcpClientDic.ContainsKey(cp_code))
                {
                    int  chargemod = (int)tcpClientDic["chargemod"];
                    bool b         = false;
                    switch (chargemod)
                    {
                    case 1:
                    {
                        Listener_ChargePile_Data_AC data = (Listener_ChargePile_Data_AC)tcpClientDic["data"];
                        if (!(bool)data.gundata[cp_guncode].guncondition)
                        {
                            b = true;
                        }
                    }
                    break;

                    case 2:
                    {
                        Listener_ChargePile_Data_DC data = (Listener_ChargePile_Data_DC)tcpClientDic["data"];
                        if (!(bool)data.gundata[cp_guncode].guncondition)
                        {
                            b = true;
                        }
                    }
                    break;
                    }
                    if (b)
                    {
                        bool   b2      = false;
                        string version = tcpClientDic["version"].ToString();
                        switch (version)
                        {
                        case "002":
                        {
                            b2 = m_incTCPSend002.DW0002(cs_id, cp_code, u_uname, u_id, cp_guncode, calmod, cal);
                        }
                        break;

                        case "003":
                        {
                            b2 = m_incTCPSend003.DW0002(cs_id, cp_code, u_uname, u_id, cp_guncode, calmod, cal);
                        }
                        break;

                        default:
                            throw new Exception();
                        }
                        if (b2)
                        {
                            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                                         "<condition name=\"SEND000\">" + SysError.GetErrorString("SEND000") + "</condition>";
                        }
                    }
                    else
                    {
                        outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                                     "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                                     "<condition name=\"SEND004\">" + SysError.GetErrorString("SEND004") + "</condition>";
                    }
                }
            }
            catch (Exception e)
            {
                outputData = "<error name=\"API001\">" + SysError.GetErrorString("API001") + "</error>" +
                             "<callback name=\"SYS003\">" + SysError.GetErrorString("SYS003") + "</callback>" +
                             "<condition name=\"SEND002\">" + SysError.GetErrorString("SEND002") + "</condition>" +
                             "<exception>" + e.Message + "</exception>";
            }
            outputData = "<root>" + outputData + "</root>";
            return(outputData);
        }
Ejemplo n.º 16
0
        public IActionResult OnPostSaveNewsType()
        {
            JObject result = new JObject();

            string        nt_id      = Request.Form["nt_id"];
            string        nt_name    = Request.Form["nt_name"];
            string        nt_pid     = Request.Form["nt_pid"];
            string        nt_top     = Request.Form["nt_top"];
            string        nt_examine = Request.Form["nt_examine"];
            List <string> query      = new List <string>()
            {
                nt_name, nt_pid, nt_top, nt_examine
            };

            if (!m_incAdmin.OpString.DecideNull(query.ToArray()))
            {
                query.AddRange(new string[] { nt_id });
                if (!m_incAdmin.OpString.DetectSql(query.ToArray(), Config.g_illegal))
                {
                    if (string.IsNullOrEmpty(nt_id))
                    {
                        g_newstype mod = new g_newstype();
                        mod.nt_name    = nt_name;
                        mod.nt_pid     = int.Parse(nt_pid);
                        mod.nt_top     = int.Parse(nt_top);
                        mod.nt_examine = bool.Parse(nt_examine);
                        if (m_incAdmin.AddNewsType(mod))
                        {
                            result.Add("success", SysError.GetErrorString("ADD000"));
                        }
                        else
                        {
                            result.Add("error", SysError.GetErrorString("ADD001"));
                        }
                    }
                    else
                    {
                        g_newstype mod = new g_newstype();
                        mod.nt_id = int.Parse(nt_id);
                        g_newstype mod2 = new g_newstype();
                        mod2.nt_name    = nt_name;
                        mod2.nt_pid     = int.Parse(nt_pid);
                        mod2.nt_top     = int.Parse(nt_top);
                        mod2.nt_examine = bool.Parse(nt_examine);
                        if (m_incAdmin.EditNewsType(mod, mod2))
                        {
                            result.Add("success", SysError.GetErrorString("EDIT000"));
                        }
                        else
                        {
                            result.Add("error", SysError.GetErrorString("EDIT001"));
                        }
                    }
                }
                else
                {
                    result.Add("error", SysError.GetErrorString("SYS001"));
                }
            }
            else
            {
                result.Add("error", SysError.GetErrorString("SYS002"));
            }

            return(new JsonResult(result.ToString()));
        }
        /// <summary>
        /// 获取充电桩充电数据
        /// </summary>
        /// <returns></returns>
        public string APP0002(string cp_code, int cp_guncode, long u_uname)
        {
            string outputData = "";

            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                         "<condition name=\"CP001\">" + SysError.GetErrorString("CP001") + "</condition>";
            if (Config.g_tcpClientDic.ContainsKey(cp_code))
            {
                try
                {
                    Dictionary <string, object> tcpClientDic = Config.g_tcpClientDic[cp_code];
                    if (tcpClientDic.ContainsKey("chargemod") && tcpClientDic.ContainsKey("data"))
                    {
                        int chargemod = (int)tcpClientDic["chargemod"];
                        switch (chargemod)
                        {
                        case 1:
                        {
                            Listener_ChargePile_Data_AC data = (Listener_ChargePile_Data_AC)tcpClientDic["data"];
                            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                                         "<condition name=\"SELECT000\">" + SysError.GetErrorString("SELECT000") + "</condition>" +
                                         "<list>" +
                                         "<timeleft>" + ((TimeSpan)data.gundata[cp_guncode].timeleft).TotalMilliseconds.ToString() + "</timeleft>" +
                                         "<money>" + (Convert.ToDouble(data.unitmoney) * (double)data.gundata[cp_guncode].kwh).ToString("0.00") + "</money>" +
                                         "<kwh>" + data.gundata[cp_guncode].kwh + "</kwh>" +
                                         "<chargemod>" + data.gundata[cp_guncode].chargemod + "</chargemod>" +
                                         "<chargemodcontent>" + data.gundata[cp_guncode].chargemodcontent + "</chargemodcontent>" +
                                         "</list>";
                        }
                        break;

                        case 2:
                        {
                            Listener_ChargePile_Data_DC data = (Listener_ChargePile_Data_DC)tcpClientDic["data"];
                            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                                         "<condition name=\"SELECT000\">" + SysError.GetErrorString("SELECT000") + "</condition>" +
                                         "<list>" +
                                         "<timeleft>" + ((TimeSpan)data.gundata[cp_guncode].timeleft).TotalMilliseconds.ToString() + "</timeleft>" +
                                         "<money>" + (Convert.ToDouble(data.unitmoney) * (double)data.gundata[cp_guncode].kwh).ToString("0.00") + "</money>" +
                                         "<kwh>" + data.gundata[cp_guncode].kwh + "</kwh>" +
                                         "<chargemod>" + data.gundata[cp_guncode].chargemod + "</chargemod>" +
                                         "<chargemodcontent>" + data.gundata[cp_guncode].chargemodcontent + "</chargemodcontent>" +
                                         "</list>";
                        }
                        break;
                        }
                    }
                }
                catch (Exception e)
                {
                    outputData = "<error name=\"API001\">" + SysError.GetErrorString("API001") + "</error>" +
                                 "<callback name=\"SYS003\">" + SysError.GetErrorString("SYS003") + "</callback>" +
                                 "<condition name=\"SELECT002\">" + SysError.GetErrorString("SELECT002") + "</condition>" +
                                 "<exception>" + e.Message + "</exception>";
                }
            }
            outputData = "<root>" + outputData + "</root>";
            return(outputData);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// 开始tcp连接
 /// </summary>
 void TCPStar()
 {
     //连接远程服务器
     try
     {
         Config.g_tcpClient = new TcpClient();
         Config.g_tcpClient.Connect(Config.g_hostname, Config.g_port);
         Config.g_socket = Config.g_tcpClient.Client;
     }
     catch
     {
         SysError.GetError("SERVERLINK001");
     }
     //开始监听
     if (Config.g_socket != null)
     {
         m_incTCPSend001.UP0002(Config.cs_uname, Config.cs_pwd);
         try
         {
             if (Config.g_socket.Poll(-1, SelectMode.SelectRead))
             {
                 byte[] receiveBytes = new byte[Config.g_socket.Available];
                 int    nRead        = Config.g_socket.Receive(receiveBytes);
                 if (nRead == 0)
                 {
                     SysError.GetError("SERVERLINK001");
                     throw new Exception("远程连接主动断开");
                 }
                 else if (nRead != receiveBytes.Length)
                 {
                     SysError.GetError("SERVERLINK001");
                     throw new Exception("出现丢包,主动断开连接");
                 }
                 else
                 {
                     //解析成文本
                     string data = Encoding.UTF8.GetString(receiveBytes);
                     //获取命令
                     string[] dataArr = Regex.Split(data, "\\)\\(", RegexOptions.IgnoreCase);
                     for (int i = 0; i < dataArr.Length; i++)
                     {
                         //删除包头和包尾
                         string receiveData = dataArr[i].Trim('(', ')');
                         //取得协议版本号
                         string version = Regex.Match(receiveData, "^.{3}").ToString();
                         //取得充电站编号
                         string csid = Regex.Match(receiveData, "(?<=^.{3}).{10}").ToString();
                         if (version == "001")
                         {
                             //取得校验位
                             string parity = Regex.Match(receiveData, "(?<=^.{13}).{4}").ToString();
                             //取得命令字
                             string number = Regex.Match(receiveData, "(?<=^.{17}).{6}").ToString();
                             //取得消息体
                             string bodyData = Regex.Match(receiveData, "(?<=^.{23}).*").ToString();
                             if (parity == CRC16.GetString(number + bodyData))
                             {
                                 if (number == "DW0002")
                                 {
                                     string code = "";
                                     if (m_incTCPReceive001.DW0002(bodyData, ref code))
                                     {
                                         try
                                         {
                                             //登录成功
                                             if ((bool)check_remember.IsChecked)
                                             {
                                                 using (StreamWriter sw = new StreamWriter(Config.g_root + "\\config.ini"))
                                                 {
                                                     sw.WriteLine("check_remember_checked:true");
                                                     sw.WriteLine("text_name_text:" + text_name.Text);
                                                 }
                                             }
                                             Config.cs_id = long.Parse(csid);
                                             new Main().Show();
                                             this.Close();
                                         }
                                         catch
                                         {
                                             //登录失败
                                             SysError.GetError("LOGIN001");
                                             throw new Exception("系统错误,登录失败");
                                         }
                                     }
                                     else
                                     {
                                         //登录失败
                                         SysError.GetError(code);
                                         throw new Exception("登录失败");
                                     }
                                 }
                                 else
                                 {
                                     SysError.GetError("SERVERLINK001");
                                     throw new Exception("错误的命令");
                                 }
                             }
                             else
                             {
                                 SysError.GetError("SERVERLINK001");
                                 throw new Exception("丢包");
                             }
                         }
                         else
                         {
                             SysError.GetError("SERVERLINK001");
                             throw new Exception("错误的协议");
                         }
                     }
                 }
             }
             else
             {
                 SysError.GetError("SERVERLINK001");
                 throw new Exception("远程连接主动断开");
             }
         }
         catch
         {
             //SysError.GetError("SERVERLINK001");
             TCPStop();
         }
     }
 }
        /// <summary>
        /// 获取用户充电状态
        /// </summary>
        /// <returns></returns>
        public string APP0005(long u_uname, long u_id)
        {
            string outputData = "";

            outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                         "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                         "<condition name=\"SELECT001\">" + SysError.GetErrorString("SELECT001") + "</condition>";
            Dictionary <string, Dictionary <string, object> > mdic = null;

            try
            {
                lock (Config.g_tcpClientDic)
                {
                    //深拷贝
                    mdic = new Dictionary <string, Dictionary <string, object> >(Config.g_tcpClientDic);
                }
                if (mdic != null)
                {
                    List <long> list = new List <long>();
                    string      cs_id = null, cp_code = null, cp_guncode = null;
                    bool        cp_guncondition = false;
                    foreach (Dictionary <string, object> dic in mdic.Values)
                    {
                        int chargemod = (int)dic["chargemod"];
                        switch (chargemod)
                        {
                        case 1:
                        {
                            //交流
                            Listener_ChargePile_Data_AC cp = (Listener_ChargePile_Data_AC)dic["data"];
                            List <long?> list2             = cp.gundata.Select(a => a.useruname).ToList();
                            if (cp.gundata.Select(a => a.useruname).ToArray().Contains(u_uname) &&
                                (bool)cp.gundata.Select(a => a.guncondition).ToArray()[Array.IndexOf(cp.gundata.Select(a => a.useruname).ToArray(), u_uname)])
                            {
                                cs_id           = cp.cs_id.ToString();
                                cp_code         = cp.cp_code;
                                cp_guncode      = Array.IndexOf(cp.gundata.Select(a => a.useruname).ToArray(), u_uname).ToString();
                                cp_guncondition = (bool)cp.gundata.Select(a => a.guncondition).ToArray()[int.Parse(cp_guncode)];
                                break;
                            }
                        }
                        break;

                        case 2:
                        {
                            //直流
                            Listener_ChargePile_Data_DC cp = (Listener_ChargePile_Data_DC)dic["data"];
                            if (cp.gundata.Select(a => a.useruname).ToArray().Contains(u_uname) &&
                                (bool)cp.gundata.Select(a => a.guncondition).ToArray()[Array.IndexOf(cp.gundata.Select(a => a.useruname).ToArray(), u_uname)])
                            {
                                cs_id           = cp.cs_id.ToString();
                                cp_code         = cp.cp_code;
                                cp_guncode      = Array.IndexOf(cp.gundata.Select(a => a.useruname).ToArray(), u_uname).ToString();
                                cp_guncondition = (bool)cp.gundata.Select(a => a.guncondition).ToArray()[int.Parse(cp_guncode)];
                                break;
                            }
                        }
                        break;
                        }
                    }
                    if (cp_guncondition && cs_id != null && cp_code != null && cp_guncode != null)
                    {
                        outputData = "<error name=\"API000\">" + SysError.GetErrorString("API000") + "</error>" +
                                     "<callback name=\"SYS000\">" + SysError.GetErrorString("SYS000") + "</callback>" +
                                     "<condition name=\"SELECT000\">" + SysError.GetErrorString("SELECT000") + "</condition>" +
                                     "<list>" +
                                     "<cs_id>" + cs_id + "</cs_id>" +
                                     "<cp_code>" + cp_code + "</cp_code>" +
                                     "<cp_guncode>" + cp_guncode + "</cp_guncode>" +
                                     "</list>";
                    }
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                string dic = "";
                if (mdic != null)
                {
                    foreach (string key in mdic.Keys)
                    {
                        dic += key + "|";
                    }
                }
                outputData = "<error name=\"API001\">" + SysError.GetErrorString("API001") + "</error>" +
                             "<callback name=\"SYS003\">" + SysError.GetErrorString("SYS003") + "</callback>" +
                             "<condition name=\"SELECT002\">" + SysError.GetErrorString("SELECT002") + "</condition>" +
                             "<exception>" + e.Message + e.StackTrace + "</exception>" +
                             "<dic>" + dic + "</dic>";
            }
            outputData = "<root>" + outputData + "</root>";
            return(outputData);
        }