1
duhe
2024-03-21 c45715fd82b94d7bf90ccbc604dcfdc1a923d465
1
1个文件已修改
414 ■■■■■ 已修改文件
WebAPI/Controllers/基础资料/工资基础资料/Gy_ProcPriceController.cs 414 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebAPI/Controllers/»ù´¡×ÊÁÏ/¹¤×Ê»ù´¡×ÊÁÏ/Gy_ProcPriceController.cs
@@ -6,7 +6,10 @@
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Web.Http;
using WebAPI.Controllers.SCGL.日计划管理;
using WebAPI.Models;
namespace WebAPI.Controllers
{
@@ -463,5 +466,416 @@
            }
        }
        #endregion
        #region å·¥åºå·¥ä»· æ–‡ä»¶ä¸Šä¼ 
        [Route("Gy_ProcPrice/Gy_ProcPrice_Excel")]
        [HttpPost]
        public object Gy_ProcPrice_Excel()
        {
            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 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("HMaterID", typeof(Int32));//物料ID
                tb2.Columns.Add("HProcID", typeof(Int32));//工序ID
                tb2.Columns.Add("HSourceID", typeof(Int32));//生产资源ID
                tb2.Columns.Add("HWorkCenterID", 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 (!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 (!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 (!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 (!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 HMaterNumber = "";
                    string HMaterName = "";
                    string HMaterModel = "";
                    string HProcNumber = "";
                    string HProcName = "";
                    string HSourceNumber = "";
                    string HSourceName = "";
                    decimal HPrice = 0;
                    string HWorkCenterNumber = "";
                    string HWorkCenterName = "";
                    decimal HWorkQty = 0;
                    decimal HStdEmp = 0;
                    decimal HChangeTimes = 0;
                    decimal HChangeMoney = 0;
                    Int64 HProcNo = 0;
                    decimal HPieceTimes = 0;
                    decimal HMouldQty = 0;
                    decimal HChangeMouldMoney = 0;
                    decimal HRushQty = 0;
                    string HBeginDate = System.DateTime.Now.ToString("G");
                    string HEndDate = System.DateTime.Now.ToString("G");
                    Int64 HCostFlag = 0;
                    Int64 HFlowFlag = 0;
                    Int64 HPayFlag = 0;
                    string HRemark = "";
                    HMaterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料代码"].ToString());
                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料名称"].ToString());
                    HMaterModel = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["规格型号"].ToString());
                    HProcNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工序代码"].ToString());
                    HProcName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工序名称"].ToString());
                    HSourceNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["生产资源代码"].ToString());
                    HSourceName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["生产资源名称"].ToString());
                    HPrice = DBUtility.ClsPub.isLong(tb2.Rows[i]["单价"].ToString());
                    HWorkCenterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工作中心代码"].ToString());
                    HWorkCenterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["工作中心名称"].ToString());
                    HWorkQty = DBUtility.ClsPub.isLong(tb2.Rows[i]["小时产能"].ToString());
                    HStdEmp = DBUtility.ClsPub.isLong(tb2.Rows[i]["标准人力"].ToString());
                    HChangeTimes = DBUtility.ClsPub.isLong(tb2.Rows[i]["换线时间"].ToString());
                    HChangeMoney = DBUtility.ClsPub.isLong(tb2.Rows[i]["换线补贴"].ToString());
                    HProcNo = DBUtility.ClsPub.isLong(tb2.Rows[i]["工艺路线流水号"].ToString());
                    HPieceTimes = DBUtility.ClsPub.isLong(tb2.Rows[i]["单件加工时间"].ToString());
                    HMouldQty = DBUtility.ClsPub.isLong(tb2.Rows[i]["模具数量"].ToString());
                    HChangeMouldMoney = DBUtility.ClsPub.isLong(tb2.Rows[i]["换模补贴"].ToString());
                    HRushQty = DBUtility.ClsPub.isLong(tb2.Rows[i]["单件冲次次数"].ToString());
                    HBeginDate = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["开始日期"].ToString());
                    HEndDate = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["结束日期"].ToString());
                    HCostFlag = DBUtility.ClsPub.isLong(tb2.Rows[i]["成本必选"].ToString());
                    HFlowFlag = DBUtility.ClsPub.isLong(tb2.Rows[i]["流转默认"].ToString());
                    HPayFlag = DBUtility.ClsPub.isLong(tb2.Rows[i]["工资默认"].ToString());
                    HRemark = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["备注"].ToString());
                    //检查表格数据
                    int index = i + 1;
                    if (HMaterNumber != "" && HMaterName != "")
                    {
                        //查询物料
                        ds = oCN.RunProcReturn("select * from Gy_Material where  HNumber='" + HMaterNumber + "' and HName='" + HMaterName + "' and HModel ='" + HMaterModel + "'", "Gy_Material");
                        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]["HMaterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //查询工序
                        ds = oCN.RunProcReturn("select * from Gy_Process where  HNumber='" + HProcNumber + "'", "Gy_Process");
                        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]["HProcID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //查询生产资源
                        ds = oCN.RunProcReturn("select * from Gy_Source where  HNumber='" + HSourceNumber + "'" , "Gy_Source");
                        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]["HSourceID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //查询工作中心
                        ds = oCN.RunProcReturn("select * from Gy_WorkCenter where  HNumber='" + HWorkCenterNumber + "'", "Gy_WorkCenter"); //
                        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]["HWorkCenterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                        //工序代码
                        if (HProcNumber == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,工序代码不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //生产资源名称
                        if (HSourceName == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,生产资源名称不能为空!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //工作中心代码
                        if (HWorkCenterNumber == "")
                        {
                            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_ProcPrice/Gy_ProcPrice_btnSave")]
        [HttpPost]
        public object Gy_ProcPrice_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_ProcPriceList_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 HProcID = item["HProcID"].ToString();//工序
                    string HMaterID = item["HMaterID"].ToString();//物料
                    string HSourceID = item["HSourceID"].ToString();//生产资源
                    string HWorkCenterID = item["HWorkCenterID"].ToString();//工作中心
                    string HPrice = item["单价"].ToString();
                    string HWorkQty = item["小时产能"].ToString();
                    string HStdEmp = item["标准人力"].ToString();
                    string HChangeTimes = item["换线时间"].ToString();
                    string HChangeMoney = item["换线补贴"].ToString();
                    string HProcNo = item["工艺路线流水号"].ToString();
                    string HPieceTimes = item["单件加工时间"].ToString();
                    string HMouldQty = item["模具数量"].ToString();
                    string HChangeMouldMoney = item["换模补贴"].ToString();
                    string HRushQty = item["单件冲次次数"].ToString();
                    string HCostFlag = item["成本必选"].ToString();
                    string HFlowFlag = item["流转默认"].ToString();
                    string HPayFlag = item["工资默认"].ToString();
                    string HRemark = item["备注"].ToString();
                    string HBeginDate = item["开始日期"].ToString();
                    string HEndDate = item["结束日期"].ToString();
                    string sql = "insert into Gy_ProcPrice(HMaterID,HProcID,HSourceID,HBeginDate,HEndDate,HCostFlag,HFlowFlag,HPayFlag,HDeptID,HWorkCenterID,HWorkQty,HStdEmp,HChangeTimes,HChangeMoney,HProcNo,HPieceTimes,HMouldQty,HChangeMouldMoney,HRushQty,HPrice,HStopflag,HRemark,HMaker,HMakeDate)" +
                            $"values({HMaterID}, {HProcID},{HSourceID}, '{HBeginDate}', '{HEndDate}', '{(HCostFlag == "是" ? 1 : 0)}', {(HFlowFlag == "是" ? 1 : 0)},'{(HPayFlag == "是" ? 1 : 0)}',{0},{HWorkCenterID},{HWorkQty},{HStdEmp},{HChangeTimes},{HChangeMoney},{HProcNo},{HPieceTimes},{HMouldQty},{HChangeMouldMoney},{HRushQty},{HPrice},{0},'{HRemark}','{user}','{System.DateTime.Now.ToString("G")}')";
                    oCN.RunProc(sql);
                    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
    }
}