|  |  | 
 |  |  | using System; | 
 |  |  | using Newtonsoft.Json.Linq; | 
 |  |  | using SyntacticSugar.constant; | 
 |  |  | using System; | 
 |  |  | using System.Collections.Generic; | 
 |  |  | using System.Data; | 
 |  |  | using System.IO; | 
 |  |  | using System.Linq; | 
 |  |  | using System.Web; | 
 |  |  | using System.Web.Http; | 
 |  |  | using WebAPI.Controllers.SCGL.日计划管理; | 
 |  |  | using WebAPI.Models; | 
 |  |  |  | 
 |  |  | namespace WebAPI.Controllers.BaseSet | 
 |  |  | 
 |  |  |             { | 
 |  |  |                 if (sWhere == null || sWhere.Equals("")) | 
 |  |  |                 { | 
 |  |  |                     ds = oCN.RunProcReturn("select * from Gy_RoutingGroup where 1=1", "Gy_RoutingGroup"); | 
 |  |  |                     ds = oCN.RunProcReturn("select * from Gy_RoutingGroup where 1=1 order by HItemID ", "Gy_RoutingGroup"); | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     string sql = "select * from Gy_RoutingGroup where 1 = 1 " + sWhere; | 
 |  |  |                     string sql = "select * from Gy_RoutingGroup where 1 = 1 " + sWhere+ " order by HItemID "; | 
 |  |  |                     ds = oCN.RunProcReturn(sql, "Gy_RoutingGroup"); | 
 |  |  |                 } | 
 |  |  |                 if (ds == null || ds.Tables[0].Rows.Count == 0) | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = "没有记录!"; | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "1"; | 
 |  |  |                     objJsonResult.count = 1; | 
 |  |  |                     objJsonResult.Message = "Sucess!"; | 
 |  |  |                     objJsonResult.data = ds.Tables[0]; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //if (ds.Tables[0].Rows.Count != 0 || ds != null) | 
 |  |  |                 //{ | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "Sucess!"; | 
 |  |  |                 objJsonResult.data = ds.Tables[0]; | 
 |  |  |                 return objJsonResult; | 
 |  |  |                 //} | 
 |  |  |                 //else | 
 |  |  |                 //{ | 
 |  |  |                 //objJsonResult.code = "0"; | 
 |  |  |                 //objJsonResult.count = 0; | 
 |  |  |                 //objJsonResult.Message = "无数据"; | 
 |  |  |                 //objJsonResult.data = null; | 
 |  |  |                 //return objJsonResult; | 
 |  |  |                 //} | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         #endregion | 
 |  |  |  | 
 |  |  |         #region 工艺路线大类 文件上传 | 
 |  |  |         [Route("Gy_RoutingGroup/Gy_Process_Excel")] | 
 |  |  |         [HttpPost] | 
 |  |  |         public json Gy_RoutingGroup_Excel() | 
 |  |  |         { | 
 |  |  |             json res = new json(); | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 //获取文件名称 | 
 |  |  |                 var file = HttpContext.Current.Request.Files[0]; | 
 |  |  |                 //获取文件物理路径 | 
 |  |  |                 string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName); | 
 |  |  |                 //保存文件 | 
 |  |  |                 file.SaveAs(ExcelPath); | 
 |  |  |  | 
 |  |  |                 NpoiHelper np = new NpoiHelper(); | 
 |  |  |                 DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0"); | 
 |  |  |  | 
 |  |  |                 //删除文件 | 
 |  |  |                 File.Delete(ExcelPath); | 
 |  |  |  | 
 |  |  |                 //创建临时表 | 
 |  |  |                 DataTable provisional = new DataTable("dt2"); | 
 |  |  |  | 
 |  |  |                 //添加列名 | 
 |  |  |                 for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++) | 
 |  |  |                 { | 
 |  |  |                     provisional.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString()); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //模板缺少列 但需要从数据库中查询出来显示在页面的字段 | 
 |  |  |                 provisional.Columns.Add("HOrgID", typeof(Int32));//组织ID | 
 |  |  |                 provisional.Columns.Add("HDeptID", typeof(Int32));//部门ID | 
 |  |  |  | 
 |  |  |                 //添加数据 | 
 |  |  |                 for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++) | 
 |  |  |                 { | 
 |  |  |                     DataRow row = provisional.NewRow(); | 
 |  |  |                     for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++) | 
 |  |  |                     { | 
 |  |  |                         row[j] = ExcelDs.Tables[0].Rows[i][j].ToString(); | 
 |  |  |                     } | 
 |  |  |                     provisional.Rows.Add(row); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 for (int i = 0; i <= provisional.Rows.Count - 1; i++) | 
 |  |  |                 { | 
 |  |  |                     string HNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["代码"].ToString()); | 
 |  |  |                     string HName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["名称"].ToString()); | 
 |  |  |                     string HHelpCode = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["助记码"]); | 
 |  |  |                     string HRemark = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["备注"].ToString()); | 
 |  |  |  | 
 |  |  |                     //获取真实行数 | 
 |  |  |                     int line = i + 1; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 res.code = "1"; | 
 |  |  |                 res.count = 1; | 
 |  |  |                 res.data = provisional; | 
 |  |  |                 return res; | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 res.code = "0"; | 
 |  |  |                 res.count = 0; | 
 |  |  |                 res.Message = "Exception!" + e.ToString(); | 
 |  |  |                 res.data = null; | 
 |  |  |                 return res; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         #endregion | 
 |  |  |  | 
 |  |  |         #region | 
 |  |  |         #region 工艺路线 导入(保存) | 
 |  |  |         [Route("Gy_RoutingGroup/Gy_Process_btnSave")] | 
 |  |  |         [HttpPost] | 
 |  |  |         public object Gy_Group_btnSave([FromBody] JObject sMainSub) | 
 |  |  |         { | 
 |  |  |             var _value = sMainSub["sMainSub"].ToString(); | 
 |  |  |             string msg1 = _value.ToString(); | 
 |  |  |             string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries); | 
 |  |  |             string msg2 = sArray[0].ToString(); | 
 |  |  |             string user = sArray[1].ToString(); | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 if (!DBUtility.ClsPub.Security_Log("Gy_Group_Edit", 1, false, user)) | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = "无保存权限!"; | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2); | 
 |  |  |                 List<Dictionary<string, string>> list = new List<Dictionary<string, string>>(); | 
 |  |  |  | 
 |  |  |                 foreach (JObject item in Excel) | 
 |  |  |                 { | 
 |  |  |                     Dictionary<string, string> dic = new Dictionary<string, string>(); | 
 |  |  |                     foreach (var itm in item.Properties()) | 
 |  |  |                     { | 
 |  |  |                         dic.Add(itm.Name, itm.Value.ToString()); | 
 |  |  |                     } | 
 |  |  |                     list.Add(dic); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 oCN.BeginTran(); | 
 |  |  |                 int i = 1; | 
 |  |  |                 foreach (Dictionary<string, string> item in list) | 
 |  |  |                 { | 
 |  |  |                     string HNumber = item["代码"].ToString(); | 
 |  |  |                     string HName = item["名称"].ToString(); | 
 |  |  |                     string HHelpCode = item["助记码"]; | 
 |  |  |                     string HRemark = item["备注"].ToString(); | 
 |  |  |  | 
 |  |  |                     string sShortNumber; | 
 |  |  |                     sShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//短代码 | 
 |  |  |                     if (sShortNumber.Trim() == "") | 
 |  |  |                     { | 
 |  |  |                         objJsonResult.code = "0"; | 
 |  |  |                         objJsonResult.count = 0; | 
 |  |  |                         objJsonResult.Message = "保存失败!短代码为空!"; | 
 |  |  |                         objJsonResult.data = 1; | 
 |  |  |                         return objJsonResult; | 
 |  |  |                     } | 
 |  |  |                     int HEndFlag = 1;//末级标志 | 
 |  |  |                     int HLevel = DBUtility.ClsPub.GetLevel(HNumber); //等级 | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                     if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim())) | 
 |  |  |                     { | 
 |  |  |                         objJsonResult.code = "0"; | 
 |  |  |                         objJsonResult.count = 0; | 
 |  |  |                         objJsonResult.Message = "保存失败!代码中不能出现连续‘.’并且首位末位不能为‘.’!"; | 
 |  |  |                         objJsonResult.data = 1; | 
 |  |  |                         return objJsonResult; | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     ds = oCN.RunProcReturn("select * from  Gy_RoutingGroup where HNumber='" + HNumber + "'", " Gy_RoutingGroup"); | 
 |  |  |  | 
 |  |  |                     if (ds.Tables[0].Rows.Count == 0) | 
 |  |  |                     { | 
 |  |  |  | 
 |  |  |                         string sql = "insert into Gy_RoutingGroup(HName,HNumber,HShortNumber,HLevel,HHelpCode,HParentID,HStopflag,HEndFlag,HRemark)" + | 
 |  |  |                             $"values('{HName}', '{HNumber}', '{sShortNumber}',0,'',0,0,0,'{HRemark}')"; | 
 |  |  |                         oCN.RunProc(sql); | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         oCN.RunProc("update Gy_RoutingGroup set  HName='" + HName + "', HHelpCode='" + HHelpCode + "'  where HNumber='" + HNumber + "'"); | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     i++; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 oCN.Commit(); | 
 |  |  |  | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "导入成功!"; | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 LogService.Write(e); | 
 |  |  |                 objJsonResult.code = "0"; | 
 |  |  |                 objJsonResult.count = 0; | 
 |  |  |                 objJsonResult.Message = "Exception!" + e.ToString(); | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         #endregion | 
 |  |  |         #endregion | 
 |  |  |     } | 
 |  |  | } |