1
wtt
2026-04-10 fae58e2951ccf415ad8e8098ca49f5611e410dd3
WebAPI/Controllers/ÏîÄ¿¹ÜÀí/¹¤×÷ÈÎÎñ/PM_WorkTaskBillController.cs
@@ -12,6 +12,8 @@
using WebAPI.Models;
using System.Threading.Tasks;
using DLL;
using SyntacticSugar.constant;
using System.IO;
namespace WebAPI.Controllers.项目管理.工作任务
{
@@ -64,6 +66,7 @@
            public string HDeleteManDate;
            public string HBackerDate;
            public string HBackRemark;
            public string HTaskType;
            public int HMainSourceInterID;
            public int HMainSourceEntryID;
@@ -184,6 +187,7 @@
                string HDeleteManDate = mainList[0].HDeleteManDate;
                string HBackerDate = mainList[0].HBackerDate;
                string HBackRemark = mainList[0].HBackRemark;
                string HTaskType = mainList[0].HTaskType;
                int HMainSourceInterID = mainList[0].HMainSourceInterID;
                int HMainSourceEntryID = mainList[0].HMainSourceEntryID;
                string HMainSourceBillNo = mainList[0].HMainSourceBillNo;
@@ -211,7 +215,7 @@
                {
                    string sql = "insert into PM_WorkTaskBillMain" +
                        "(HYear,HPeriod,HBillType,HBillSubType,HInterID,HBillNo,HProjectID,HProNumber,HProjectStageID,HName,HDate,HTaskNote,HPlanTimes" +
                        ",HSelfTimes,HLastDate,HSendEmp,HReceiveEmp,HType,HCopyEmp,HRemark,HOrgID,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HOrderLevID,HTaskClassID)" +
                        ",HSelfTimes,HLastDate,HSendEmp,HReceiveEmp,HType,HCopyEmp,HRemark,HOrgID,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HOrderLevID,HTaskClassID,HTaskType)" +
                        "values(" +
                        "" + HYear +
                        "," + HPeriod +
@@ -242,6 +246,7 @@
                        "','" + HMainSourceBillType +
                        "','" + HOrderLevID  +
                        "','"+ HTaskClassID+
                        "','"+ HTaskType +
                        "')";
                    //主表
@@ -280,6 +285,7 @@
                        "',HMainSourceBillType = '" + HMainSourceBillType +
                        "',HOrderLevID  = '" + HOrderLevID  +
                        "',HTaskClassID  = '" + HTaskClassID +
                        "',HTaskType  = '" + HTaskType +
                        "' where HInterID = " + HInterID;
                    oCN.RunProc(sql);
@@ -294,7 +300,7 @@
                {
                    string sql = "insert into PM_WorkTaskBillMain" +
                        "(HYear,HPeriod,HBillType,HBillSubType,HInterID,HBillNo,HProjectID,HProNumber,HProjectStageID,HName,HDate,HTaskNote,HPlanTimes" +
                        ",HSelfTimes,HLastDate,HSendEmp,HReceiveEmp,HType,HCopyEmp,HRemark,HOrgID,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HOrderLevID )" +
                        ",HSelfTimes,HLastDate,HSendEmp,HReceiveEmp,HType,HCopyEmp,HRemark,HOrgID,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HOrderLevID,HTaskType )" +
                        "values(" +
                        "" + HYear +
                        "," + HPeriod +
@@ -324,6 +330,7 @@
                        ",'" + HMainSourceBillNo +
                        "','" + HMainSourceBillType +
                        "','" + HOrderLevID +
                        "','" + HTaskType +
                        "')";
                    //主表
                    oCN.RunProc(sql);
@@ -442,6 +449,62 @@
            }
        }
        #endregion
        #region å·¥ä½œä»»åŠ¡åˆ—è¡¨åˆ†é¡µåˆ—è¡¨
        [Route("PM_WorkTaskBill/page")]
        [HttpGet]
        public object PM_WorkTaskBillPage(string sWhere, string user, int page, int size)
        {
            DataSet ds;
            try
            {
                List<object> columnNameList = new List<object>();
                //判断权限
                //if (!DBUtility.ClsPub.Security_Log("Cg_POInStockBillQuery", 1, false, user))
                //{
                //    objJsonResult.code = CodeConstant.FAIL;
                //    objJsonResult.count = CountConstant.FAIL;
                //    objJsonResult.Message = "您没有该模块权限,请与管理员联系!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("exec h_p_PM_WorkTaskBillList " + page + "," + size + ",''", "h_p_PM_WorkTaskBillList");
                }
                else
                {
                    sWhere = sWhere.Replace("'", "''");
                    ds = oCN.RunProcReturn("exec h_p_PM_WorkTaskBillList " + page + "," + size + ",'" + sWhere + "'", "h_p_PM_WorkTaskBillList");
                }
                //添加列名
                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.list = columnNameList;
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region å·¥ä½œä»»åŠ¡åˆ—è¡¨  ä¸‹æŽ¨æ•°æ®æŸ¥è¯¢
        /// <summary>
@@ -1257,6 +1320,8 @@
            public string HBackRemark;
            public int HReportEmpID;
            public string HReportEmpName;
            public string HReceiveEmp;
            public string HCopyEmp;
        }
        #endregion
        #region ä»»åŠ¡æ±‡æŠ¥ å­è¡¨æ•°æ®
@@ -1278,7 +1343,10 @@
            public int HSourceEntryID;
            public string HSourceBillNo;
            public string HSourceBillType;
            public bool HFinishFlag;
            public bool HFinishFlag;
            public string HWeekProDays; // æœ¬å‘¨æ¶ˆè€—实施人天(类里面使用string存,后面转化为decimal)
            public string HWeekReportFileName; // äººå¤©å•文件名称
            public string HWeekReportFileAddr; // äººå¤©å•文件路径
        }
        #endregion
        #region ä»»åŠ¡æ±‡æŠ¥ æ–°å¢ž/编辑-保存
