| | |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Net.Http; |
| | | using System.Text.RegularExpressions; |
| | | using System.Web; |
| | | using System.Web.Http; |
| | | using WebAPI; |
| | | using WebAPI.Code; |
| | | using WebAPI.Controllers.SCGL.日计划管理; |
| | | using WebAPI.Models; |
| | | using static WebAPI.Controllers.基础资料.基础资料.Gy_DutyBillController; |
| | | |
| | |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region 工厂日历 文件上传 |
| | | [Route("Gy_PlanShifts/Gy_PlanShifts_Excel")] |
| | | [HttpPost] |
| | | public object Gy_PlanShifts_Excel() |
| | | { |
| | | try |
| | | { |
| | | //var WorkBookName = HttpContext.Current.Request["WorkBookName"]; |
| | | //DBUtility.ClsPub.HOrgID = long.Parse(HttpContext.Current.Request["HOrgID"]); |
| | | //获取文件名称 |
| | | 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 tb2 = new DataTable("dt2"); |
| | | |
| | | //添加列名 |
| | | for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++) |
| | | { |
| | | tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString()); |
| | | } |
| | | |
| | | //模板缺少列 但需要从数据库中查询出来显示在页面的字段 |
| | | tb2.Columns.Add("HOrgID", typeof(Int32));//组织ID |
| | | tb2.Columns.Add("HSourceID", typeof(Int32));//生产资源ID |
| | | |
| | | //添加数据 |
| | | for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++) |
| | | { |
| | | DataRow row = tb2.NewRow(); |
| | | for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++) |
| | | { |
| | | row[j] = ExcelDs.Tables[0].Rows[i][j].ToString(); |
| | | } |
| | | //如果表格第i行的第一列为空,则判断为这一行的数据为空,跳出循环并且不把数据写入 tb2 |
| | | if (ExcelDs.Tables[0].Rows[i][0].ToString() == "") |
| | | { |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | tb2.Rows.Add(row); |
| | | } |
| | | } |
| | | |
| | | |
| | | var error = ""; |
| | | |
| | | //查询工艺路线没有的列 |
| | | if (!tb2.Columns.Contains("组织编码")) |
| | | error += "没有找到【组织编码】的标题,"; |
| | | |
| | | if (!tb2.Columns.Contains("组织")) |
| | | error += "没有找到【组织】的标题,"; |
| | | |
| | | if (!tb2.Columns.Contains("生产资源代码")) |
| | | error += "没有找到【生产资源代码】的标题,"; |
| | | |
| | | if (!tb2.Columns.Contains("生产资源")) |
| | | error += "没有找到【生产资源】的标题,"; |
| | | |
| | | if (!tb2.Columns.Contains("日期")) |
| | | error += "没有找到【日期】的标题,"; |
| | | |
| | | if (!tb2.Columns.Contains("工时")) |
| | | error += "没有找到【工时】的标题,"; |
| | | |
| | | |
| | | if (error.Length > 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = $"Excel模板存在错误,{error}\r\n"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | for (int i = 0; i <= tb2.Rows.Count - 1; i++) |
| | | { |
| | | string HORGNumber = ""; |
| | | string HORGName = ""; |
| | | string HSourceNumer = ""; |
| | | string HSourceName = ""; |
| | | string HDate = ""; |
| | | string HOverTimes = ""; |
| | | |
| | | HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织编码"].ToString()); |
| | | HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["组织"].ToString()); |
| | | HSourceNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["生产资源代码"].ToString()); |
| | | HSourceName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["生产资源"].ToString()); |
| | | HDate = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["日期"].ToString()); |
| | | HOverTimes = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工时"].ToString()); |
| | | |
| | | //检查物料 |
| | | int index = i + 1; |
| | | |
| | | if (HORGNumber != "") |
| | | { |
| | | |
| | | |
| | | //查询组织 |
| | | ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS"); |
| | | |
| | | if (ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "第" + index + "行,组织不存在!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | else |
| | | { |
| | | tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); |
| | | } |
| | | string HORGid = ds.Tables[0].Rows[0]["HItemID"].ToString(); |
| | | |
| | | |
| | | //查询生产资源 |
| | | ds = oCN.RunProcReturn("select * from Gy_Source where HNumber='" + HSourceNumer + "' and HUSEORGID=" + HORGid + "", "Gy_Department"); |
| | | |
| | | if (ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "第" + index + "行,该" + HORGName + "组织,生产资源:" + HSourceName + ",不存在!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | else |
| | | { |
| | | tb2.Rows[i]["HSourceID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); |
| | | } |
| | | |
| | | //日期 |
| | | if (HDate == "") |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "第" + index + "行,日期为空!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | }else if(!Regex.IsMatch(HDate, @"^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$")) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "第" + index + "行,日期不为“yyyy-MM-dd”格式!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | //工时 |
| | | if (HOverTimes == "") |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "第" + index + "行,工时为空!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | //else if (!Regex.IsMatch(HWorkTime, @"/^\d+(\.\d+)?$/")) |
| | | //{ |
| | | // objJsonResult.code = "0"; |
| | | // objJsonResult.count = 0; |
| | | // objJsonResult.Message = "第" + index + "行,工时不为非负数格式!"; |
| | | // objJsonResult.data = null; |
| | | // return objJsonResult; |
| | | //} |
| | | } |
| | | else |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "第" + index + "行,组织代码为空"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | |
| | | objJsonResult.code = "1"; |
| | | objJsonResult.count = 1; |
| | | objJsonResult.Message = error; |
| | | objJsonResult.data = tb2; |
| | | 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_PlanShifts/Gy_PlanShifts_btnSave")] |
| | | [HttpPost] |
| | | public object Gy_PlanShifts_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_PlanShifts_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 HSourceID = item["HSourceID"].ToString();//生产资源ID |
| | | string HOrgID = item["HOrgID"].ToString();//组织ID |
| | | string HDate = item["日期"].ToString(); |
| | | string HOverTimes = item["工时"].ToString(); |
| | | |
| | | ds = oCN.RunProcReturn("select * from Gy_PlanShifts where HSourceID=" + HSourceID + " and convert(varchar(100),HDate,23)='" + HDate + "'", "Gy_PlanShifts"); |
| | | |
| | | if (ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | string sql = "insert into Gy_PlanShifts(HDate,HSourceID,HShiftsID,HOverTimes,HClassCount,HRemark,HUseFlag) " + |
| | | "values(" + |
| | | "'" + HDate + "'" + |
| | | "," + HSourceID + "" + |
| | | ",0" + |
| | | "," + HOverTimes + "" + |
| | | ",1" + |
| | | ",''" + |
| | | ",''" + |
| | | ")"; |
| | | |
| | | //主表 |
| | | oCN.RunProc(sql); |
| | | } |
| | | else |
| | | { |
| | | oCN.RunProc("update Gy_PlanShifts set HOverTimes = " + HOverTimes + " where HSourceID=" + HSourceID + " and convert(varchar(100),HDate,23)='" + HDate + "'"); |
| | | } |
| | | |
| | | 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 |
| | | |
| | | #region 制成率明细报表 |