using DBUtility; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SQLHelper; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Web; using System.Web.Http; using WebAPI.Code; using WebAPI.Models; namespace WebAPI.Controllers { public class BasicInfoController : ApiController { private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; /// /// 返回货币列表 ///参数:string sql。 ///返回值:object。 /// [Route("Gy_Currency/list1")] [HttpGet] public object list(string sWhere, string user) { try { List columnNameList = new List(); if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("select * from h_v_Gy_CurrencyList where 禁用标记=''" + sWhere + " order by 货币代码", "h_v_Gy_CurrencyList"); } else { string sql1 = "select * from h_v_Gy_CurrencyList where 禁用标记='' "; string sql = sql1 + sWhere + " order by 货币代码"; ds = oCN.RunProcReturn(sql, "h_v_Gy_CurrencyList"); } //添加列名 foreach (DataColumn col in ds.Tables[0].Columns) { Type dataType = col.DataType; string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = columnNameList; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } /// /// 获取物料列表 /// /// [Route("Web/GetMaterialList_Json")] [HttpGet] public object GetMaterialList_Json(string sWhere) { try { List columnNameList = new List(); if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("select * from h_v_IF_Material " + sWhere + " order by HNumber", "h_v_IF_Material"); } else { string sql1 = "select * from h_v_IF_Material "; string sql = sql1 + sWhere + " order by HNumber"; ds = oCN.RunProcReturn(sql, "h_v_IF_Material"); } //添加列名 foreach (DataColumn col in ds.Tables[0].Columns) { Type dataType = col.DataType; string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = columnNameList; return objJsonResult; } catch (Exception ex) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "获取失败" + ex.ToString(); objJsonResult.data = null; return objJsonResult; } } /// /// 返回供应商列表 ///参数:string sql。 ///返回值:object。 /// [Route("Gy_Supplier/list")] [HttpGet] public object list(string sWhere, string user, string Organization) { try { List columnNameList = new List(); string sql1 = string.Format(@"select * from h_v_Gy_SupplierList where 组织名称='" + Organization + "'"); if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn(sql1 + sWhere + " order by 供应商代码", "h_v_Gy_SupplierList"); } else { string sql = sql1 + sWhere + " order by 供应商代码 "; ds = oCN.RunProcReturn(sql, "h_v_Gy_SupplierList"); } //添加列名 foreach (DataColumn col in ds.Tables[0].Columns) { Type dataType = col.DataType; string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = columnNameList; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } /// /// 获取单位列表 /// /// [Route("Web/GetUnitList_Json")] [HttpGet] public object GetUnitList_Json(string Unit) { string sWhere = ""; if (Unit != "") { sWhere = sWhere + " and ( HNumber like '%" + Unit + "%' or HName like '%" + Unit + "%' ) "; } try { SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("Select HItemID,HNumber ,HName from Gy_Unit where HStopflag=0 Order by HItemID ", "Gy_Unit"); } else { string sql1 = "Select HItemID,HNumber ,HName from Gy_Unit where HStopflag=0 and HEndFlag=1 "; string sql = sql1 + sWhere; ds = oCN.RunProcReturn(sql, "Gy_Unit"); } if (ds == null || ds.Tables[0].Rows.Count <= 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "获取失败" + DBUtility.ClsPub.sErrInfo; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "获取成功!"; objJsonResult.data = ds.Tables[0]; return objJsonResult; } } catch (Exception ex) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "获取失败" + ex.ToString(); objJsonResult.data = null; return objJsonResult; } } } }