@@ -1376,6 +1444,8 @@
                string HReportEmpName = mainList[0].HReportEmpName;
                string HUpdater = mainList[0].HUpdater;
                string HUpdaterDate = mainList[0].HUpdaterDate;
                string HReceiveEmp = mainList[0].HReceiveEmp;
                string HCopyEmp = mainList[0].HCopyEmp;
                reportMan = HReportEmpName;//获取汇报人名称
                //保存前控制
                DataSet BeforeDs = oCN.RunProcReturn("Exec h_p_PM_WorkTaskReportBill_BeforeSaveCtrl " + HInterID.ToString() + ",'" + HBillNo + "'," + OperationType.ToString(), "h_p_PM_WorkTaskReportBill_BeforeSaveCtrl");
@@ -1404,7 +1474,7 @@
                if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//新增
                {
                    string sql = "insert into PM_WorkTaskReportBillMain" +
                        "(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate,HBillNo,HBillStatus,HRemark,HMaker,HMakeDate,HOrgID,HReportEmpID) " +
                        "(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate,HBillNo,HBillStatus,HRemark,HMaker,HMakeDate,HOrgID,HReportEmpID,HReceiveEmp, HCopyEmp) " +
                        "values(" +
                        "" + HYear +
                        "," + HPeriod +
@@ -1419,8 +1489,10 @@
                        "','" + HMakerDate +
                        "'," + HOrgID +
                        "," + HReportEmpID +
                        ")";
                        ",N'" + HReceiveEmp +
                        "',N'" + HCopyEmp +
                        "')";
                    LogService.Write(sql);
                    //主表
                    oCN.RunProc(sql);
                    LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",新增任务汇报:" + HBillNo);
@@ -1441,8 +1513,9 @@
                        "',HUpdateDate = '" + HUpdaterDate +
                        "',HOrgID = " + HOrgID +
                        ",HReportEmpID = " + HReportEmpID +
                        ",HReceiveEmp = N'" + HReceiveEmp + "'" +
                        ",HCopyEmp = N'" + HCopyEmp + "'" +
                        " where HInterID = " + HInterID;
                    oCN.RunProc(sql);
                    //删除子表时  å›žå¡«å·¥ä½œä»»åŠ¡å•å…³è”æ•°é‡ã€å•æ®çŠ¶æ€
