| using DBUtility; | 
| 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; | 
| using System.Web; | 
| using System.IO; | 
| using SyntacticSugar.constant; | 
|   | 
| namespace WebAPI.Controllers.基础资料.基础资料 | 
| { | 
|     public class Gy_BarCodeBill_Set_TempController : ApiController | 
|     { | 
|         public DBUtility.ClsPub.Enum_BillStatus BillStatus; | 
|   | 
|         private json objJsonResult = new json(); | 
|         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
|         DataSet ds; | 
|         DataSet ds_his; | 
|   | 
|         Models.ClsGy_BarCodeBill_Set_Temp OSet = new Models.ClsGy_BarCodeBill_Set_Temp(); | 
|   | 
|   | 
|         #region SET条码列表数据 | 
|         [Route("Gy_BarCodeBill_Set_TempController/GetBarCodeBillSETList")] | 
|         [HttpGet] | 
|         public object GetBarCodeBillSetList(string sWhere, string user) | 
|         { | 
|             try | 
|             { | 
|                 List<object> columnNameList = new List<object>(); | 
|                 if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBill_SET_Temp_Query", 1, false, user)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "没有查看权限"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 ds = oCN.RunProcReturn("select * from h_v_Gy_BarCodeBill_SET_TempList where 1=1 " + sWhere + " order by N'条码编号'", "h_v_Gy_BarCodeBill_SET_TempList"); | 
|   | 
|                 //添加列名 | 
|                 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 SET条码列表数据 分页查询 | 
|         [Route("Gy_BarCodeBill_Set_TempController/GetBarCodeBillSETListPage")] | 
|         [HttpGet] | 
|         public object GetBarCodeBillSETListPage(string sWhere, string user, string page, string size) | 
|         { | 
|             try | 
|             { | 
|                 List<object> columnNameList = new List<object>(); | 
|                 if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBill_SET_Temp_Query", 1, false, user)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "没有查看权限"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 if (string.IsNullOrWhiteSpace(sWhere) == false) | 
|                 { | 
|                     sWhere = sWhere.Replace("'", "''"); | 
|                 } | 
|   | 
|                 ds = oCN.RunProcReturn("exec h_p_Gy_BarCodeBill_Set_TempListPage " + page + "," + size + ",'" + sWhere + "'", "h_p_Gy_BarCodeBill_Set_TempListPage"); | 
|   | 
|                 //添加列名 | 
|                 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 = CodeConstant.SUCCEED; | 
|                 objJsonResult.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString()); | 
|                 objJsonResult.Message = "Sucess!"; | 
|                 objJsonResult.data = ds.Tables[0]; | 
|                 objJsonResult.list = columnNameList; | 
|                 return objJsonResult; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 objJsonResult.code = CodeConstant.FAIL; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "没有返回任何记录!" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|         #region Set条码列表数据删除 | 
|         [Route("Gy_BarCodeBill_Set_TempController/DeleteBarCodeBillSetList")] | 
|         [HttpGet] | 
|         public object DeleteBarCodeBillSetList(string HBarCode, string User) | 
|         { | 
|             try | 
|             { | 
|                 if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBill_Set_Temp_Drop", 1, false, User)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "没有删除权限"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 //ds = oCN.RunProcReturn("Select * from Gy_BarCodeBill_Set_Temp Where HBarCode='" + HBarCode + "'", "Gy_BarCodeBill_Set_Temp", ref DBUtility.ClsPub.sExeReturnInfo); | 
|                 //ds_his = oCN.RunProcReturn("Select * from Gy_BarCodeBill_Set_Temp_His Where HBarCode='" + HBarCode + "'", "Gy_BarCodeBill_Set_Temp_His", ref DBUtility.ClsPub.sExeReturnInfo); | 
|                 //if (ds.Tables[0].Rows.Count != 0 || ds_his.Tables[0].Rows.Count != 0) // Set条码表或者Set条码历史表中需要有对应数据 | 
|                 //{ | 
|                     DataSet ds_delcheck; | 
|                     oCN.BeginTran(); | 
|                     //删除前控制========================================= | 
|                     ds_delcheck = oCN.RunProcReturn("Exec h_p_Gy_BarCodeBill_Set_Temp_BeforeDelCtrl " + HBarCode + ",'" + User + "'", "h_p_Gy_BarCodeBill_Set_Temp_BeforeDelCtrl"); | 
|                     if (ds_delcheck == null) | 
|                     { | 
|                         oCN.RollBack(); | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "删除前判断失败!"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                     if (DBUtility.ClsPub.isStrNull(ds_delcheck.Tables[0].Rows[0]["HBack"]) != "0") | 
|                     { | 
|                         oCN.RollBack(); | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "删除失败!" + DBUtility.ClsPub.isStrNull(ds_delcheck.Tables[0].Rows[0]["HBackRemark"]); | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                     //========================================================= | 
|   | 
|                     // 同时对Set临时表中的数据进行删除 | 
|                     ds = oCN.RunProcReturn("Delete from Gy_BarCodeBill_Set_Temp Where HBarCode='" + HBarCode + "'", "Gy_BarCodeBill_Set_Temp", ref DBUtility.ClsPub.sExeReturnInfo); | 
|                     //ds_his = oCN.RunProcReturn("Delete from Gy_BarCodeBill_Set_Temp_His Where HBarCode='" + HBarCode + "'", "Gy_BarCodeBill_Set_Temp_His", ref DBUtility.ClsPub.sExeReturnInfo); | 
|   | 
|   | 
|                     //删除后控制========================================= | 
|                     ds_delcheck = oCN.RunProcReturn("Exec h_p_Gy_BarCodeBill_Set_Temp_AfterDelCtrl " + HBarCode + ",'" + User + "'", "h_p_Gy_BarCodeBill_Set_Temp_AfterDelCtrl"); | 
|                     if (ds_delcheck == null) | 
|                     { | 
|                         oCN.RollBack(); | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "删除后判断失败!"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                     if (DBUtility.ClsPub.isStrNull(ds_delcheck.Tables[0].Rows[0]["HBack"]) != "0") | 
|                     { | 
|                         oCN.RollBack(); | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "删除失败!" + DBUtility.ClsPub.isStrNull(ds_delcheck.Tables[0].Rows[0]["HBackRemark"]); | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                     //========================================================= | 
|   | 
|                     oCN.Commit(); | 
|   | 
|                     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; | 
|                 //} | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "Exception!" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|   | 
|         } | 
|         #endregion | 
|   | 
|         #region Set条码列表数据编辑 | 
|         [Route("Gy_BarCodeBill_Set_TempController/EditBill")] | 
|         [HttpPost] | 
|         public object EditBill([FromBody] JObject oMain) | 
|         { | 
|             try | 
|             { | 
|                 var _value = oMain["oMain"].ToString(); | 
|                 string msg1 = _value.ToString(); | 
|                 string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | 
|                 string msg2 = sArray[0].ToString(); | 
|                 string msg3 = sArray[1].ToString();//当前人 | 
|                 string msg4 = sArray[2].ToString();//旧条码编号 | 
|   | 
|                 //反序列化 | 
|                 msg2 = "[" + msg2.ToString() + "]"; | 
|                 List<Models.ClsGy_BarCodeBill_Set_Temp> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Models.ClsGy_BarCodeBill_Set_Temp>>(msg2); | 
|   | 
|                 string HBarCode = list[0].HBarCode; | 
|                 string HBarCode_PNL = list[0].HBarCode_PNL; | 
|                 string HMaker = list[0].HMaker; | 
|                 string HMakeDate = list[0].HMakeDate; | 
|   | 
|                 //判断权限 | 
|                 if (!ClsPub.Security_Log("Gy_BarCodeBill_Set_Temp_Edit", 1, false, msg3)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "没有修改权限!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 oCN.BeginTran(); | 
|                 DataSet ds_editCheck; | 
|                 //保存前控制========================================= | 
|                 ds_editCheck = oCN.RunProcReturn("Exec h_p_Gy_BarCodeBill_Set_Temp_BeforeSaveCtrl " + msg3 + ",'2'", "h_p_Gy_BarCodeBill_Set_Temp_BeforeSaveCtrl"); | 
|                 if (ds_editCheck == null) | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "保存前判断失败!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 if (DBUtility.ClsPub.isStrNull(ds_editCheck.Tables[0].Rows[0]["HBack"]) != "0") | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]); | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 //========================================================= | 
|                 if (string.Equals(msg4, HBarCode) == false) | 
|                 { | 
|                     DataSet ds_exits = oCN.RunProcReturn("select HBarCode from Gy_BarCodeBill_Set_Temp where HBarCode = N'" + HBarCode + "'", "Gy_BarCodeBill_PNL_Temp"); | 
|                     if (ds_exits.Tables[0].Rows.Count > 0) | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "条码编号已存在!"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                 } | 
|   | 
|                 // 同时对Set表和Set历史表中的数据进行更新 | 
|                 string sql = "update Gy_BarCodeBill_Set_Temp set " + | 
|                     "HBarCode=N'" + HBarCode + "'," + | 
|                     "HBarCode_PNL=N'" + HBarCode_PNL + "'" + | 
|                     "where HBarCode=N'" + msg4 + "'"; | 
|   | 
|                 oCN.RunProc(sql, ref DBUtility.ClsPub.sExeReturnInfo); | 
|                 string sql1 = "update Gy_BarCodeBill_Set_His set " + | 
|                     "HBarCode=N'" + HBarCode + "'," + | 
|                     "HBarCode_PNL=N'" + HBarCode_PNL + "'" + | 
|                     "where HBarCode=N'" + msg4 + "'"; | 
|                 oCN.RunProc(sql1, ref DBUtility.ClsPub.sExeReturnInfo); | 
|   | 
|                 //保存后控制========================================= | 
|                 ds_editCheck = oCN.RunProcReturn("Exec h_p_Gy_BarCodeBill_Set_Temp_AfterSaveCtrl " + msg3 + ",'2'", "h_p_Gy_BarCodeBill_Set_Temp_AfterSaveCtrl"); | 
|                 if (ds_editCheck == null) | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "保存后判断失败!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|   | 
|                 } | 
|                 if (DBUtility.ClsPub.isStrNull(ds_editCheck.Tables[0].Rows[0]["HBack"]) != "0") | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "" + DBUtility.ClsPub.isStrNull(ds_editCheck.Tables[0].Rows[0]["HBackRemark"]); | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 //========================================================= | 
|   | 
|                 oCN.Commit(); | 
|                 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 = "Exception!" + e.Message; | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|   | 
|         } | 
|         #endregion | 
|   | 
|         #region Set条码列表数据新增 | 
|         [Route("Gy_BarCodeBill_Set_TempController/AddBill")] | 
|         [HttpPost] | 
|         public object AddBill([FromBody] JObject oMain) | 
|         { | 
|             try | 
|             { | 
|                 var _value = oMain["oMain"].ToString(); | 
|                 string msg1 = _value.ToString(); | 
|                 string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | 
|                 string msg2 = sArray[0].ToString(); | 
|                 string msg3 = sArray[1].ToString();//当前人 | 
|                 //string msg4 = sArray[2].ToString();//当前人 | 
|   | 
|                 //反序列化 | 
|                 msg2 = "[" + msg2.ToString() + "]"; | 
|                 List<Models.ClsGy_BarCodeBill_Set_Temp> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Models.ClsGy_BarCodeBill_Set_Temp>>(msg2); | 
|   | 
|                 string HBarCode = list[0].HBarCode; | 
|                 string HBarCode_PNL = list[0].HBarCode_PNL; | 
|   | 
|                 //判断权限 | 
|                 if (!ClsPub.Security_Log("Gy_BarCodeBill_Set_Temp_Edit", 1, false, msg3)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "没有新增权限!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 DataSet ds_exits = oCN.RunProcReturn("select HBarCode from Gy_BarCodeBill_Set_Temp where HBarCode = N'" + HBarCode + "'", "Gy_BarCodeBill_Set_Temp"); | 
|                 if (ds_exits.Tables[0].Rows.Count > 0) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "条码编号已存在!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 oCN.BeginTran(); | 
|                 DataSet ds_editCheck; | 
|                 //保存前控制========================================= | 
|                 ds_editCheck = oCN.RunProcReturn("Exec h_p_Gy_BarCodeBill_Set_Temp_BeforeSaveCtrl " + msg3 + ",'1'", "h_p_Gy_BarCodeBill_Set_Temp_BeforeSaveCtrl"); | 
|                 if (ds_editCheck == null) | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "保存前判断失败!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 if (DBUtility.ClsPub.isStrNull(ds_editCheck.Tables[0].Rows[0]["HBack"]) != "0") | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]); | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 //========================================================= | 
|   | 
|                 oCN.RunProc("insert into Gy_BarCodeBill_Set_Temp(HBarCode, HBarCode_PNL, HMaker, HMakeDate)" + | 
|                     "values(N'" + HBarCode + "', N'" + HBarCode_PNL + "', N'" + msg3 + "' , getdate())"); | 
|   | 
|                 //保存后控制========================================= | 
|                 ds_editCheck = oCN.RunProcReturn("Exec h_p_Gy_BarCodeBill_Set_Temp_AfterSaveCtrl " + msg3 + ",'1'", "h_p_Gy_BarCodeBill_Set_Temp_AfterSaveCtrl"); | 
|                 if (ds_editCheck == null) | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "保存后判断失败!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|   | 
|                 } | 
|                 if (DBUtility.ClsPub.isStrNull(ds_editCheck.Tables[0].Rows[0]["HBack"]) != "0") | 
|                 { | 
|                     oCN.RollBack(); | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "" + DBUtility.ClsPub.isStrNull(ds_editCheck.Tables[0].Rows[0]["HBackRemark"]); | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 //========================================================= | 
|   | 
|                 oCN.Commit(); | 
|                 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 = "Exception!" + e.Message; | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|     } | 
| } |