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 Gy_MatePriceCusController : ApiController { private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; #region 采购价格 列表 [Route("Gy_MatePriceCus/MatePriceCusList")] [HttpGet] public object MatePriceCusList(string sWhere, string user, string Organization) { try { List columnNameList = new List(); //编辑权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_MatePriceCusList_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_Gy_MatePriceCusList_Sec where 1 = 1 "); string sql = sql1 + sWhere; ds = oCN.RunProcReturn(sql, "h_v_Gy_MatePriceCusList"); //添加列名 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.list = columnNameList; objJsonResult.data = ds.Tables[0]; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 采购价格 编辑查看信息 [Route("Gy_MatePriceCus/cx")] [HttpGet] public object cx(string HItemID, string user) { try { List columnNameList = new List(); //编辑权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_MatePriceCusList_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_Gy_MatePriceCusEdit where HItemID = " + HItemID); ds = oCN.RunProcReturn(sql1, "h_v_Gy_MatePriceCusEdit"); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 采购价格 编辑 [Route("Gy_MatePriceCus/MatePriceCusEdit")] [HttpPost] public object MatePriceCusEdit([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(); //编辑权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_MatePriceCusList_Edit", 1, false, msg2)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无保存权限!"; objJsonResult.data = null; return objJsonResult; } //获取最大ID值赋值 //DataSet Maxds = oCN.RunProcReturn("select MAX(HItemID) HItemID from Gy_TaxRate ", "Gy_TaxRate"); //if (Maxds != null || Maxds.Tables[0].Rows.Count > 0) //{ // //HItemID= Maxds.Tables[0].Rows[0]["HItemID"] // var maxid = Convert.ToInt32((Maxds.Tables[0].Rows[0]["HItemID"].ToString()==""?0: Maxds.Tables[0].Rows[0]["HItemID"])); // maxid += 1; // HItemID = maxid; //} ListModels oListModels = new ListModels(); try { DAL.ClsGy_MatePriceCus_Ctl oBill = new DAL.ClsGy_MatePriceCus_Ctl(); List lsmain = new List(); msg1 = msg1.Replace("\\", ""); msg1 = msg1.Replace("\n", ""); //\n msg1 = "[" + msg1.ToString() + "]"; lsmain = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg1); foreach (Model.ClsGy_MatePriceCus_Model oItem in lsmain) { //新增时判断 #region 父级校验方法(api调用先注释掉,) /* if (oItem.HItemID == 0) { if (ds == null || ds.Tables[0].Rows.Count > 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!代码重复!"; objJsonResult.data = 1; return objJsonResult; } //检查父级是否存在 string sParent; sParent = DBUtility.ClsPub.GetParentCode(oItem.HNumber.Trim()); if (sParent.Trim() == "") { oBill.oModel.HParentID = 0; } else { if (oBill.HavParentCode(sParent.Trim(), HItemID)) { oBill.oModel.HParentID = oBill.oModel.HItemID; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!上级代码不存在或被禁用!"; objJsonResult.data = 1; return objJsonResult; } } } else//编辑时判断 { //检查父级是否存在 string sParent; sParent = DBUtility.ClsPub.GetParentCode(oItem.HNumber.Trim()); if (sParent.Trim() == "") { oBill.oModel.HParentID = 0; } else { if (oBill.HavParentCode(sParent.Trim(), oItem.HItemID)) { oBill.oModel.HParentID = oBill.oModel.HItemID; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!上级代码不存在或被禁用!"; objJsonResult.data = 1; return objJsonResult; } } } */ #endregion //oItem.HUSEORGID = Convert.ToInt32(msg_HUSEORGID); //组织id oBill.oModel = oItem; } //保存 //保存完毕后处理 bool bResult; if (oBill.oModel.HItemID == 0) { bResult = oBill.AddNew(); } else { //是否已经审核判断 DataSet Maxds = oCN.RunProcReturn("select * from h_v_Gy_MatePriceCusEdit where HItemID = " + oBill.oModel.HItemID, "h_v_Gy_MatePriceCusEdit"); if (Maxds != null && Maxds.Tables[0].Rows[0]["审核人"].ToString()!="") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核无法编辑!"; objJsonResult.data = 1; return objJsonResult; } bResult = oBill.ModifyByID(oBill.oModel.HItemID); } if (bResult) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "保存成功!"; //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单"); objJsonResult.data = 1; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = 1; return objJsonResult; } } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + e.ToString(); objJsonResult.data = 1; return objJsonResult; } } #endregion #region 采购价格 删除 [Route("Gy_MatePriceCus/Delete")] [HttpGet] public object Delete(string HItemID, string user) { DataSet ds; try { SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); //删除权限 if (!DBUtility.ClsPub.Security_Log("Gy_MatePriceCusList_Delete", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无删除权限"; objJsonResult.data = null; return objJsonResult; } 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 Gy_MatePriceCus where HItemID=" + HItemID, "Gy_MatePriceCus"); 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 (ds.Tables[0].Rows[0]["HChecker"].ToString()!="") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "数据已审核无法删除!"; objJsonResult.data = null; return objJsonResult; } oCN.RunProc("delete from Gy_MatePriceCus 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 #region 审核、反审核 /// /// /// /// 单据ID /// 审核(0),反审核(1) /// 审核人 /// [Route("Gy_MatePriceCus/CheckGy_MatePriceCus")] [HttpGet] public object CheckGy_MatePriceCus(long HInterID, int IsAudit, string CurUserName) { try { //审核权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_MatePriceCusList_Check", 1, false, CurUserName)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核失败!无权限!"; objJsonResult.data = null; return objJsonResult; } var ds = oCN.RunProcReturn("select * from Gy_MatePriceCus where HItemID=" + HInterID, "Gy_MatePriceCus"); if (ds.Tables[0].Rows.Count > 0) { if (IsAudit == 0) //审核判断 { if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核!不能再次审核!"; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反审核判断 { if (ds.Tables[0].Rows[0]["HChecker"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据未审核!不需要反审核!"; objJsonResult.data = null; return objJsonResult; } } } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据不存在!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran(); if (IsAudit == 0) //审核判断 { oCN.RunProc("update Gy_MatePriceCus set HChecker='" + CurUserName + "',HCheckDate=getdate() where HItemID=" + HInterID); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "审核成功"; objJsonResult.data = null; } if (IsAudit == 1) //反审核判断 { oCN.RunProc("update Gy_MatePriceCus set HChecker='',HCheckDate=null where HItemID=" + HInterID); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "反审核成功"; objJsonResult.data = null; } oCN.Commit(); return objJsonResult; } catch (Exception e) { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核失败或者反审核失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 批量审核 /// /// 批量审核 /// /// 单据ID /// 审核(0),反审核(1) /// 审核人 /// [Route("Gy_MatePriceCus/CheckAll")] [HttpGet] public object CheckAll(string ids, int Type, string HMaker) { try { //处理字符串 if (!string.IsNullOrEmpty(ids)) { long[] idArray = Array.ConvertAll(ids.Split(','), long.Parse); // 处理idArray... for (int i = 0; i < idArray.Length; i++) { objJsonResult = (json)CheckGy_MatePriceCus(idArray[i], Type, HMaker);//审核执行 if (objJsonResult.count == 0) { objJsonResult.Message += "第" + (i + 1) + "行出现问题无法继续完成"; return objJsonResult; } } } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "请选择正确行"; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "执行成功!"; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核或反审核失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion } }