using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using WebAPI.Models; namespace WebAPI.Controllers.基础资料.基础资料 { public class Gy_MatePriceController : ApiController { private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; // GET: Gy_MatePrice #region 样品 列表 [Route("Gy_MatePriceController/MatePriceList")] [HttpGet] public object MatePriceList(string sWhere, string user, string Organization) { try { List columnNameList = new List(); //编辑权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_MatePrice_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_MaterPrice where 1 = 1 "); string sql = sql1 + sWhere+ "order by 创建时间 DESC "; ds = oCN.RunProcReturn(sql, "h_v_Gy_MaterPrice"); //添加列名 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_MatePrice/cx")] [HttpGet] public object cx(string HItemID, string user) { try { List columnNameList = new List(); //编辑权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_MatePrice_Edit", 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_MatePriceEdit where HItemID = " + HItemID); ds = oCN.RunProcReturn(sql1, "h_v_Gy_MatePriceEdit"); 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_MatePriceController/MatePriceEdit")] [HttpPost] public object MatePriceEdit([FromBody] JObject msg) { 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_MatePrice_Edit", 1, false, msg2)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无保存权限!"; objJsonResult.data = null; return objJsonResult; } ListModels oListModels = new ListModels(); try { DAL.ClsGy_MatePrice_Ctl oBill = new DAL.ClsGy_MatePrice_Ctl(); List lsmain = new List(); msg1 = msg1.Replace("\\", ""); msg1 = msg1.Replace("\n", ""); //\n lsmain = oListModels.getObjectByJson_Gy_MatePrice(msg1); foreach (Model.ClsGy_MatePrice_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(); DataSet Maxds = oCN.RunProcReturn("select MAX(HItemID) from Gy_MaterPrice" , "Gy_MaterPrice"); oBill.oModel.HItemID = Convert.ToInt64(Maxds.Tables[0].Rows[0][0]); } else { //是否已经审核判断 DataSet Maxds = oCN.RunProcReturn("select * from h_v_Gy_MatePriceEdit where HItemID = " + oBill.oModel.HItemID, "h_v_Gy_MatePriceEdit"); //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 = "保存成功!"; objJsonResult.data = oBill.oModel.HItemID; 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_MatePriceController/Delete")] [HttpGet] public object Delete(string HItemID, string user) { DataSet ds; try { SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); //删除权限 if (!DBUtility.ClsPub.Security_Log("Gy_MatePrice_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_MaterPrice where HItemID=" + HItemID, "Gy_MaterPrice"); 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]["HCheckEmp"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "数据已审核无法删除!"; objJsonResult.data = null; return objJsonResult; } oCN.RunProc("delete from Gy_MaterPrice 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 审核、反审核 [Route("Gy_MatePriceController/MatePriceCheck")] [HttpGet] public object MatePriceCheck(int HInterID, int IsAudit, string CurUserName) { Int64 lngBillKey = 0; lngBillKey = DBUtility.ClsPub.isLong(HInterID); DAL.ClsGy_MatePrice_Ctl oBill = new DAL.ClsGy_MatePrice_Ctl(); List lsmain = new List(); try { //审核权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_MatePrice_Check", 1, false, CurUserName)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核失败!无权限!"; objJsonResult.data = null; return objJsonResult; } if(lngBillKey==0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } ////针对需要进行的操作,检验当前单据的状态是否支持需要进行的操作 //if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) //根据HInterID获取该单据的数据 //{ // if (oBill.oModel.HCheckEmp.Trim() != "") // { // objJsonResult.code = "0"; // objJsonResult.count = 0; // objJsonResult.Message = "单据已关闭!不能再次审核!"; // objJsonResult.data = null; // return objJsonResult; // } // //if (oBill.omodel.HDeleteMan.Trim() != "") // //{ // // objJsonResult.code = "0"; // // objJsonResult.count = 0; // // objJsonResult.Message = "单据已作废!不能再次审核!"; // // objJsonResult.data = null; // // return objJsonResult; // //} //} //else //{ // objJsonResult.code = "0"; // objJsonResult.count = 0; // objJsonResult.Message = "单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo; // objJsonResult.data = null; // return objJsonResult; //} var ds = oCN.RunProcReturn("select * from Gy_MaterPrice where HItemID=" + HInterID, "Gy_MaterPrice"); if (ds.Tables[0].Rows.Count > 0) { if (IsAudit == 0) //审核判断 { if (ds.Tables[0].Rows[0]["HCheckEmp"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核!不能再次审核!"; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反审核判断 { if (ds.Tables[0].Rows[0]["HCheckEmp"].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) //审核判断 { //审核前控制========================================= string sql1 = "exec h_p_Gy_MaterPrice_BeforeCheckCtrl " + HInterID + ",'" + CurUserName + "'"; ds = oCN.RunProcReturn(sql1, "h_p_Gy_MaterPrice_BeforeCheckCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:审核前判断失败,请与网络管理人员联系"; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } //================================================================================== oCN.RunProc("update Gy_MaterPrice set HCheckEmp='" + CurUserName + "',HCheckTime=getdate() where HItemID=" + HInterID); //审核后控制========================================= string sql2 = "exec h_p_Gy_MaterPrice_AfterCheckCtrl " + HInterID + ",'" + CurUserName + "'"; ds = oCN.RunProcReturn(sql2, "h_p_Gy_MaterPrice_AfterCheckCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:审核后判断失败,请与网络管理人员联系"; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } //================================================================================== objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "审核成功"; objJsonResult.data = null; } if (IsAudit == 1) //反审核判断 { //反审核前控制========================================= string sql1 = "exec h_p_Gy_MaterPrice_BeforeUnCheckCtrl " + HInterID + ",'" + CurUserName + "'"; ds = oCN.RunProcReturn(sql1, "h_p_Gy_MaterPrice_BeforeUnCheckCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反审核失败!原因:反审核前判断失败,请与网络管理人员联系"; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } //================================================================================== oCN.RunProc("update Gy_MaterPrice set HCheckEmp='',HCheckTime=null where HItemID=" + HInterID); //反审核后控制========================================= string sql2 = "exec h_p_Gy_MaterPrice_AfterUnCheckCtrl " + HInterID + ",'" + CurUserName + "'"; ds = oCN.RunProcReturn(sql2, "h_p_Gy_MaterPrice_AfterUnCheckCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反审核失败!原因:反审核后判断失败,请与网络管理人员联系"; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } //================================================================================== 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 禁用、反禁用 [Route("Gy_MatePriceController/StopGy_MaterPrice")] [HttpGet] public object StopGy_MaterPrice(int HInterID, int IsStop, string CurUserName) { try { //禁用权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_MatePrice_Stop", 1, false, CurUserName)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "禁用失败!无权限!"; objJsonResult.data = null; return objJsonResult; } var ds = oCN.RunProcReturn("select * from Gy_MaterPrice where HItemID=" + HInterID, "Gy_MaterPrice"); if (ds.Tables[0].Rows.Count > 0) { if (IsStop == 0) //禁用判断 { if (ds.Tables[0].Rows[0]["HStopEmp"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已禁用!不能再次禁用!"; objJsonResult.data = null; return objJsonResult; } } if (IsStop == 1) //反禁用判断 { if (ds.Tables[0].Rows[0]["HStopEmp"].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 (IsStop == 0) //禁用判断 { //禁用前控制========================================= string sql1 = "exec h_p_Gy_MaterPrice_BeforeStopCtrl " + HInterID + ",'" + CurUserName + "'"; ds = oCN.RunProcReturn(sql1, "h_p_Gy_MaterPrice_BeforeStopCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "禁用失败!原因:禁用前判断失败,请与网络管理人员联系"; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "禁用失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } //================================================================================== oCN.RunProc("update Gy_MaterPrice set HStopEmp='" + CurUserName + "',HStopTime=getdate(),HStopflag=1 where HItemID=" + HInterID); //禁用后控制========================================= string sql2 = "exec h_p_Gy_MaterPrice_AfterStopCtrl " + HInterID + ",'" + CurUserName + "'"; ds = oCN.RunProcReturn(sql2, "h_p_Gy_MaterPrice_AfterStopCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "禁用失败!原因:禁用后判断失败,请与网络管理人员联系"; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "禁用失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } //================================================================================== objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "禁用成功"; objJsonResult.data = null; } if (IsStop == 1) //反禁用判断 { //反禁用前控制========================================= string sql1 = "exec h_p_Gy_Gy_MaterPrice_BeforeUnStopCtrl " + HInterID + ",'" + CurUserName + "'"; ds = oCN.RunProcReturn(sql1, "h_p_Gy_Gy_MaterPrice_BeforeUnStopCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反禁用失败!原因:反禁用前判断失败,请与网络管理人员联系"; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反禁用失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } //================================================================================== oCN.RunProc("update Gy_MaterPrice set HStopEmp='',HStopTime=null,HStopflag=0 where HItemID=" + HInterID); //反禁用后控制========================================= string sql2 = "exec h_p_Gy_MaterPrice_AfterUnStopCtrl " + HInterID + ",'" + CurUserName + "'"; ds = oCN.RunProcReturn(sql2, "h_p_Gy_MaterPrice_AfterUnStopCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反禁用失败!原因:反禁用后判断失败,请与网络管理人员联系"; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反禁用失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; oCN.RollBack(); return objJsonResult; } //================================================================================== 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 } }