using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Pub_Class; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Web.Http; using WebAPI.Models; namespace WebAPI.Controllers { //班组Controller public class Gy_ProcPriceController : ApiController { public DBUtility.ClsPub.Enum_BillStatus BillStatus; private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; #region 返回工序工价列表 [Route("Gy_ProcPrice/list")] [HttpGet] public object list(string sWhere,string user) { try { List columnNameList = new List(); //查看权限 if (!DBUtility.ClsPub.Security_Log("Gy_ProcPriceList", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查看权限!"; objJsonResult.data = null; return objJsonResult; } ds = oCN.RunProcReturn("select * from h_v_Gy_ProcPriceList where 1 = 1 " + sWhere, "h_v_Gy_ProcPriceList"); //添加列名 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列对象的列名 } //if (ds.Tables[0].Rows.Count != 0 || ds != null) //{ objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = columnNameList; return objJsonResult; //} //else //{ //objJsonResult.code = "0"; //objJsonResult.count = 0; //objJsonResult.Message = "无数据"; //objJsonResult.data = null; //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_ProcPrice/set_SaveBill")] [HttpPost] public object set_SaveBill([FromBody] JObject sMainSub) { var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); //保存单据 return objJsonResult = AddBillMain(msg1); } public json AddBillMain(string msg1) { string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); string msg3 = sArray[1].ToString(); string OperationType = sArray[2].ToString().Trim(); string msg4 = sArray[3].ToString(); bool bResult; try { //查看权限 if (!DBUtility.ClsPub.Security_Log("Gy_ProcPriceList_Edit", 1, false, msg4)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无保存权限!"; objJsonResult.data = null; return objJsonResult; } msg2 = "[" + msg2.ToString() + "]"; List mainList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); List subList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg3); DAL.ClsGy_ProcPrice_Ctl BillNew = new DAL.ClsGy_ProcPrice_Ctl(); BillNew.DetailColl = new List(); Model.ClsGy_ProcPrice_Model BillOld = new Model.ClsGy_ProcPrice_Model(); for (int i = 0; i < subList.ToArray().Length; i++) { if (i >= 0)//HQty { Model.ClsGy_ProcPrice_Model oSub = new Model.ClsGy_ProcPrice_Model(); oSub.HMaterID = DBUtility.ClsPub.isLong(subList[i].HMaterIDCol); oSub.HProcID = DBUtility.ClsPub.isLong(subList[i].HProcIDCol); oSub.HSourceID = DBUtility.ClsPub.isLong(subList[i].HSourceIDCol); oSub.HPrice = DBUtility.ClsPub.isLong(subList[i].HPriceCol); oSub.HBeginDate = DBUtility.ClsPub.isDate(subList[i].HBeginDateCol); oSub.HEndDate = DBUtility.ClsPub.isDate(subList[i].HEndDateCol); oSub.HCostFlag = DBUtility.ClsPub.GridToBool(subList[i].HCostFlagCol); oSub.HFlowFlag = DBUtility.ClsPub.GridToBool(subList[i].HFlowFlagCol); oSub.HPayFlag = DBUtility.ClsPub.GridToBool(subList[i].HPayFlagCol); oSub.HDeptID = DBUtility.ClsPub.isLong(mainList[0].HDeptID); oSub.HStopflag = false; oSub.HMaker = DBUtility.ClsPub.isStrNull(mainList[0].HMaker); oSub.HMakeDate = DateTime.Today.ToString(); oSub.HRemark = DBUtility.ClsPub.isStrNull(subList[i].HRemarkCol); BillNew.DetailColl.Add(oSub); } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无明细行信息!"; objJsonResult.data = null; return objJsonResult; } } //保存完毕后处理 if (OperationType.Equals("1.1") || OperationType.Equals("1.2") || OperationType.Equals("2")) { bResult = BillNew.AddNew(); } else { bResult = BillNew.ModifyByID(DBUtility.ClsPub.isLong(mainList[0].HItemID)); } //提示 if (bResult == true) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "保存成功!"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; 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_ProcPrice/GetProcPriceValue")] [HttpGet] public object GetProcPriceValue(int HItemID) { try { List columnNameList = new List(); ds = oCN.RunProcReturn("select * from h_v_Gy_ProcPriceList where HItemID = " + HItemID, "h_v_Gy_ProcPriceList"); //添加列名 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("Gy_ProcPrice/DelProcPrice")] [HttpGet] public object DelProcPrice(int HInterID, string User) { try { //删除权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_ProcPriceList_Delete", 1, false, User)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限删除!"; objJsonResult.data = null; return objJsonResult; } DAL.ClsGy_ProcPrice_Ctl BillNew = new DAL.ClsGy_ProcPrice_Ctl(); var sReturn = ""; if (BillNew.ShowBill(HInterID, ref sReturn)) { foreach (Model.ClsGy_ProcPrice_Model oSub in BillNew.DetailColl) { if (oSub.HChecker.Trim() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "当前单据不能删除!"; objJsonResult.data = null; return objJsonResult; } } bool flag = false; oCN.BeginTran();//开启事务 flag= BillNew.DeleteByID(HInterID); oCN.Commit();//结束事务 if (flag) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "删除成功!"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "删除失败!"; objJsonResult.data = null; return objJsonResult; } } objJsonResult.code = "0"; objJsonResult.count = 0; 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 #region [工序工价审核、反审核] /// /// /// /// 单据ID /// 审核(0),反审核(1) /// 审核人 /// [Route("Gy_ProcPrice/AuditGy_ProcPrice")] [HttpGet] public object AuditGy_ProcPrice(int HInterID, int IsAudit, string CurUserName) { try { //审核权限 if (!DBUtility.ClsPub.Security_Log_second("Gy_ProcPriceList_Check", 1, false, CurUserName)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核失败!无权限!"; objJsonResult.data = null; return objJsonResult; } DBUtility.ClsPub.CurUserName = CurUserName; DAL.ClsGy_ProcPrice_Ctl BillNew = new DAL.ClsGy_ProcPrice_Ctl(); var sReturn = ""; if (BillNew.ShowBill(HInterID, ref sReturn)) { foreach (Model.ClsGy_ProcPrice_Model oSub in BillNew.DetailColl) { if (IsAudit == 0) //审核判断 { if (oSub.HChecker.Trim() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核!不能再次审核!"; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反审核判断 { if (oSub.HChecker.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; } foreach (Model.ClsGy_ProcPrice_Model oSub in BillNew.DetailColl) { if (IsAudit == 0) //审核判断 { //审核提交 if (BillNew.CheckBill(HInterID, ref DBUtility.ClsPub.sExeReturnInfo) == true) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "审核成功"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反审核判断 { //反审核提交AbandonCheck if (BillNew.AbandonCheck(HInterID, ref DBUtility.ClsPub.sExeReturnInfo) == true) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "反审核成功"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "反审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } } return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核失败或者反审核失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion } }