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 Xt_CheckItemBillController : ApiController { private json objJsonResult = new json(); public DataSet ds = new DataSet(); public SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); #region 审核项目列表 [Route("Xt_CheckItemBill/Xt_CheckItemList")] [HttpGet] public object Xt_CheckItemList(string sWhere, string user) { try { List columnNameList = new List(); //查询权限 if (!DBUtility.ClsPub.Security_Log_second("Xt_CheckItem_Query", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查看权限!"; objJsonResult.data = null; return objJsonResult; } string sql1 = string.Format(@"select * from h_v_Xt_CheckItemList where 1=1 "); ds = oCN.RunProcReturn(sql1 + sWhere + " order by 审批项目代码 ", "h_v_Xt_CheckItemList"); //添加列名 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; } } #endregion #region 审核项目保存 [Route("Xt_CheckItemBill/Xt_CheckItemEdit")] [HttpPost] public object Xt_CheckItemEdit([FromBody] JObject msg) { DataSet ds; var _value = msg["msg"].ToString(); string msg3 = _value.ToString(); string[] sArray = msg3.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg1 = sArray[0].ToString(); string msg2 = sArray[1].ToString(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); //编辑权限 if (!DBUtility.ClsPub.Security_Log_second("Xt_CheckItem_Edit", 1, false, msg2)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无保存权限!"; objJsonResult.data = null; return objJsonResult; } ListModels oListModels = new ListModels(); try { List lsmain = new List(); msg1 = msg1.Replace("\\", ""); msg1 = msg1.Replace("\n", ""); //\n lsmain = oListModels.getObjectByJson_Xt_CheckItem(msg1); foreach (Xt_CheckItem oItem in lsmain) { if (oItem.HNumber.Trim() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!代码不能为空!"; objJsonResult.data = 1; return objJsonResult; } if (oItem.HName.Trim() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!名称不能为空!"; objJsonResult.data = 1; return objJsonResult; } //查询数据中是否存在重复代码 ds = oCN.RunProcReturn("select * from Xt_CheckItem where HStopflag=0 and HNumber='" + oItem.HNumber.Trim() + "'", "Xt_CheckItem"); //新增时判断 if (oItem.HItemID == 0) { if (ds == null || ds.Tables[0].Rows.Count == 0) { } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!代码重复!"; objJsonResult.data = 1; return objJsonResult; } } } //保存 //保存完毕后处理 oCN.BeginTran(); foreach (Xt_CheckItem oItem in lsmain) { bool bResult = false; if (oItem.HItemID == 0) { oCN.RunProc("Insert into Xt_CheckItem " + " (HNumber,HName" + ",HStopflag,HRemark) " + " Values('" + oItem.HNumber + "','" + oItem.HName + "'," + Convert.ToString(oItem.HStopFlag ? 1 : 0) + ",'" + oItem.HRemark + "')"); bResult = true; } else { oCN.RunProc("Update Xt_CheckItem set " + " HNumber='" + oItem.HNumber + "'" + ",HName='" + oItem.HName + "'" + ",HStopflag=" + Convert.ToString(oItem.HStopFlag ? 1 : 0) + ",HRemark= '" + oItem.HRemark + "' Where HItemID=" + oItem.HItemID); bResult = true; } if (!bResult) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = 1; return objJsonResult; } } oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "保存成功!"; objJsonResult.data = 1; return objJsonResult; } catch (Exception e) { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + e.ToString(); objJsonResult.data = 1; return objJsonResult; } } #endregion #region 审核项目删除 [Route("Xt_CheckItemBill/Xt_CheckItemBillDelete")] [HttpGet] public object Xt_CheckItemBillDelete(string HItemID, string user) { try { //删除权限 if (!DBUtility.ClsPub.Security_Log("Xt_CheckItem_Drop", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无删除权限"; objJsonResult.data = null; return objJsonResult; } SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); if (string.IsNullOrWhiteSpace(HItemID)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HItemID为空!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran();//开始事务 ds = oCN.RunProcReturn("select * from Xt_CheckItem where HItemID=" + HItemID, "Xt_CheckItem"); if (ds == null || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "没有数据,无法删除!"; objJsonResult.data = null; return objJsonResult; ; } var HStopflag = Convert.ToBoolean(ds.Tables[0].Rows[0]["HStopflag"]); if (HStopflag) { oCN.RollBack();//回滚事务 objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "数据已删除无法再次删除!"; objJsonResult.data = null; return objJsonResult; } oCN.RunProc("update Xt_CheckItem set HStopflag=1 where HItemID=" + HItemID); oCN.Commit();//提交事务 objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "* 数据删除成功!"; objJsonResult.data = null; return objJsonResult; ; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "删除失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion } }