using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace LYFZ.WeixinServers.LoginApi { public partial class enterprise : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod.ToUpper() == "GET") return; if (Request.QueryString["type"] != null) { string strOptType = Request.QueryString["type"]; if (!string.IsNullOrEmpty(strOptType)) { if (strOptType.StartsWith("sys-")) { string strUser, strUserPsw; if (VerifySysParam(out strUser, out strUserPsw)) { LoginModel.user model = GlobalCache.GetUserInfo(strUser, strUserPsw); if (model == null) { Response.Write("{\"code\":201, \"msg\":\"账号或密码不对\"}"); return; } if (model.user_type != 0) { Response.Write("{\"code\":201, \"msg\":\"账号操作权限不足\"}"); return; } switch (strOptType) { case "sys-add": { OptSysAdd(); } break; case "sys-delete": { OptSysDelete(); } break; case "sys-modify": { OptSysModify(); } break; case "sys-query": { OptSysQuery(); } break; default: break; } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } else { } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } public bool VerifySysParam(out string strUser, out string strUserPsw) { strUser = strUserPsw = ""; if (this.Request.Form["user"] != null && this.Request.Form["user_psw"] != null ) { strUser = this.Request.Form["user"]; strUserPsw = this.Request.Form["user_psw"]; if (string.IsNullOrEmpty(strUser) || string.IsNullOrEmpty(strUserPsw) ) return false; return true; } return false; } public void OptSysAdd() { bool hasnull = false; Dictionary PostParam = new Dictionary(); string[] not_null_field = { "ind_name", "ent_name", "ent_leal_persion", "ent_phone", "ent_web_site", "ent_address", "ent_kf_count", "ent_kf_usage_days", "server_id", "ent_note" }; foreach (string str in not_null_field ) { if (Request.Form[str] == null) { hasnull = true; break; } PostParam.Add(str, Request.Form[str]); } if ( hasnull ) { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } else { string ind_name = PostParam["ind_name"]; if ( string.IsNullOrEmpty( PostParam["ent_name"]) || string.IsNullOrEmpty(ind_name) ) { Response.Write("{\"code\":201, \"msg\":\"行业名或企业名不能为空\"}"); return; } try { LoginModel.enterprise model = new LoginModel.enterprise(); LoginModel.industry model_ind = new LoginModel.industry(); DataSet ds = GlobalCache.DalIndustry.GetList("ind_name = '" + ind_name + "'", "id"); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { model_ind = GlobalCache.DalIndustry.DataRowToModel(ds.Tables[0].Rows[0]); model.ind_id = model_ind.ind_id; model.ent_id = GlobalCache.GuidString(); model.ent_name = PostParam["ent_name"]; model.ent_leal_persion = PostParam["ent_leal_persion"]; model.ent_phone = PostParam["ent_phone"]; model.ent_web_site = PostParam["ent_web_site"]; model.ent_address = PostParam["ent_address"]; model.ent_kf_count = Convert.ToInt32(PostParam["ent_kf_count"].ToString()); model.ent_kf_usage_days = Convert.ToInt32(PostParam["ent_kf_usage_days"].ToString()); model.server_id = PostParam["server_id"]; model.ent_note = PostParam["ent_note"]; GlobalCache.DalEnterprise.Add(model); Response.Write("{\"code\":200, \"msg\":\"添加企业成功\"}"); } } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } } public void OptSysDelete() { if ( Request.Form["ent_id"] != null ) { string strEntId = Request.Form["ent_id"]; try { LoginModel.enterprise model = new LoginModel.enterprise(); DataSet ds = GlobalCache.DalEnterprise.GetList("ent_id = '" + strEntId + "'", "id"); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { model = GlobalCache.DalEnterprise.DataRowToModel(ds.Tables[0].Rows[0]); GlobalCache.DalEnterprise.Delete(model.id); Response.Write("{\"code\":200, \"msg\":\"删除成功\"}"); } else { Response.Write("{\"code\":201, \"msg\":\"没有该企业信息\"}"); } } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } else { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } } public void OptSysModify() { bool hasnull = false; Dictionary PostParam = new Dictionary(); string[] not_null_field = { "ent_id", "ent_name", "ent_leal_persion", "ent_phone", "ent_web_site", "ent_address", "ent_kf_count", "ent_kf_usage_days", "server_id", "ent_note" }; foreach (string str in not_null_field) { if (Request.Form[str] == null) { hasnull = true; break; } PostParam.Add(str, Request.Form[str]); } if (hasnull) { Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}"); } else { LoginModel.enterprise model = new LoginModel.enterprise(); model.ent_id = PostParam["ent_id"]; model.ent_name = PostParam["ent_name"]; if (string.IsNullOrEmpty(model.ent_id) || string.IsNullOrEmpty(model.ent_name)) { Response.Write("{\"code\":201, \"msg\":\"企业id或企业名不能为空\"}"); return; } try { model.ent_leal_persion = PostParam["ent_leal_persion"]; model.ent_phone = PostParam["ent_phone"]; model.ent_web_site = PostParam["ent_web_site"]; model.ent_address = PostParam["ent_address"]; model.ent_kf_count = Convert.ToInt32(PostParam["ent_kf_count"].ToString()); model.ent_kf_usage_days = Convert.ToInt32(PostParam["ent_kf_usage_days"].ToString()); model.server_id = PostParam["server_id"]; model.ent_note = PostParam["ent_note"]; if ( GlobalCache.DalEnterprise.UpdateEx(model) ) Response.Write("{\"code\":200, \"msg\":\"修改企业成功\"}"); else Response.Write("{\"code\":200, \"msg\":\"修改企业失败,该企业可能不存在\"}"); } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } } public void OptSysQuery() { List listModel = new List(); if (Request.Form["ent_id"] != null) {// 查询单个; string strEntId = Request.Form["ent_id"]; try { LoginModel.enterprise model = new LoginModel.enterprise(); DataSet ds = GlobalCache.DalEnterprise.GetList("ent_id = '" + strEntId + "'", "id"); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { model = GlobalCache.DalEnterprise.DataRowToModel(ds.Tables[0].Rows[0]); listModel.Add(model); string strJson = JsonConvert.SerializeObject(listModel); Response.Write(strJson); } else { Response.Write("{\"code\":201, \"msg\":\"没有该企业信息\"}"); } } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } else {// 查询全部; try { LoginModel.enterprise model = new LoginModel.enterprise(); DataSet ds = GlobalCache.DalEnterprise.GetAllList("id"); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { model = GlobalCache.DalEnterprise.DataRowToModel(ds.Tables[0].Rows[0]); listModel.Add(model); } string strJson = JsonConvert.SerializeObject(listModel); Response.Write(strJson); } else { Response.Write("{\"code\":200, \"msg\":\"没有业信息\"}"); } } catch (Exception ex) { Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}"); } } } } }