VueWebCoreApi/DLL/DAL/ReportManagerDAL.cs
@@ -19,6 +19,7 @@
        public static string strProcName = ""; //定义全局sql变量
        public static List<SqlParameter> listStr = new List<SqlParameter>(); //定义全局参数集合
        public static SqlParameter[] parameters; //定义全局SqlParameter参数数组
        public static string ErpPath = AppSetting.GetAppSetting("ErpPath"); //获取ERP配置
        #region[生产进度报表]
@@ -1629,8 +1630,8 @@
        #endregion
        #region[入库记录]
        public static ToMessage StorageRecordSearch(string hbillno, string sono, string mono, string wocode, string partcode, string partname, string stockcode, string respondopendate, string respondclosedate, int startNum, int endNum, string prop, string order)
        #region[T8入库记录表头]
        public static ToMessage StorageRecordMainSearch(string hbillno, string username, string hbdateopendate, string hbdateclosedate, string userdateopendate, string userdateclosedate, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
@@ -1638,76 +1639,130 @@
            {
                if (hbillno != "" && hbillno != null)
                {
                    search += "and AA.hbillno like '%'+@hbillno+'%' ";
                    search += "and hbillno like '%'+@hbillno+'%' ";
                    dynamicParams.Add("@hbillno", hbillno);
                }
                if (sono != "" && sono != null)
                if (username != "" && username != null)
                {
                    search += "and AA.salecode like '%'+@sono+'%' ";
                    dynamicParams.Add("@sono", sono);
                    search += "and create_user like '%'+@username+'%' ";
                    dynamicParams.Add("@username", username);
                }
                if (mono != "" && mono != null)
                if (hbdateopendate != "" && hbdateopendate != null)
                {
                    search += "and AA.mo_no like '%'+@mono+'%' ";
                    dynamicParams.Add("@mono", mono);
                    search += "and hbdate between @hbdateopendate and @hbdateclosedate ";
                    dynamicParams.Add("@hbdateopendate", hbdateopendate + " 00:00:00");
                    dynamicParams.Add("@hbdateclosedate", hbdateclosedate + " 23:59:59");
                }
                if (wocode != "" && wocode != null)
                if (userdateopendate != "" && userdateopendate != null)
                {
                    search += "and AA.wocode like '%'+@wocode+'%' ";
                    dynamicParams.Add("@wocode", wocode);
                }
                if (partcode != "" && partcode != null)
                {
                    search += "and AA.partcode  like '%'+@partcode+'%' ";
                    dynamicParams.Add("@partcode", partcode);
                }
                if (partname != "" && partname != null)
                {
                    search += "and AA.partname  like '%'+@partname+'%' ";
                    dynamicParams.Add("@partname", partname);
                }
                if (stockcode != "" && stockcode != null)
                {
                    search += "and AA.stockcode=@stockcode ";
                    dynamicParams.Add("@stockcode", stockcode);
                }
                if (respondopendate != "" && respondopendate != null)
                {
                    search += "and AA.hbdate between @respondopendate and @respondclosedate ";
                    dynamicParams.Add("@respondopendate", respondopendate + " 00:00:00");
                    dynamicParams.Add("@respondclosedate", respondclosedate + " 23:59:59");
                    search += "and create_date between @userdateopendate and @userdateclosedate ";
                    dynamicParams.Add("@userdateopendate", userdateopendate + " 00:00:00");
                    dynamicParams.Add("@userdateclosedate", userdateclosedate + " 23:59:59");
                }
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select *  from(
                           select A.hbillno,A.hbdate,B.salecode,B.mo_no,B.wocode,B.partcode,P.partname,P.partspec,M.wkshp_code,T.torg_name as wkshp_name,B.stockcode,S.name as stockname,
                           B.qty,B.inbarcode,R.step_code,E.stepname,R.style,A.create_user,A.create_date
                           from TK_WMS_Inwh_Main A
                           inner join TK_WMS_Inwh_Sub B on A.hbillno=B.hbillno
                           inner join TK_Wrk_Record R on B.inbarcode=R.inbarcode
                           left join  TK_Wrk_Man M on B.wocode=M.wo_code
                           left join  TMateriel_Info P on B.partcode=P.partcode
                           left join  TSecStck S on B.stockcode=S.code
                           left join  TStep E on R.step_code=E.stepcode
                           left join  TOrganization T on M.wkshp_code=T.torg_code
                           union all
                           select A.hbillno,A.hbdate,B.salecode,B.mo_no,B.wocode,B.partcode,P.partname,P.partspec,M.wkshp_code,T.torg_name as wkshp_name,B.stockcode,S.name as stockname,
                           B.qty,B.inbarcode,O.step_code,E.stepname,O.style,A.create_user,A.create_date
                           from TK_WMS_Inwh_Main A
                           inner join TK_WMS_Inwh_Sub B on A.hbillno=B.hbillno
                           inner join TK_Wrk_OutRecord O on B.inbarcode=O.inbarcode
                           left join  TK_Wrk_Man M on B.wocode=M.wo_code
                           left join  TMateriel_Info P on B.partcode=P.partcode
                           left join  TSecStck S on B.stockcode=S.code
                           left join  TStep E on O.step_code=E.stepcode
                           left join  TOrganization T on M.wkshp_code=T.torg_code
                           ) as AA where 1=1 " + search;
                var sql = @"select (case when docu_typecode='WI' then '产成品入库' end) as hbilltype,hbillno,hbdate,create_user,create_date
                            from TK_WMS_Inwh_Main where 1=1 " + search;
                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.count = total;
                mes.data = data.ToList();
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[T8入库记录表体]
        public static ToMessage StorageRecordSubSearch(string hbillno)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                dynamicParams.Add("@hbillno", hbillno);
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select *  from(
                            select S.hbillno,S.rownumber,S.inbarcode,S.mo_id,S.mo_no,E.sbid,S.wocode,R.step_code,T.stepname,E.materiel_id,S.partcode,M.partname,M.partspec,
                            E.unitid,S.unitcode,E.unitname,COALESCE(K.noid, E.stck_id) as stockid,COALESCE(K.code, E.stck_code) as stockcode,K.name as stockname,
                            S.qty,S.salecode,S.style
                            from TK_WMS_Inwh_Sub S
                            left join TKimp_Ewo E on S.mo_no=E.wo and S.mo_id=E.woid and S.partcode=E.materiel_code
                            left join TK_Wrk_Record R on S.inbarcode=R.inbarcode
                            left join TStep T on R.step_code=T.stepcode
                            left join TMateriel_Info M on S.partcode=M.partcode
                            left join TSecStck K on COALESCE(M.idwarehouse, E.stck_code)=K.code
                            where S.style='B' and S.hbillno=@hbillno
                            union all
                            select S.hbillno,S.rownumber,S.inbarcode,S.mo_id,S.mo_no,E.sbid,S.wocode,O.step_code,T.stepname,E.materiel_id,S.partcode,M.partname,M.partspec,
                            E.unitid,S.unitcode,E.unitname,COALESCE(K.noid, E.stck_id) as stockid,COALESCE(K.code, E.stck_code) as stockcode,K.name as stockname,
                            S.qty,S.salecode,S.style
                            from TK_WMS_Inwh_Sub S
                            left join TKimp_Ewo E on S.mo_no=E.wo and S.mo_id=E.woid and S.partcode=E.materiel_code
                            left join TK_Wrk_OutRecord O on S.inbarcode=O.inbarcode
                            left join TStep T on O.step_code=T.stepcode
                            left join TMateriel_Info M on S.partcode=M.partcode
                            left join TSecStck K on COALESCE(M.idwarehouse, E.stck_code)=K.code
                            where S.style='S' and S.hbillno=@hbillno
                            ) as AA" + search;
                DataTable data = DapperHelper.selectdata(sql, dynamicParams);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.count = total;
                mes.data = data;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[T8入库记录删除]
        public static ToMessage StorageRecordDelete(DataTable dt, User us)
        {
            var sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //存储过程名
                sql = @"h_p_IFCLD_T8DeleteInProductOrder";
                dynamicParams.Add("@RecordSub", dbType: DbType.Object, value: dt);
                // 添加输出参数
                dynamicParams.Add("@StatusCode", dbType: DbType.Int32, direction: ParameterDirection.Output);
                dynamicParams.Add("@Message", dbType: DbType.String, size: 255, direction: ParameterDirection.Output);
                bool a = DapperHelper.IsProcedure(sql, dynamicParams);
                // 获取输出参数的值
                var statusCode = dynamicParams.Get<int>("@StatusCode");
                var message = dynamicParams.Get<string>("@Message");
                if (a)
                {
                    mes.code = statusCode.ToString();
                    mes.count = 0;
                    mes.message = message;
                    mes.data = null;
                }
                else
                {
                    mes.code = statusCode.ToString();
                    mes.count = 0;
                    mes.message = message;
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
@@ -1767,13 +1822,25 @@
                    });
                    if (json[i].style == "B") 
                    {
                        //自制报工记录表入库数量
                        sql = @"update TK_Wrk_Record set inhouseqty=inhouseqty-@qty where inbarcode=@inbarcode";
                        //删除报工记录主表
                        //sql = @"delete from TK_Wrk_Record  where id=@repoid  and inbarcode=@inbarcode";
                        //list.Add(new
                        //{
                        //    str = sql,
                        //    parm = new
                        //    {
                        //        repoid = json[i].repoid.ToString(),
                        //        inbarcode = json[i].inbarcode.ToString()
                        //    }
                        //});
                        //修改自制报工入库数量
                        sql = @"update TK_Wrk_Record set inhouseqty=inhouseqty-@qty where inbarcode=@inbarcode and id=@repoid";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                repoid = json[i].repoid.ToString(),
                                qty = json[i].qty.ToString(),
                                inbarcode = json[i].inbarcode.ToString()
                            }
@@ -1781,7 +1848,18 @@
                    }
                    if (json[i].style == "S")
                    {
                        //外协收料记录表入库数量
                        //删除外协收料记录主表
                        //sql = @"delete from TK_Wrk_OutRecord  where id=@repoid  and inbarcode=@inbarcode";
                        //list.Add(new
                        //{
                        //    str = sql,
                        //    parm = new
                        //    {
                        //        repoid = json[i].repoid.ToString(),
                        //        inbarcode = json[i].inbarcode.ToString()
                        //    }
                        //});
                        //修改外协收料记录表入库数量
                        sql = @"update TK_Wrk_OutRecord set inhouseqty=inhouseqty-@qty where inbarcode=@inbarcode";
                        list.Add(new
                        {
@@ -1931,5 +2009,151 @@
            return mes;
        }
        #endregion
        #region[T+入库记录表头]
        public static ToMessage InStorageRecordMainSearch(string hbillno, string username, string hbdateopendate, string hbdateclosedate, string userdateopendate, string userdateclosedate, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (hbillno != "" && hbillno != null)
                {
                    search += "and hbillno like '%'+@hbillno+'%' ";
                    dynamicParams.Add("@hbillno", hbillno);
                }
                if (username != "" && username != null)
                {
                    search += "and create_user like '%'+@username+'%' ";
                    dynamicParams.Add("@username", username);
                }
                if (hbdateopendate != "" && hbdateopendate != null)
                {
                    search += "and hbdate between @hbdateopendate and @hbdateclosedate ";
                    dynamicParams.Add("@hbdateopendate", hbdateopendate + " 00:00:00");
                    dynamicParams.Add("@hbdateclosedate", hbdateclosedate + " 23:59:59");
                }
                if (userdateopendate != "" && userdateopendate != null)
                {
                    search += "and create_date between @userdateopendate and @userdateclosedate ";
                    dynamicParams.Add("@userdateopendate", userdateopendate + " 00:00:00");
                    dynamicParams.Add("@userdateclosedate", userdateclosedate + " 23:59:59");
                }
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select (case when docu_typecode='69' then '产成品入库' end) as hbilltype,hbillno,hbdate,create_user,create_date
                            from TK_WMS_Inwh_Main where 1=1 " + search;
                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.count = total;
                mes.data = data.ToList();
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[T+入库记录表体]
        public static ToMessage InStorageRecordSubSearch(string hbillno)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                dynamicParams.Add("@hbillno", hbillno);
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select *  from(
                            select S.hbillno,S.rownumber,S.inbarcode,S.mo_id,S.mo_no,E.sbid,S.wocode,R.step_code,T.stepname,E.materiel_id,S.partcode,M.partname,M.partspec,
                            E.unitid,S.unitcode,E.unitname,COALESCE(K.noid, E.stck_id) as stockid,COALESCE(K.code, E.stck_code) as stockcode,K.name as stockname,
                            S.qty,S.salecode,S.style
                            from TK_WMS_Inwh_Sub S
                            left join TKimp_Ewo E on S.mo_no=E.wo and S.mo_id=E.woid and S.partcode=E.materiel_code
                            left join TK_Wrk_Record R on S.inbarcode=R.inbarcode
                            left join TStep T on R.step_code=T.stepcode
                            left join TMateriel_Info M on S.partcode=M.partcode
                            left join TSecStck K on COALESCE(M.idwarehouse, E.stck_code)=K.code
                            where S.style='B' and S.hbillno=@hbillno
                            union all
                            select S.hbillno,S.rownumber,S.inbarcode,S.mo_id,S.mo_no,E.sbid,S.wocode,O.step_code,T.stepname,E.materiel_id,S.partcode,M.partname,M.partspec,
                            E.unitid,S.unitcode,E.unitname,COALESCE(K.noid, E.stck_id) as stockid,COALESCE(K.code, E.stck_code) as stockcode,K.name as stockname,
                            S.qty,S.salecode,S.style
                            from TK_WMS_Inwh_Sub S
                            left join TKimp_Ewo E on S.mo_no=E.wo and S.mo_id=E.woid and S.partcode=E.materiel_code
                            left join TK_Wrk_OutRecord O on S.inbarcode=O.inbarcode
                            left join TStep T on O.step_code=T.stepcode
                            left join TMateriel_Info M on S.partcode=M.partcode
                            left join TSecStck K on COALESCE(M.idwarehouse, E.stck_code)=K.code
                            where S.style='S' and S.hbillno=@hbillno
                            ) as AA" + search;
                DataTable data = DapperHelper.selectdata(sql, dynamicParams);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.count = total;
                mes.data = data;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[T+入库记录删除]
        public static ToMessage DeleteInStorageRecord(DataTable dt, User us)
        {
            var sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //存储过程名
                sql = @"h_p_IFCLD_TCloudDeleteInProductOrder";
                dynamicParams.Add("@RecordSub", dbType: DbType.Object, value: dt);
                // 添加输出参数
                dynamicParams.Add("@StatusCode", dbType: DbType.Int32, direction: ParameterDirection.Output);
                dynamicParams.Add("@Message", dbType: DbType.String, size: 255, direction: ParameterDirection.Output);
                bool a = DapperHelper.IsProcedure(sql, dynamicParams);
                // 获取输出参数的值
                var statusCode = dynamicParams.Get<int>("@StatusCode");
                var message = dynamicParams.Get<string>("@Message");
                if (a)
                {
                    mes.code = statusCode.ToString();
                    mes.count = 0;
                    mes.message = message;
                    mes.data = null;
                }
                else
                {
                    mes.code = statusCode.ToString();
                    mes.count = 0;
                    mes.message = message;
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
    }
}