using CallCenterApi.Common; using CallCenterApi.DB; using CallCenterApi.Interface.App_Start; using CallCenterApi.Interface.Controllers.Base; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Mvc; namespace CallCenterApi.Interface.Controllers.County { public class CountyBranchController : BaseController { // GET: CountyBranch private BLL.T_Branch_List branchBLL = new BLL.T_Branch_List(); #region 网点 /// /// 获取所有网点 /// /// [OutActionFilter] public ActionResult GetCityList(string code,string name) { string sql = " F_IsDelete=0 "; if (!string.IsNullOrEmpty(code)) { sql += " and F_Code like '%" + code + "%' "; } if (!string.IsNullOrEmpty(name)) { sql += " and F_Name like '%" + name + "%' "; } DataTable dt = branchBLL.GetList(sql).Tables[0]; return Success("成功", dt); } /// /// 获取详情 /// /// /// [OutActionFilter] public ActionResult GetCityDetail(string code) { string sql = " F_IsDelete=0 "; if (!string.IsNullOrEmpty(code)) { sql += " and F_Code = '" + code + "' "; } var model = branchBLL.GetModelList(sql).FirstOrDefault(); return Success("成功", model); } /// /// 获取网点列表 /// /// [Authority] public ActionResult GetList(int isdc = 0) { Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]); DataTable dt = new DataTable(); string sql = " and F_IsDelete=0 "; string strcode = HttpUtility.UrlDecode(RequestString.GetQueryString("code")); string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name")); string strpageindex = RequestString.GetQueryString("page"); int pageindex = 1; string strpagesize = RequestString.GetQueryString("pagesize"); int pagesize = 10; if (strcode.Trim() != "" && strcode != "undefined") { sql += " and F_Code like '%" + strcode + "%' "; } if (strname.Trim() != "" && strname != "undefined") { sql += " and F_Name like '%" + strname + "%' "; } if (strpageindex.Trim() != "") { pageindex = Convert.ToInt32(strpageindex); } if (strpagesize.Trim() != "") { pagesize = Convert.ToInt32(strpagesize); } string cols = "*,dbo.GetUserName(F_CreateUser) as UserName"; if (isdc > 0) { var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Branch_List where 1=1 " + sql).Tables[0]; var msg = new NPOIHelper().ExportToExcel("网点列表", dtdc); if (msg == "") { return Success("导出成功"); } else { return Error("导出失败"); } } int recordCount = 0; dt = BLL.PagerBLL.GetListPager( "T_Branch_List", "F_Id", cols, sql, "ORDER BY F_CreateTime DESC", pagesize, pageindex, true, out recordCount); var obj = new { state = "success", message = "成功", rows = dt, total = recordCount }; return Content(obj.ToJson()); } /// /// 获取网点列表 /// /// [Authority] public ActionResult GetBranchList() { DataTable dt = branchBLL.GetList(" F_IsDelete=0 ").Tables[0]; return Success("加载成功", dt); } /// /// 获取网点 /// /// /// [Authority] public ActionResult GetBranch() { int id = RequestString.GetInt("id", 0); Model.T_Branch_List dModel = branchBLL.GetModel(id); if (dModel != null) return Success("获取信息成功", dModel); return Error("获取信息失败"); } /// /// 添加网点 /// /// /// [HttpPost] [Authority] public ActionResult AddBranch() { Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]); int id = RequestString.GetInt("id", 0); string code = RequestString.GetFormString("code"); string name = RequestString.GetFormString("name"); string pwd = RequestString.GetFormString("pwd"); string address = RequestString.GetFormString("address"); string conname = RequestString.GetFormString("conname"); string conphone = RequestString.GetFormString("conphone"); string contel = RequestString.GetFormString("contel"); string conemail = RequestString.GetFormString("conemail"); string url = RequestString.GetFormString("url"); string sign = RequestString.GetFormString("sign"); string wsurl = RequestString.GetFormString("wsurl"); string phone = RequestString.GetFormString("phone"); Model.T_Branch_List dModel = new Model.T_Branch_List(); if (id == 0) { var list = branchBLL.GetModelList(" F_Name='" + name + "' "); if (list.Count > 0) { return Error("已经存在此网点"); } else { dModel.F_Code = code; dModel.F_Name = name; dModel.F_Password = pwd; dModel.F_Address = address; dModel.F_ConName = conname; dModel.F_ConPhone = conphone; dModel.F_ConTel = contel; dModel.F_ConEmail = conemail; dModel.F_Url = url; dModel.F_Sign = sign; dModel.F_WebSocketUrl = wsurl; dModel.F_Phone = phone; dModel.F_IsDelete = 0; dModel.F_State = 0; dModel.F_CreateUser = userModel.F_UserCode; dModel.F_CreateTime = DateTime.Now; int n = branchBLL.Add(dModel); if (n > 0) return Success("添加成功", n); else return Error("添加失败"); } } else { dModel = branchBLL.GetModel(id); if (dModel != null) { var list = branchBLL.GetModelList(" F_Name='" + name + "' and F_Id!='" + id + "' "); if (list.Count > 0) { return Error("已经存在此网点"); } else { dModel.F_Code = code; dModel.F_Name = name; dModel.F_Password = pwd; dModel.F_Address = address; dModel.F_ConName = conname; dModel.F_ConPhone = conphone; dModel.F_ConTel = contel; dModel.F_ConEmail = conemail; dModel.F_Url = url; dModel.F_Sign = sign; dModel.F_WebSocketUrl = wsurl; dModel.F_Phone = phone; if (branchBLL.Update(dModel)) return Success("修改成功"); else return Error("修改失败"); } } else { return Error("修改失败"); } } } /// /// 删除网点 /// /// /// [Authority] public ActionResult DelBranch(string[] ids) { if (ids == null || ids.Length <= 0) return Error("请选择要删除的网点"); var idStr = string.Join(",", ids); if (string.IsNullOrEmpty(idStr.Trim())) return Error("请选择要删除的网点"); if (branchBLL.DeleteList(idStr)) return Success("删除成功"); return Error("删除失败"); } /// /// 删除网点 /// /// /// [Authority] public ActionResult DelBranchs(int id) { if (id > 0) { if (new BLL.T_Branch_List().Delete(id)) { return Success("删除成功"); } else { return Error("删除失败"); } } else { return Error("删除失败"); } } //大屏展示使用 /// /// 获取网点列表 /// /// //[Authority] public ActionResult GetBranchListS() { DataTable dt = branchBLL.GetList(" F_IsDP=1 ").Tables[0]; return Success("加载成功", dt); } #endregion } }