@@ -1535,7 +1608,9 @@
                string HSourceBillNo = oSub.HSourceBillNo;
                string HSourceBillType = oSub.HSourceBillType;
                bool HFinishFlag = oSub.HFinishFlag;
                string HWeekProDays = oSub.HWeekProDays;
                string HWeekReportFileAddr = oSub.HWeekReportFileAddr;
                string HWeekReportFileName = oSub.HWeekReportFileName;
                if (HFinishFlag==true)
                {
                    //判断单据是否存在
@@ -1572,12 +1647,14 @@
                }
                string HSendEmp = ds.Tables[0].Rows[0]["派单人"].ToString();//派单人
                string HCopyEmp = ds.Tables[0].Rows[0]["抄送人"].ToString();//抄送人
                string HPlanTimes = ds.Tables[0].Rows[0]["评估工时"].ToString();//评估工时
                string HWorkTaskDate = DateTime.Parse(ds.Tables[0].Rows[0]["日期"].ToString()).ToString("yyyy-MM-dd");//工作任务单据时间
                string HSelfTimes = ds.Tables[0].Rows[0]["自评工时"].ToString();//自评工时
                string HProjectName = ds.Tables[0].Rows[0]["项目名称"].ToString();//项目名称
                string HTaskDescription = ds.Tables[0].Rows[0]["任务描述"].ToString();
                //插入子表sql
                string sql = "insert into PM_WorkTaskReportBillSub" +
                    "(HInterID,HBillNo_bak,HEntryID,HRemark,HProjectID,HProNumber,HProjectStageID,HName,HTaskNote,HType,HRelTimes,HReportNote,HAdv,HSourceInterID,HSourceEntryID,HSourceBillType,HSourceBillNo,HFinishFlag) " +
                    "(HInterID,HBillNo_bak,HEntryID,HRemark,HProjectID,HProNumber,HProjectStageID,HName,HTaskNote,HType,HRelTimes,HReportNote,HAdv,HSourceInterID,HSourceEntryID,HSourceBillType,HSourceBillNo,HFinishFlag " +
                    ", HWeekProDays,HWeekReportFileName,HWeekReportFileAddr) " +
                    "values(" +
                    "" + HInterID +
                    ",'" + HBillNo +
@@ -1597,9 +1674,10 @@
                    ",'" + HSourceBillType +
                    "','" + HSourceBillNo +
                    "'," + DBUtility.ClsPub.BoolToString(HFinishFlag) +
                    $",CONVERT(MONEY, '{HWeekProDays}'), '{HWeekReportFileName}', '{HWeekReportFileAddr}'" +
                    ")";
                oCN.RunProc(sql);
                string messageContext = "日期= " + DateTime.Now + ",汇报人=" + reportMan + ",汇报内容=" + HReportNote + ",评估工时=" + HPlanTimes + "小时,自评工时=" + HSelfTimes + "小时,耗用工时=" + HRelTimes + "小时,任务名称=" + HName + ",项目名称=" + HProjectName; ;
                string messageContext = "单据日期= " + HWorkTaskDate + ",汇报人=" + reportMan + ",汇报内容=" + HReportNote +",任务描述 ="+ HTaskDescription +",完成标记="+ (HFinishFlag?"是":"否") + ",自评工时=" + HSelfTimes + "小时,耗用工时=" + HRelTimes + "小时,任务名称=" + HName + ",项目名称=" + HProjectName; ;
                _ = SendDingDingAsync(HSendEmp, messageContext, HCopyEmp);
            }
@@ -1698,6 +1776,62 @@
            }
        }
        #endregion
        #region ä»»åŠ¡æ±‡æŠ¥åˆ†é¡µåˆ—è¡¨
        [Route("PM_WorkTaskReportBill/page")]
        [HttpGet]
        public object PM_WorkTaskReportBillPage(string sWhere, string user, int page, int size)
        {
            DataSet ds;
            try
            {
                List<object> columnNameList = new List<object>();
                //判断权限
                //if (!DBUtility.ClsPub.Security_Log("Cg_POInStockBillQuery", 1, false, user))
                //{
                //    objJsonResult.code = CodeConstant.FAIL;
                //    objJsonResult.count = CountConstant.FAIL;
                //    objJsonResult.Message = "您没有该模块权限,请与管理员联系!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("exec h_p_PM_WorkTaskReportBillList " + page + "," + size + ",''", "h_p_PM_WorkTaskReportBillList");
                }
                else
                {
                    sWhere = sWhere.Replace("'", "''");
                    ds = oCN.RunProcReturn("exec h_p_PM_WorkTaskReportBillList " + page + "," + size + ",'" + sWhere + "'", "h_p_PM_WorkTaskReportBillList");
                }
                //添加列名
                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.list = columnNameList;
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region ä»»åŠ¡æ±‡æŠ¥ ç¼–辑-页面赋值
        /// <summary>
@@ -4093,5 +4227,163 @@
            return response;
        }
        #endregion
        //#region è‡ªåŠ¨åŠ è½½é¡µé¢è¡¨å¤´
        ///// <summary>
        ///// è¿”回项目阶段列表
        /////参数:string sql。
        /////返回值:object。
        ///// </summary>
        //[Route("Xt_DefineBillMainSet/getDefineBillMainSet")]
        //[HttpGet]
        //public object getDefineBillMainSet(string HModName, string user)
        //{
        //    try
        //    {
        //        string sql = "select * from h_v_Xt_DefineBillMainSet_AutoLoadList where HModName ='" + HModName + "' and HUser ='" + user + "' order by HArrangeOrder,HArrangeOrderSub";
        //        ds = oCN.RunProcReturn(sql, "Xt_DefineBillMainSet");
        //        if(ds!=null && ds.Tables[0].Rows.Count == 0)
        //        {
        //            sql = "select * from h_v_Xt_DefineBillMainSet_AutoLoadList where HModName ='" + HModName + "' and HUser ='admin' order by HArrangeOrder,HArrangeOrderSub";
        //            ds = oCN.RunProcReturn(sql, "h_v_Xt_DefineBillMainSet_AutoLoadList");
        //        }
        //        objJsonResult.code = "1";
        //        objJsonResult.count = 1;
        //        objJsonResult.Message = "Sucess!";
        //        objJsonResult.data = ds.Tables[0];
        //        return objJsonResult;
        //    }
        //    catch (Exception e)
        //    {
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 0;
        //        objJsonResult.Message = "Exception!" + e.ToString();
        //        objJsonResult.data = null;
        //        return objJsonResult;
        //    }
        //}
        //#endregion
        #region ä»»åŠ¡æ±‡æŠ¥ ä¸Šä¼ äººå¤©å•
        [Route("PM_WorkTaskReportBill/UploadFile")]
        [HttpPost]
        public object UploadFile()
        {
            string HNumber = HttpContext.Current.Request.Params["HNumber"];  //人天单文件名
            string HRemark = HttpContext.Current.Request.Params["HRemark"];  //备注
            string HUserName = HttpContext.Current.Request.Params["HUserName"];  //创建人
            HttpPostedFile files = HttpContext.Current.Request.Files["file"];
            string path = HttpContext.Current.Server.MapPath("~/../Files/WorkTaskReportBill/" + HNumber);
            dynamic dyResult = UpLoadFile(files, path, HNumber, HRemark, HUserName);
            if (dyResult != null && dyResult.result == 1)
            {
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "上传成功!";
                objJsonResult.data = "Files/WorkTaskReportBill/" + HNumber + "/";
                return objJsonResult;
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = dyResult.returnval;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        public dynamic UpLoadFile(HttpPostedFile files, string path, string HNumber, string HRemark, string HUserName)
        {
            dynamic Result_Ob = new { result = 1, returnval = "上传成功!" };
            string filePath = Path.GetFullPath(files.FileName);//文件上传路径
            string fileExtension = Path.GetExtension(files.FileName);// æ–‡ä»¶æ‰©å±•名
            string filename = files.FileName;//文件名
            string fileSavePath = path;// ä¸Šä¼ ä¿å­˜è·¯å¾„
            int filesize = files.ContentLength;//获取上传文件的大小单位为字节byte
            int Maxsize = 40000 * 1024;//定义上传文件的最大空间大小为40M
            try
            {
                if (files == null || files.ContentLength <= 0)
                {
                    Result_Ob = new { result = 0, returnval = "文件不能为空!" };
                    return Result_Ob;
                }
                if (filesize >= Maxsize)
                {
                    Result_Ob = new { result = 0, returnval = "上传文件超过40M,不能上传!" };
                    return Result_Ob;
                }
                string fileurl = Path.Combine(fileSavePath, filename);
                if (Directory.Exists(fileurl) == true)  //如果存在重名文件就提示
                {
                    Result_Ob = new { result = 0, returnval = "存在同名文件!" };
                    return Result_Ob;
                }
                //删除数据表数据
                ds = oCN.RunProcReturn("delete from MES_AccessoriesList where HSourceBillNo ='" + HNumber + "' and HFileName='" + filename + "'", "MES_AccessoriesList");
                if (Directory.Exists(path))
                {
                    File.Delete(fileurl);      //删除指定文件
                    files.SaveAs(fileurl);
                    string StrPath = "/files/WorkTaskReportBill/" + HNumber + "/" + filename;
                    if (File.Exists(fileurl))
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
                        //写入数据表
                        oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" +
                                    ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" +
                                    ",HFileClsID,HSourceBillNo" +
                                   ") values('"
                                    + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" +
                                    ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize +
                                    "','" + 0 + "','" + HNumber +
                                   "') ");
                    }
                    else
                    {
                        Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" };
                    }
                }
                else
                {
                    Directory.CreateDirectory(fileSavePath); //添加文件夹
                    files.SaveAs(fileurl);
                    string StrPath = "/files/WorkTaskReportBill/" + HNumber + "/" + filename;
                    if (File.Exists(fileurl))
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
                        //写入数据表
                        oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" +
                                    ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" +
                                    ",HFileClsID,HSourceBillNo" +
                                   ") values('"
                                    + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" +
                                    ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize +
                                    "','" + 0 + "','" + HNumber +
                                   "') ");
                    }
                    else
                    {
                        Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" };
                    }
                }
            }
            catch (Exception e)
            {
                Result_Ob = new { result = 0, returnval = e.Message };
            }
            return Result_Ob;
        }
        #endregion
    }
}