using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using WebAPI.Models; namespace WebAPI.Controllers.仓存管理.委外用料 { public class WW_PPBomBillController : ApiController { public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更) private json objJsonResult = new json(); public DataSet ds = new DataSet(); public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); public DLL.ClsWW_PPBomBill BillNew0 = new DLL.ClsWW_PPBomBill(); public DLL.ClsWW_PPBomBill BillOld0 = new DLL.ClsWW_PPBomBill(); #region 委外用料列表 [Route("WW_PPBomBillController/Get_WW_PPBomBillList")] [HttpGet] public object Get_WW_PPBomBillList(string sWhere,string user) { try { List columnNameList = new List(); //定义声明变量 ,把通过 new List()创建的 实例,赋值给变量 //判断是否有查询权限 if (!DBUtility.ClsPub.Security_Log("WW_PPBomBill_Query", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查询权限!"; objJsonResult.data = null; return objJsonResult; } ds = WW_PPBomBillList(sWhere); if (ds.Tables[0].Rows.Count != 0 || ds != null) { foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用 { Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接 // 将列名和数据类型信息拼接成一个JSON格式的字符串 columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0];//代码将第一个DataTable(索引为0)赋值给objJsonResult的data属性 objJsonResult.list = columnNameList;//将columnNameList赋值给objJsonResult的list属性 return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无数据"; objJsonResult.data = null; return objJsonResult; } } catch (Exception ex) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString(); objJsonResult.data = null; return objJsonResult; } } public static DataSet WW_PPBomBillList(string sWhere) { string sql1 = string.Format(@"select * from h_v_WW_PPBomBillList where 1=1 "); if (sWhere == null || sWhere.Equals("")) { return new SQLHelper.ClsCN().RunProcReturn(sql1 + sWhere + " order by hmainid desc", "h_v_WW_PPBomBillList"); } else { string sql = sql1 + sWhere + " order by hmainid desc"; return new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_WW_PPBomBillList"); } } } #endregion }