diff --git a/.gitignore b/.gitignore index c631cfd..ec750c9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ NFine.Repository/obj/ NFine.Repository/bin/ NFine.Web/bin/ NFine.Web/obj/ +NFine.Domain/obj/ diff --git a/NFine.Application/01 Infrastructure/DbLogType.cs b/NFine.Application/01 Infrastructure/DbLogType.cs new file mode 100644 index 0000000..9a3703f --- /dev/null +++ b/NFine.Application/01 Infrastructure/DbLogType.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NFine.Application +{ + public enum DbLogType + { + [Description("其他")] + Other = 0, + [Description("登录")] + Login = 1, + [Description("退出")] + Exit = 2, + [Description("访问")] + Visit = 3, + [Description("新增")] + Create = 4, + [Description("删除")] + Delete = 5, + [Description("修改")] + Update = 6, + [Description("提交")] + Submit = 7, + [Description("异常")] + Exception = 8, + } +} diff --git a/NFine.Application/01 Infrastructure/vssver2.scc b/NFine.Application/01 Infrastructure/vssver2.scc new file mode 100644 index 0000000..cb26893 Binary files /dev/null and b/NFine.Application/01 Infrastructure/vssver2.scc differ diff --git a/NFine.Application/Properties/AssemblyInfo.cs b/NFine.Application/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..dafd883 --- /dev/null +++ b/NFine.Application/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("NFine快速开发平台")] +[assembly: AssemblyDescription("NFine快速开发平台")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("NFine团队")] +[assembly: AssemblyProduct("NFine快速开发平台(www.nfine.cn)")] +[assembly: AssemblyCopyright("Copyright © NFine 2016")] +[assembly: AssemblyTrademark("NFine.Framework")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("a2dde122-5712-466b-8039-a700af1ef8bc")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/NFine.Application/Properties/vssver2.scc b/NFine.Application/Properties/vssver2.scc new file mode 100644 index 0000000..6cafa3b Binary files /dev/null and b/NFine.Application/Properties/vssver2.scc differ diff --git a/NFine.Application/SRM/UserWorkPointApp.cs b/NFine.Application/SRM/UserWorkPointApp.cs new file mode 100644 index 0000000..6f1429a --- /dev/null +++ b/NFine.Application/SRM/UserWorkPointApp.cs @@ -0,0 +1,34 @@ +using NFine.Code; +using NFine.Data.Extensions; +using NFine.Domain.Entity.SystemManage; +using NFine.Repository; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Linq; +using System.Text; + +namespace NFine.Application +{ + public class UserWorkPointApp : RepositoryFactory + { + + public DataTable GetWorkPoint(string queryJson) + { + DataTable dt = new DataTable(); + var queryParam = queryJson.ToJObject(); + List parameter = new List(); + string sql = @"SELECT WorkPointCode,WorkPointName FROM dbo.Sys_WorkPoint where 1=1 "; + if (!string.IsNullOrWhiteSpace(queryJson)) + { + if (!string.IsNullOrWhiteSpace(queryParam["WorkPointCode"].ToString())) + { + sql += " and WorkPointCode = '%" + queryParam["WorkPointCode"].ToString() + "%' "; + } + } + return Repository().FindTableBySql(sql.ToString()); + } + + } +} diff --git a/NFine.Application/SRM/WatchPanelApp.cs b/NFine.Application/SRM/WatchPanelApp.cs new file mode 100644 index 0000000..8705ea3 --- /dev/null +++ b/NFine.Application/SRM/WatchPanelApp.cs @@ -0,0 +1,1295 @@ +using NFine.Code; +using NFine.Domain.Entity.SystemManage; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using NFine.Repository; +using System.Text; +using System; +using System.Configuration; +using NFine.Data; +using System.IO; +using Newtonsoft.Json; +using NFine.Domain._02_ViewModel; +using NFine.Data.Extensions; +using Newtonsoft.Json.Linq; + +namespace NFine.Application.SRM +{ + public class WatchPanelApp : RepositoryFactory + { + //到货明细 + public DataTable GetList1(string queryJson, ref Pagination jqgridparam) + { + var queryParam = queryJson.ToJObject(); + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; + List parameter = new List(); + string SqlText = @" +select * from ( + SELECT *, 收货数量 -已检数量 待检数量, + CASE WHEN 收货数量 -已检数量> 0 THEN '待检验' WHEN 已检待入> 0 THEN '待入库' ELSE '完成' END 状态 + FROM ( + SELECT cc.receiptNo 到货单号,dd.orderno 订单号,dd.itemcode 料号,dd.planqty 收货数量,inv.invname 物料名称, + isnull(( + SELECT SUM (lotqty) + FROM icsitemlot lot with (nolock) + WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine + AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint),0) 已检数量, + isnull(( + SELECT SUM (lotqty) + FROM icsitemlot lot with (nolock) + WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine + AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint + AND NOT EXISTS ( + SELECT 1 FROM ICSWareHouseLotInfo info + WHERE info.lotno=lot.lotno AND info.workpoint=lot.workpoint)),0) 已检待入 + FROM ICSINVReceipt cc with (nolock) + LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint + LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint + WHERE cc.mtime >=DATEADD(week, -1,getdate()) + and cc.workpoint='" + workpoint + @"' + ) ff ) gg + + "; + + DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam); + + + return dt; + + } + + //来料不合格明细 + public DataTable GetList2(string queryJson, ref Pagination jqgridparam) + { + var queryParam = queryJson.ToJObject(); + string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + List parameter = new List(); + string SqlText = @" + select * from ( + SELECT cc.receiptNo 到货单,dd.orderno 采购订单号,dd.itemcode 料号, inv.invname 物料名称, + sum(lot.lotqty) 不合格数量 ,kk.CKITEMDESC 不良原因 + + FROM ICSINVReceipt cc with (nolock) + LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint + LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint + left join icsitemlot lot with (nolock) on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine + AND cc.workpoint=lot.workpoint + left join (select * from (select ROW_NUMBER()over(partition by LOTNO order by mtime desc,id ) rowId,lotno ,errdata , + CASE WHEN NG='' THEN CKITEMDESC ELSE NG END CKITEMDESC + from ICSIQCErrList ck with (nolock) where workpoint='" + workpoint + @"' and errdata='不合格' ) as AuctionRecords + where rowId=1) kk on kk.lotno=lot.lotno + WHERE 1=1 + and cc.mtime >=DATEADD(MONTH, -1,getdate()) + -- and kk.errdata='不合格' + and isnull(lot.iqcstatus,'') ='不合格' + and cc.workpoint='" + workpoint + @"' + group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,kk.CKITEMDESC ) jj + "; + + DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam); + + + return dt; + + } + + + //配料信息表 + public DataTable GetList3(string queryJson, ref Pagination jqgridparam) + { + string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; + var queryParam = queryJson.ToJObject(); + string type = queryParam["type"].ToString(); + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + List parameter = new List(); + string SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTrans')) + drop table #Temp_TJRdTrans + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTransLog')) + drop table #Temp_TJRdTransLog + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJResult')) + drop table #Temp_TJResult + select tt.rdcode 出库单号,tt.invcode 产品编号, tt.rdstatus 业务类型, tt.depname 需求部门,tt.fromstoragecode 所属仓库, + tt.mocode 生产工单号,'' 项目号,tt.rduser 制单人,tt.mtime 制单日期 , CASE WHEN isnull(tt.actqty,0) !=0 then '完成' else '待提交' end 状态, + tt.rdNO,case when PLANQTY<0 then '物料退料' else '材料出库' end LogType + into #Temp_TJRdTrans + from ICSRdTransTer tt with (nolock) + left join icsmo mo with (nolock) on mo.mocode=tt.mocode and mo.moseq=tt.moseq and mo.workpoint=tt.workpoint + where tt.rdtype='材料出库单' + AND TT.MTIME >DATEADD(MONTH, -1, GETDATE()) + AND TT.WORKPOINT='" + workpoint + @"' + and CASE WHEN isnull(tt.actqty,0) !=0 then '已完成' else '未完成' end ='" + type + @"' + + + SELECT * into #Temp_TJRdTransLog FROM ( + select LOG.MUSERNAME,LOG.TransNO,LOG.TransLine,LOG.MTIME ,row_number() over (partition by LOG.BUSINESSCODE,LOG.TransNO,LOG.TransLine order by LOG.LOTNO desc,ID) rn + + from ICSWareHouseLotInfoLog LOG with (nolock) + WHERE EXISTS(SELECT 1 FROM #Temp_TJRdTrans TT + WHERE tt.rdNO =LOG.TransLine + AND TT.出库单号=LOG.TransNO AND LOG.BUSINESSCODE=tt.LogType and 状态='完成' ) + AND LOG.WORKPOINT='" + workpoint + @"' + + ) FF + WHERE RN=1 + + select distinct 出库单号,需求部门,生产工单号,制单人, + CONVERT(varchar(19), 制单日期, 21) 制单日期,CONVERT(varchar(19), 完成日期, 21) 完成日期,状态 into #Temp_TJResult + from ( + SELECT tt.*,log.MUSERNAME 审核人,log.mtime 完成日期 + FROM #Temp_TJRdTrans tt + LEFT JOIN #Temp_TJRdTransLog log on tt.rdNO =LOG.TransLine AND TT.出库单号=LOG.TransNO ) gg "; + + DataTable dt = Repository().FindTablePageBySql_OtherTemp(SqlText, " #Temp_TJResult ", + @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTrans')) + drop table #Temp_TJRdTrans + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTransLog')) + drop table #Temp_TJRdTransLog + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJResult')) + drop table #Temp_TJResult ", + "MESconnstr", parameter.ToArray(), ref jqgridparam); + + + return dt; + + } + + //待入库明细 + public DataTable GetList4(string queryJson, ref Pagination jqgridparam) + { + string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; + var queryParam = queryJson.ToJObject(); + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + List parameter = new List(); + string SqlText = @" + select * from ( + SELECT cc.receiptNo 到货单,dd.orderno 采购订单号,dd.itemcode 料号, inv.invname 物料名称, + sum(lot.lotqty) 待入库数量 ,(select top 1 bincode from ICSWareHouseLotInfo info where info.lotno=lot.lotno + and info.workpoint=cc.workpoint) 库位,lot.lotno 条码 + + FROM ICSINVReceipt cc with (nolock) + LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint + LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint + left join icsitemlot lot with (nolock) on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine AND cc.workpoint=lot.workpoint + left join ICSWareHouseLotInfolog kk with (nolock) on kk.lotno=lot.lotno and kk.workpoint=cc.workpoint and kk.transtype='收' + WHERE 1=1 + and kk.lotno is null + and lot.IQCStatus= '合格' + and cc.mtime >=DATEADD(month, -1,getdate()) + and cc.workpoint='" + workpoint + @"' + group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,lot.lotno ,kk.tostackcode,cc.workpoint + ) jj + "; + + DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam); + + + return dt; + + } + + + + //生产进度汇总表 + public DataTable GetList_WIPJinDu(string queryJson, string filters, ref Pagination jqgridparam) + { + try + { + List parameter = new List(); + + #region 过滤条件 + string SQLWhere = ""; + + if (!queryJson.Contains("[]")) + { + JObject jobject = JObject.Parse(queryJson); + JArray array = JArray.Parse(jobject["value"].ToString()); + SQLWhere += " and A.SEGCODE in ("; + + foreach(JObject j in array) { + SQLWhere += "'" + j["value"].ToString()+"',"; + } + SQLWhere= SQLWhere.TrimEnd(','); + SQLWhere += ")"; + } + + + + + + + #endregion + string SqlText = GetCaiJiSQL(SQLWhere); + + DataTable dt = SqlHelper.GetDataTableBySql(SqlText); + + return dt; + + } + catch (Exception ex) + { + WriteLogFile(ex.ToString(), "看板异常"); + } + return null; + } + + + public DataTable GetList_WIPJinDu(string value) + { + try + { + WriteLogFile("参数:"+ value, "看板异常"); + List parameter = new List(); + + #region 过滤条件 + string SQLWhere = ""; + if (!string.IsNullOrEmpty(value)) + { + SQLWhere += " and A.SEGCODE in ('" + value .Replace(",","','")+ "')"; + } + + + + + #endregion + string SqlText = GetCaiJiSQL(SQLWhere); + + DataTable dt = SqlHelper.GetDataTableBySql(SqlText); + + return dt; + + } + catch (Exception ex) + { + WriteLogFile(ex.ToString(), "看板异常"); + } + return null; + } + + + private string GetCaiJiSQL(string SQLWhere) + { + string SqlText = @" + + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOSelect')) + drop table #TempMOSelect + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCaiJi')) + drop table #TempCaiJi + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_MINDaJian')) + drop table #Temp_MINDaJian + select distinct lot.lotno,mo.mocode as 生产订单号, mo.moseq 生产订单行号, + a.StartPlanDate as 工单日期,c.INVPARSETYPE as 产品代码, + mo.ITEMCODE as 产品编码,mo.moplanqty as 计划量,lot.lotqty,a.mtime 换线时间,A.SEGCODE AS 线体 + into #TempMOSelect + from icsmo2user A with (nolock) + inner JOIN ICSMO mo with (nolock) ON A.MOCODE=mo.MOCODE AND A.MOSEQ=mo.MOSEQ + left join ICSITEMLot lot with (nolock) on mo.mocode=lot.transno and mo.moseq=lot.transline + LEFT JOIN ICSINVENTORY C with (nolock) ON C.INVCODE=mo.ITEMCODE + where mo.itemcode like '30%' and a.rcard='非批次' + and a.StartPlanDate >= dateadd(day,-30,getdate()) + " + SQLWhere + @" + + select hh.lotno,hh.AB面,min(hh.mtime) mtime,tt.lotqty lotqty,生产订单号,生产订单行号 + into #TempCaiJi + from( + select Rcard lotno,case when plane='BOTTOM' then 'B' else 'A' end AB面,min(mtime) mtime + from ICSSZAOIDATA + where Rcard is not null and Rcard!='' + and Rcard in (select lotno from #TempMOSelect) + group by Rcard,case when plane='BOTTOM' then 'B' else 'A' end + union all + select snno lotno,case when type='1' then 'A' else 'B' end AB面,min(data4) mtime + from ICSAIODATA dd + where snno is not null and snno!='' + and snno in (select lotno from #TempMOSelect tt) + group by snno ,case when type='1' then 'A' else 'B' end + ) hh + left join #TempMOSelect tt on hh.lotno=tt.lotno + group by hh.lotno,hh.AB面,tt.lotqty,生产订单号,生产订单行号 + + + select min(hh.mtime) mtime ,生产订单号 + into #Temp_MINDaJian + from ICSSMTFEEDINGINFO hh + inner join #TempCaiJi tt on hh.mocode=tt.生产订单号 + group by 生产订单号 + + + + select * , + case when 计划量 is not null and 计划量!=0 then cast(Convert(decimal(18,2),产出量*1.0000/计划量*100) as nvarchar) +'%' + else '0%' end 完成率 + from ( + select gg.线体,gg.生产订单号 ,gg.AB面,gg.工单日期 ,gg.产品编码 ,gg.产品代码 ,gg.换线时间 ,cc2.mtime 打件时间, + (select min(mtime) from #TempCaiJi cc + where cc.生产订单号=gg.生产订单号 and cc.生产订单行号=gg.生产订单行号 and cc.AB面=gg.AB面 ) 首检时间, + gg.计划量, + (select sum(lotqty) from #TempCaiJi cc + where cc.生产订单号=gg.生产订单号 and cc.生产订单行号=gg.生产订单行号 and cc.AB面=gg.AB面 ) 产出量 + + from ( + select cc.AB面,mm.生产订单号, mm.生产订单行号, + mm.工单日期,mm.产品代码, + mm. 产品编码,mm.计划量,min(换线时间) 换线时间,mm.线体 + from #TempCaiJi cc + left join #TempMOSelect mm with (nolock) on cc.lotno=mm.lotno + group by cc.AB面,mm.生产订单号, mm.生产订单行号, + mm.工单日期,mm.产品代码, + mm. 产品编码,mm.计划量,mm.线体 + ) gg + left join #Temp_MINDaJian cc2 on cc2.生产订单号=gg.生产订单号 + ) jj + order by 2,1,3 + + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOSelect')) + drop table #TempMOSelect + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCaiJi')) + drop table #TempCaiJi + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_MINDaJian')) + drop table #Temp_MINDaJian + + "; + return SqlText; + } + + //项目阶段 + public DataTable GetProjectJD() + { + List parameter = new List(); + string sql = @" select distinct REPLACE(PROJECTSTAGE, '生产确认表', '待装配') NAME from EXP_PROJECTPRODUCTIONSCHEDULE + where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and REPLACE(PROJECTSTAGE, '生产确认表', '待装配') is not null"; + DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray()); + return dt; + //DataTable tblDatas = new DataTable("Datas"); + //tblDatas.Columns.Add("NAME", Type.GetType("System.String")); + //for (int i = 0; i < 5; i++) + //{ + // DataRow newRow; + // newRow = tblDatas.NewRow(); + // newRow["NAME"] = i.ToString(); + // tblDatas.Rows.Add(newRow); + //} + + //return tblDatas; + } + + //设备类型 + public DataTable GetEQPType() + { + List parameter = new List(); + string sql = @" select distinct DEVICETYPE NAME from EXP_PROJECTPRODUCTIONSCHEDULE + where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and DEVICETYPE is not null "; + DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray()); + return dt; + } + + //状态 + public DataTable GetStatus() + { + List parameter = new List(); + string sql = @" select distinct case when PROJECTSTAGE ='FAT完成' then '完成' when PROJECTSTAGE ='FQC' then '完成' + when BEGINDATE like '%-%-%' and TO_DATE(BEGINDATE,'YYYY-MM-DD')-sysdate < 7 and NVL(RTRIM(PROJECTSCHEDULE,'%'),0) <80 then '紧急' else STATUS end NAME + from EXP_PROJECTPRODUCTIONSCHEDULE + where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') + and case when PROJECTSTAGE ='FAT完成' then '完成' when PROJECTSTAGE ='FQC' then '完成' + when BEGINDATE like '%-%-%' and TO_DATE(BEGINDATE,'YYYY-MM-DD')-sysdate < 7 and NVL(RTRIM(PROJECTSCHEDULE,'%'),0) <80 then '紧急' else STATUS end is not null "; + DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray()); + return dt; + } + + //生产进度-层析柱Qty + public DataTable GetWIPQty1() + { + try + { + List parameter = new List(); + string SqlText = @" + SELECT + sum(case when REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) like '%开始%' or + REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) not like '%完成%' + then to_number ( QUANTITY ) else 0 end ) WIPQTY, + sum(case when REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) not like '%开始%' and + REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) like '%完成%' + then to_number ( QUANTITY ) else 0 end ) COMQTY, + sum(to_number ( QUANTITY ) ) ZQTY, + REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ), '完成', '' ), '开始', '' ) PROJECTStr + FROM + EXP_PROJECTPRODUCTIONSCHEDULE + WHERE + 1 = 1 + and not (PROJECTID>='2117101' and PROJECTID<='2117116') + and DEVICETYPE in ('EAC系列') + and OQC is null + GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ), '完成', '' ), '开始', '' ) + HAVING sum(to_number ( QUANTITY ) )>0 "; + + DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray()); + + return dt; + } + catch (Exception ex) + { + WriteLogFile(ex.ToString(), "看板异常"); + } + return null; + } + + //生产进度-设备Qty + public DataTable GetWIPQty5() + { + try + { + List parameter = new List(); + string SqlText = @" SELECT + sum(case when REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) like '%开始%' or + REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) not like '%完成%' + then to_number ( QUANTITY ) else 0 end ) WIPQTY, + sum(case when REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) not like '%开始%' and + REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) like '%完成%' + then to_number ( QUANTITY ) else 0 end ) COMQTY, + sum(to_number ( QUANTITY ) ) ZQTY, + REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ), '完成', '' ), '开始', '' ) PROJECTStr + FROM + EXP_PROJECTPRODUCTIONSCHEDULE + WHERE + 1 = 1 + AND NOT ( PROJECTID >= '2117101' AND PROJECTID <= '2117116' ) + AND DEVICETYPE NOT IN ( 'SAC系列','EAC系列' ) + AND OQC IS NULL + GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ), '完成', '' ), '开始', '' ) + HAVING sum(to_number ( QUANTITY ) )>0 "; + + DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray()); + + return dt; + } + catch (Exception ex) + { + WriteLogFile(ex.ToString(), "看板异常"); + } + return null; + } + + //生产进度 柱状图 (在制数 完成数 ) + public DataTable GetWIPQty2() + { + + try + { + //生产确认表 有值中: 电装开始 有值 就是已开工,电装开始 无值 就是待开工 + List parameter = new List(); + string SqlText = @" SELECT + SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NOT NULL + THEN to_number(QUANTITY) ELSE 0 END) YKGQty, + SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NULL + THEN to_number(QUANTITY) ELSE 0 END) DKGQty + + from EXP_PROJECTPRODUCTIONSCHEDULE + WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL + and not (PROJECTID>='2117101' and PROJECTID<='2117116') + and OQC is null "; + + DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray()); + + return dt; + } + catch (Exception ex) + { + WriteLogFile(ex.ToString(), "看板异常"); + } + return null; + } + + //设备类型在制数 + public DataTable GetWIPQty3() + { + + try + { + //生产确认表 有值 FQC 无值 + List parameter = new List(); + string SqlText = @" SELECT + SUM( to_number(QUANTITY) ) Qty,nvl(DEVICETYPE,'空设备类型') EQPTypeName + from EXP_PROJECTPRODUCTIONSCHEDULE + WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL + and not (PROJECTID>='2117101' and PROJECTID<='2117116') + AND OQC IS NULL + GROUP BY DEVICETYPE "; + + DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray()); + + return dt; + } + catch (Exception ex) + { + WriteLogFile(ex.ToString(), "看板异常"); + } + return null; + } + + //待开工项目(Qty) + public DataTable GetWIPQty4() + { + + try + { + //生产确认表 有值 电装开始 无值 + List parameter = new List(); + string SqlText = @" + SELECT SUM ( to_number ( QUANTITY ) ) Qty, + SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ) MonthStr + FROM + EXP_PROJECTPRODUCTIONSCHEDULE + WHERE + 1 = 1 + AND( (ELECTRICASSEMBLYSTART IS NULL + AND PRODUCTIONCONFIRM IS NOT NULL + and OQC IS NULL + ) or PROJECTSTAGE='生产确认表' ) + AND BEGINDATE IS NOT NULL + and not (PROJECTID>='2117101' and PROJECTID<='2117116') + GROUP BY + SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ), + SUBSTR ( BEGINDATE, 0, 4 ), + to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) ) + ORDER BY + SUBSTR ( BEGINDATE, 0, 4 ), + to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) ) + "; + + DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray()); + + return dt; + } + catch (Exception ex) + { + WriteLogFile(ex.ToString(), "看板异常"); + } + return null; + } + + + + + //收货进度 + public DataTable GetRCVJingDu() + { + string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; + List parameter = new List(); + string SqlText = @" + if exists(select* from tempdb..sysobjects where id= object_id('tempdb..#TEMP_ItemCK')) + drop table #TEMP_ItemCK + + select sum(lotqty) Qty,cktype + INTO #TEMP_ItemCK + from( + select lot.lotno, lot.lotqty, lot.IQCStatus, lot.step, + case when lot.step= '优先' and lot.IQCStatus= '' then '优先待检' + when isnull(lot.step,'')!='优先' and lot.IQCStatus='' then '待检' + when lot.IQCStatus= '合格' then '已检待入' else '' end CKType + from ICSINVReceipt cc with (nolock) + left join ICSINVReceiptDetail dd with (nolock) on cc.ReceiptNO= dd.ReceiptNO and dd.workpoint= cc.workpoint + left join ICSITEMLot lot with (nolock) on lot.mcode= dd.itemcode and lot.TransNO= dd.ReceiptNO + and lot.TransLine= dd.ReceiptLine and dd.workpoint= lot.workpoint + + where not exists(select 1 from ICSWareHouseLotInfoLog log with (nolock) where log.lotno= lot.lotno) + and lot.lotno is not null + and cc.workpoint ='" + workpoint + @"' + and cc.mtime >=DATEADD(week, -1,getdate()) + ) gg + where cktype!='' + group by cktype + + select * from ( + SELECT QTY,CKTYPE,cast(CONVERT(DECIMAL(18,2),QTY/(SELECT SUM(QTY) FROM #TEMP_ItemCK )*100) as NVARCHAR) +'%' Qtypercent + from #TEMP_ItemCK + union all + SELECT 0,'优先待检', '0%' Qtypercent + where not EXISTS(select 1 from #TEMP_ItemCK where cktype='优先待检') + union all + SELECT 0,'已检待入', '0%' Qtypercent + where not EXISTS(select 1 from #TEMP_ItemCK where cktype='已检待入') + union all + SELECT 0,'待检', '0%' Qtypercent + where not EXISTS(select 1 from #TEMP_ItemCK where cktype='待检') + ) ff + order by case CKTYPE when '已检待入' then 0 when '优先待检' then 1 when '待检' then 2 else 3 end + "; + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); + + + return dt; + } + + //到货数量(item) + public DataTable GetRCVQty(string type) + { + string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; + List parameter = new List(); + + + string SqlText = ""; + switch (type) + { + case "日": + SqlText = @" + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + + SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS 日期 + INTO #TEMP_Itemrr_tt2 + FROM master.dbo.spt_values + WHERE type = 'p' + AND number <= 6 AND number >= 0 + + SELECT SUM( planqty ) QTY, + CONVERT ( VARCHAR ( 100 ), mtime, 23 ) 日期 + INTO #TEMP_Itemrr_tt + FROM + ICSINVReceiptDetail + WHERE + mtime >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00' + AND workpoint = '" + workpoint + @"' + GROUP BY + CONVERT ( VARCHAR ( 100 ), mtime, 23 ) + + SELECT substring( aa.日期,6,5) 日期, + isnull( bb.qty, 0 ) QTY + FROM + #TEMP_Itemrr_tt2 aa + LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 + ORDER BY 1 + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 "; + break; + case "周": + SqlText = @" + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + + SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS 日期 , + CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23) 年 + INTO #TEMP_Itemrr_tt2 + FROM master.dbo.spt_values + WHERE + type = 'p' + AND number <= 7 AND number >= 0 + + SELECT SUM( planqty ) QTY, + DATEPART(wk, mtime) 日期,CONVERT( VARCHAR ( 4 ),mtime,23) 年 INTO #TEMP_Itemrr_tt + FROM + ICSINVReceiptDetail with (nolock) + WHERE + mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00' + AND workpoint = '" + workpoint + @"' + GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) + ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime) + + SELECT + aa.日期, + isnull( bb.qty, 0 ) QTY + FROM + #TEMP_Itemrr_tt2 aa + LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 AND aa.年 = bb.年 + ORDER BY aa.年, aa.日期 + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + "; break; + case "月": + SqlText = @" + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + + SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS 日期 , + CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23) 年 + INTO #TEMP_Itemrr_tt2 + FROM master.dbo.spt_values + WHERE + type = 'p' + AND number <= 11 AND number >= 0 + + SELECT SUM( planqty ) QTY, + DATEPART(month, mtime) 日期,CONVERT( VARCHAR ( 4 ),mtime,23) 年 INTO #TEMP_Itemrr_tt + FROM + ICSINVReceiptDetail with (nolock) + WHERE + mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00' + AND workpoint = '" + workpoint + @"' + GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) + ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime) + + SELECT + aa.日期, + isnull( bb.qty, 0 ) QTY + FROM + #TEMP_Itemrr_tt2 aa + LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 AND aa.年 = bb.年 + ORDER BY aa.年, aa.日期 + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + "; break; + case "年": SqlText = @" + SELECT SUM( planqty ) QTY, + CONVERT( VARCHAR ( 4 ),mtime,23) 日期 + FROM + ICSINVReceiptDetail with (nolock) + WHERE workpoint = '" + workpoint + @"' + GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23) + ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23) + + + "; break; + } + + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); + + + return dt; + } + + //入库数量(item) + public DataTable GetWareInQty(string type) + { + string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; + List parameter = new List(); + + + string SqlText = ""; + switch (type) + { + case "日": + SqlText = @" + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + + SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS 日期 + INTO #TEMP_Itemrr_tt2 + FROM master.dbo.spt_values + WHERE type = 'p' + AND number <= 6 AND number >= 0 + + SELECT SUM( TRANSQTY ) QTY, + CONVERT ( VARCHAR ( 100 ), MTIME, 23 ) 日期 + INTO #TEMP_Itemrr_tt + FROM + ICSWareHouseLotInfoLOG log with (nolock) + WHERE + MTIME >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00' + AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退') + GROUP BY + CONVERT ( VARCHAR ( 100 ), MTIME, 23 ) + + SELECT substring( aa.日期,6,5) 日期, + isnull( bb.qty, 0 ) QTY + FROM + #TEMP_Itemrr_tt2 aa + LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 + ORDER BY 1 + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 "; + break; + case "周": + SqlText = @" + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + + SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS 日期 , + CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23) 年 + INTO #TEMP_Itemrr_tt2 + FROM master.dbo.spt_values + WHERE + type = 'p' + AND number <= 7 AND number >= 0 + + SELECT SUM( transqty ) QTY, + DATEPART(wk, mtime) 日期,CONVERT( VARCHAR ( 4 ),mtime,23) 年 INTO #TEMP_Itemrr_tt + FROM + ICSWareHouseLotInfolog log with (nolock) + WHERE + mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00' + AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退') + GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) + ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime) + + SELECT + aa.日期, + isnull( bb.qty, 0 ) QTY + FROM + #TEMP_Itemrr_tt2 aa + LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 AND aa.年 = bb.年 + ORDER BY aa.年, aa.日期 + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + "; break; + case "月": + SqlText = @" + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + + SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS 日期 , + CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23) 年 + INTO #TEMP_Itemrr_tt2 + FROM master.dbo.spt_values + WHERE + type = 'p' + AND number <= 11 AND number >= 0 + + SELECT SUM( transqty ) QTY, + DATEPART(month, mtime) 日期,CONVERT( VARCHAR ( 4 ),mtime,23) 年 INTO #TEMP_Itemrr_tt + FROM + ICSWareHouseLotInfolog log with (nolock) + WHERE + mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00' + AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退') + GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) + ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime) + + SELECT + aa.日期, + isnull( bb.qty, 0 ) QTY + FROM + #TEMP_Itemrr_tt2 aa + LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 AND aa.年 = bb.年 + ORDER BY aa.年, aa.日期 + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) + DROP TABLE #TEMP_Itemrr_tt + + IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) + DROP TABLE #TEMP_Itemrr_tt2 + "; break; + case "年": SqlText = @" + SELECT SUM( transqty ) QTY, + CONVERT( VARCHAR ( 4 ),mtime,23) 日期 + FROM + ICSWareHouseLotInfolog log with (nolock) + WHERE workpoint = '" + workpoint + @"' and log.transtype in ('收','退') + GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23) + ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23) + + + "; break; + } + + + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); + + + return dt; + } + + + + + //配料进度 + public DataTable GetPeiLiaoJingDu() + { + string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; + List parameter = new List(); + string SqlText = @" + select UnDoQty, DoneQty, + case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), DoneQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end DoneQtyPer, + case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), UnDoQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end UnDoQtyPer + from( + select isnull(sum(case when isnull(actqty, 0) = 0 then planqty else 0 end),0) UnDoQty, + isnull(sum(case when isnull(actqty, 0) = 0 then 0 else actqty end),0) DoneQty + + from ICSRdTransTer with (nolock) + where RdType = '材料出库单' + and planqty > 0 and workpoint ='" + workpoint + @"' + and mtime >=DATEADD(MONTH, -1,getdate()) + ) gg + + "; + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); + DataTable retdd = new DataTable(); + retdd.Columns.Add("cktype", Type.GetType("System.String")); + retdd.Columns.Add("Qty", Type.GetType("System.Decimal")); + retdd.Columns.Add("Qtypercent", Type.GetType("System.String")); + + + if (dt != null && dt.Rows.Count > 0) + { + DataRow newRow = retdd.NewRow(); + newRow["cktype"] = "待配料"; + newRow["Qty"] = Convert.ToDecimal(dt.Rows[0]["UnDoQty"].ToString()); + newRow["Qtypercent"] = dt.Rows[0]["UnDoQtyPer"].ToString(); + retdd.Rows.Add(newRow); + + DataRow newRow2 = retdd.NewRow(); + newRow2["cktype"] = "已配料"; + newRow2["Qty"] = Convert.ToDecimal(dt.Rows[0]["DoneQty"].ToString()); + newRow2["Qtypercent"] = dt.Rows[0]["DoneQtyPer"].ToString(); + retdd.Rows.Add(newRow2); + } + else + { + DataRow newRow = retdd.NewRow(); + newRow["cktype"] = "待配料"; + newRow["Qty"] = 0; + newRow["Qtypercent"] = "0%"; + retdd.Rows.Add(newRow); + + DataRow newRow2 = retdd.NewRow(); + newRow2["cktype"] = "已配料"; + newRow2["Qty"] = 0; + newRow2["Qtypercent"] = "0%"; + retdd.Rows.Add(newRow2); + } + + return retdd; + } + + public DataTable GetSScode(string cookie) { + string sql = @" + select distinct a.sscode as name,a.sscode as value,'' as selected + from ICSSS as a,ICSSEG as b,ICSSHIFTTYPE as c + where a.SEGID = b.ID and a.SHIFTTYPEID = c.ID and + b.WorkPoint = a.WorkPoint and c.WorkPoint = a.WorkPoint + order by 1 "; + DataTable table= Repository().GetDataTableBySql_Other(sql, "MESconnstr", null); + foreach (DataRow row in table.Rows) + { + if (!string.IsNullOrEmpty(cookie)) + { + JObject jobject = JObject.Parse(cookie); + JArray array = JArray.Parse(jobject["value"].ToString()); + foreach (JObject j in array) { + if (j["value"].ToString() == row["value"].ToString()) + row["selected"] = "true"; + } + + } + + } + table.AcceptChanges(); + return table; + } + + public static void WriteLogFile(string input, string txtName) + { + try + { + string logAdress = "C:\\看板日志" + "\\"; + if (!System.IO.Directory.Exists(logAdress)) + { + System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录 + } + + string adress = logAdress + txtName; + if (!System.IO.Directory.Exists(adress)) + { + System.IO.Directory.CreateDirectory(adress);//不存在就创建目录 + } + + // string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString(); + /**/ + ///指定日志文件的目录 + string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt"; + /**/ + ///定义文件信息对象 + + FileInfo finfo = new FileInfo(fname); + + if (!finfo.Exists) + { + FileStream fs; + fs = File.Create(fname); + fs.Close(); + finfo = new FileInfo(fname); + } + + /**/ + ///判断文件是否存在以及是否大于2K + if (finfo.Length > 1024 * 1024 * 10) + { + /**/ + ///文件超过10MB则重命名 + File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt"); + /**/ + ///删除该文件 + //finfo.Delete(); + } + //finfo.AppendText(); + /**/ + ///创建只写文件流 + + using (FileStream fs = finfo.OpenWrite()) + { + /**/ + ///根据上面创建的文件流创建写数据流 + StreamWriter w = new StreamWriter(fs); + + /**/ + ///设置写数据流的起始位置为文件流的末尾 + + ///设置写数据流的起始位置为文件流的末尾 + w.BaseStream.Seek(0, SeekOrigin.End); + + w.WriteLine("*****************Start*****************"); + w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + /**/ + ///写入当前系统时间并换行 + + /**/ + ///写入日志内容并换行 + w.WriteLine(input); + + /**/ + ///写入------------------------------------“并换行 + w.WriteLine("------------------END------------------------"); + + /**/ + ///清空缓冲区内容,并把缓冲区内容写入基础流 + w.Flush(); + + /**/ + ///关闭写数据流 + w.Close(); + } + } + catch (Exception ex) + { } + + } + + + public string ConvertDataTableToJson(DataTable dt) + { + StringBuilder sbs = new StringBuilder(); + if (dt.Rows.Count > 0)//如果有记录 + { + sbs.Append("{'" + dt.TableName + "':["); + string str = ""; + foreach (DataRow dr in dt.Rows)//开始拼 + { + string result = ""; + foreach (DataColumn dc in dt.Columns) + { + result += string.Format(",'{0}':'{1}'", + dc.ColumnName, dr[dc.ColumnName]); + } + result = result.Substring(1); + result = ",{" + result + "}"; + str += result; + } + str = str.Substring(1); + sbs.Append(str); + sbs.Append("]}"); + } + else//如果没有记录 + { + sbs.Append(""); + } + return sbs.ToString(); + } + + + #region 执行大看板 + public DataTable GetZhiXing_MO(string ItemNumber) + { + + + string SqlText = ""; + + SqlText = @" +SELECT DISTINCT C.molotcode as 销售车号,C.ITEMCODE 物料编码,dd.INVNAME 物料名称 ,C.MOCODE 工单号,LL.OPSEQ, +a.OPCODE 工序代码,ppp.opname 工序名称,us.UserName 报工人, +CASE WHEN A.ACTIONRESULT='COLLECT_BEGIN' then '----生产中----' WHEN A.ACTIONRESULT='COLLECT_END' then '----已结束----' end as 工序结束状态, +SUM(DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime)) as '报工时长', +SUM(DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime))-ISNULL(xx.[暂停时长],0) AS 有效时间, +xx.[暂停时长], +CONVERT(VARCHAR,B.BeginDateTime,120) 开工时间, +CONVERT(VARCHAR,B.EndDateTime,120) 完工时间, +CONVERT(VARCHAR,xx.开始时间 ,120) as 暂停开始时间, +CONVERT(VARCHAR,xx.结束时间,120) as 暂停结束时间, +xx.[暂停原因], +xx.[暂停备注] +FROM ICSLOTONWIP A +LEFT JOIN ICSLOTONWIPDetail B ON A.LOTNO=B.LOTNO AND A.OPCODE=B.OPCODE +LEFT JOIN ICSOP ppp on a.OPCODE=ppp.OPCODE +LEFT JOIN ICSLOTSIMULATION nn on nn.LOTNO=A.LOTNO +LEFT JOIN Sys_User us on us.UserCode=B.UserCodeBegin +LEFT JOIN ICSMO C ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQ +LEFT JOIN ICSMO2ROUTE gg ON c.MOCODE=gg.MOCODE and gg.EATTRIBUTE1=C.MOSEQ +LEFT JOIN ICSINVENTORY dd on C.ITEMCODE=dd.INVCODE +LEFT JOIN ICSITEMROUTE2OPLot LL ON LL.LotNo=A.LOTNO AND A.OPCODE=LL.OPCODE +LEFT JOIN ICSMO2User UU ON UU.LOTNO=A.LOTNO AND UU.OPCODE=A.OPCODE AND B.ECCode=UU.CREWCODE +LEFT JOIN (SELECT DISTINCT C.molotcode as 销售车号,C.ITEMCODE 物料编码,dd.INVNAME 物料名称 ,gg.ROUTECODE 工艺路线 ,A.LOTNO 跟踪单号, +c.MOCODE 工单号,c.MOSEQ 工单行号, A.OPCODE 工序,us.UserName as 报工人, +pp.BeginTime 开始时间, +pp.EndTime 结束时间, +SUM(DATEDIFF(MINUTE, PP.BeginTime, PP.EndTime)) as '暂停时长' , +vv.EnumText 暂停原因, +pp.Memo 暂停备注 +from ICSLOTONWIP A INNER JOIN ICSLOTPAUSE pp on A.Lotno=pp.lotno and A.opcode=pp.opcode + +LEFT JOIN Sys_User us on us.UserCode=PP.Usercode +LEFT JOIN ICSMO C ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQ +LEFT JOIN ICSMO2ROUTE gg ON c.MOCODE=gg.MOCODE and gg.EATTRIBUTE1=C.MOSEQ +LEFT JOIN ICSINVENTORY dd on C.ITEMCODE=dd.INVCODE +LEFT JOIN ICSITEMROUTE2OPLot LL ON LL.LotNo=A.LOTNO AND A.OPCODE=LL.OPCODE +LEFT JOIN ICSMO2User UU ON UU.LOTNO=A.LOTNO AND UU.OPCODE=A.OPCODE AND pp.EATTRIBUTE1=UU.CREWCODE +LEFT JOIN Sys_EnumValues vv on vv.EnumValue=pp.RESCODE --AND vv.EnumKey='00022' +where pp.MODELCODE='标准报工' and vv.EnumKey='00022' --AND a.LOTNO=''-- and A.ACTIONRESULT = 'COLLECT_END' +GROUP BY C.molotcode,C.ITEMCODE ,dd.INVNAME ,gg.ROUTECODE, A.LOTNO,c.MOCODE ,c.MOSEQ , A.OPCODE ,us.UserName,pp.BeginTime,pp.EndTime,vv.EnumText , +pp.Memo) +xx on xx.[工单号]=c.MOCODE AND xx.[工单行号]=c.MOSEQ AND A.OPCODE=xx.[工序] AND xx.[报工人]=us.UserName AND xx.开始时间 >B.BeginDateTime AND xx.结束时间 < B.EndDateTime +where 1=1 AND b.Type='标准报工' and a.WorkPoint='6000' +GROUP BY C.molotcode,C.ITEMCODE ,dd.INVNAME ,gg.ROUTECODE, A.LOTNO,c.MOCODE ,c.MOSEQ , A.OPCODE ,us.UserName,xx.[暂停时长],nn.ISCOM,b.MTIME,B.BeginDateTime, B.EndDateTime,xx.[开始时间],xx.[结束时间],ppp.opname,xx.[暂停原因], +xx.[暂停备注],A.ACTIONRESULT,LL.OPSEQ +ORDER BY C.molotcode, C.ITEMCODE ,LL.OPSEQ,us.UserName asc + + "; + + + + + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); + + + return dt; + } + #endregion + #region 振翔生产进度 + public DataTable GetProductProgress(string ItemNumber) + { + string where1 = ""; + + string SqlText = ""; + + SqlText = @" "; + + + + + + + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); + + + return dt; + } + + public DataTable GetZhiXing_OQC( ) + { + + string SqlText = ""; + + SqlText = @" + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC')) + drop table #TempIPPCC + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc')) + drop table #TempMonthcc + + + declare @begin datetime,@end datetime + set @end=GETDATE() + declare @months int + set @months=6 + select convert(varchar(7),DATEADD(month,number*-1+1,@end) ,120) AS 月份 + into #TempMonthcc + from master.dbo.spt_values + where type='p' + AND number<=@months + and number>=1 + order by 1 + + select count(1) Qty,result,月份 + into #TempIPPCC + from ( + select distinct ccode, invcode ,result,convert(varchar(7),mtime,120) 月份 + + from ICSOQCLotNo + where mtime>=DATEADD(month,DATEDIFF(month,0,DATEADD(mm, -5, GETDATE() )),0) + and result in('合格','不合格') + ) dd + group by 月份,result + + + + select isnull( case when isnull(gg.QtyAll,0) =0 then 0 else + Convert(decimal(18,2), (isnull(gg.QtyAll,0)-isnull(FF.QtyNG,0))*1.00/gg.QtyAll*100) end + ,0) PercentNum, + cc.月份 + FROM #TempMonthcc cc + left join (select sum(qty) QtyAll,月份 from #TempIPPCC hh group by 月份 ) GG on cc.月份=gg.月份 + left join (select isnull(sum(qty),0) QtyNG,月份 from #TempIPPCC hh where result='不合格' group by 月份 ) ff on cc.月份=ff.月份 + ORDER BY cc.月份 + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC')) + drop table #TempIPPCC + if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc')) + drop table #TempMonthcc + "; + + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); + + + return dt; + } + + + public DataTable GetZhiXing_RCVUnInWare() + { + + string SqlText = ""; + + SqlText = @" + select A.CCODE 到货单号, B.LOTNO,a.cInvCode as 物料编码,C.INVSTD 规格型号,C.INVNAME 物料名称,b.transno 采购订单号, + A.iQuantity AS 数量,A.STNO 送货单号 ,CONVERT(varchar(100), a.MTime, 23) MTime , + STUFF((select',' + MUSERName from (SELECT DISTINCT MUSERName FROM ICSOQCLotNo d where D.CCODE=a.cCode and d.InvCode=a.cInvCode ) DD for xml path('')),1,1,'') 检验人 + + from ICSPOArrive a with(nolock) + inner join icsitemlot b with(nolock) on a.LOTNO=b.LotNO + LEFT JOIN ICSINVENTORY C with(nolock) ON C.INVCODE = A.cInvCode + where EXISTS(select 1 from ICSOQCLotNo d with(nolock) where D.CCODE=a.cCode and d.InvCode=a.cInvCode and result='合格' ) + and not EXISTS(select 1 from ICSWareHouseLotInfoLog ll with(nolock) where ll.lotno=a.lotno and ll.TransType='收') + order by A.CCODE,a.cInvCode,B.LOTNO "; + + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); + + + return dt; + } + #endregion + + + } +} diff --git a/NFine.Application/SRM/vssver2.scc b/NFine.Application/SRM/vssver2.scc new file mode 100644 index 0000000..0179faa Binary files /dev/null and b/NFine.Application/SRM/vssver2.scc differ diff --git a/NFine.Application/SystemManage/AreaApp.cs b/NFine.Application/SystemManage/AreaApp.cs new file mode 100644 index 0000000..7986390 --- /dev/null +++ b/NFine.Application/SystemManage/AreaApp.cs @@ -0,0 +1,50 @@ +using NFine.Domain.Entity.SystemManage; +using NFine.Domain.IRepository.SystemManage; +using NFine.Repository.SystemManage; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace NFine.Application.SystemManage +{ + public class AreaApp + { + private IAreaRepository service = new AreaRepository(); + + public List GetList() + { + return service.IQueryable().ToList(); + } + + public AreaEntity GetForm(string keyValue) + { + return service.FindEntity(keyValue); + } + + public void DeleteForm(string keyValue) + { + if (service.IQueryable().Count(t => t.F_ParentId.Equals(keyValue)) > 0) + { + throw new Exception("删除失败!操作的对象包含了下级数据。"); + } + else + { + service.Delete(t => t.F_Id == keyValue); + } + } + + public void SubmitForm(AreaEntity areaEntity, string keyValue) + { + if (!string.IsNullOrEmpty(keyValue)) + { + areaEntity.Modify(keyValue); + service.Update(areaEntity); + } + else + { + areaEntity.Create(); + service.Insert(areaEntity); + } + } + } +} diff --git a/NFine.Application/SystemManage/CommonReportApp.cs b/NFine.Application/SystemManage/CommonReportApp.cs new file mode 100644 index 0000000..52f87db --- /dev/null +++ b/NFine.Application/SystemManage/CommonReportApp.cs @@ -0,0 +1,1543 @@ +using NFine.Code; +using NFine.Domain.Entity.SystemManage; +using NFine.Domain.IRepository.SystemManage; +using NFine.Repository.SystemManage; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Data; +using System.Data.Common; +using System.Text; +using NFine.Data.Extensions; +using NFine.Repository; +using System.Data.SqlClient; +using NFine.Domain._03_Entity.SystemManage; +using Newtonsoft.Json; +using System.Reflection; +using Newtonsoft.Json.Linq; + +namespace NFine.Application.SystemManage +{ + + public class CommonReportApp : RepositoryFactory + { + //查询数据 + public DataTable GetGridJson(string sqlTxt, string DBName, string TempName, ref Pagination jqgridparam) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string SqlText = sqlTxt; + if (SqlText.Contains("[AppConfig.WorkPointCode]")) + { + SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location); + } + if (SqlText.Contains("[AppConfig.UserId]")) + { + SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId); + } + if (SqlText.Contains("[AppConfig.UserCode]")) + { + SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode); + } + if (SqlText.Contains("[AppConfig.UserName]")) + { + SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName); + } + List parameter = new List(); + // return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, ref jqgridparam, null); + if (!string.IsNullOrEmpty(TempName)) + { + return Repository().FindTablePageBySql_OtherTemp(SqlText, " " + TempName + " ", " ", DBName, parameter.ToArray(), ref jqgridparam); + } + else + { + return Repository().FindTablePageBySql_Other(SqlText, DBName, parameter.ToArray(), ref jqgridparam); + } + + + } + + + //查询数据 + public DataTable GetGridJsonNew(string MenuID, string sqlTxt_Condition, string DBName, string TempName, ref Pagination jqgridparam) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + DataTable dt = GetMenuSQL(MenuID); + + string SqlText = dt.Rows[0]["SqlTxt"].ToString(); + + if (!string.IsNullOrEmpty(sqlTxt_Condition) && sqlTxt_Condition != "[]") + { + ConditionSQLClass[] list = JsonConvert.DeserializeObject(sqlTxt_Condition); + if (list != null && list.Length > 0) + { + for (int i = 0; i < list.Length; i++) + { + SqlText = SqlText.Replace(list[i].CIndex,list[i].Content); + } + + } + } + + if (SqlText.Contains("[AppConfig.WorkPointCode]")) + { + SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location); + } + if (SqlText.Contains("[AppConfig.UserId]")) + { + SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId); + } + if (SqlText.Contains("[AppConfig.UserCode]")) + { + SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode); + } + if (SqlText.Contains("[AppConfig.UserName]")) + { + SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName); + } + + List parameter = new List(); + // return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, ref jqgridparam, null); + if (!string.IsNullOrEmpty(TempName)) + { + return Repository().FindTablePageBySql_OtherTemp(SqlText, " " + TempName + " ", " ", DBName, parameter.ToArray(), ref jqgridparam); + } + else + { + return Repository().FindTablePageBySql_Other(SqlText, DBName, parameter.ToArray(), ref jqgridparam); + } + + + } + + public DataTable ExportAll(string sqlTxt, string DBName, string TempName, string MenuID) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string SqlText = sqlTxt; + if (SqlText.Contains("[AppConfig.WorkPointCode]")) + { + SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location); + } + if (SqlText.Contains("[AppConfig.UserId]")) + { + SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId); + } + if (SqlText.Contains("[AppConfig.UserCode]")) + { + SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode); + } + if (SqlText.Contains("[AppConfig.UserName]")) + { + SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName); + } + + // return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, null); + if (!string.IsNullOrEmpty(TempName)) + { + SqlText = SqlText + " select * from " + TempName + " "; + } + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, DBName, null); + //栏位权限控制 + string sql2 = @" + select distinct ColCaption,ColFiledName from ( + SELECT rr.ColCaption,rr.ColFiledName, rr.VisbleFlag, + (case when (select count(1) from Sys_FormColsVisible vv + where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"') + >0 then '1' else '0' end) RoleVisible + FROM dbo.Sys_ColsOfGridReport rr + left join Sys_FormDataSource ss on rr.SourceId=ss.id + where ss.menuid='" + MenuID + @"' ) fff + where VisbleFlag=1 and RoleVisible='1' + + "; + DataTable dtcol = Repository().FindTableBySql(sql2); + if (dtcol != null && dtcol.Rows.Count > 0) + { + List DelList = new List(); + for (int i = 0; i < dt.Columns.Count; i++) + { + DataRow[] dr = dtcol.Select("ColFiledName='" + dt.Columns[i].ColumnName + "'"); + if (dr != null && dr.Length > 0) + { + dt.Columns[i].ColumnName = dr[0]["ColCaption"].ToString(); + } + else + { + // dt.Columns.Remove(dt.Columns[i].ColumnName);这样子是错误的 删除的过程中 i会变化 + DelList.Add(i); + } + } + + for (int j = DelList.Count - 1; j >= 0; j--) + { + + dt.Columns.Remove(dt.Columns[DelList[j]]); + } + + return dt; + } + return null; + + + } + + + + public DataTable ExportAllNew(string sqlTxt_Condition, string DBName, string TempName, string MenuID) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + DataTable dt2 = GetMenuSQL(MenuID); + string SqlText = dt2.Rows[0]["SqlTxt"].ToString(); + + + if (!string.IsNullOrEmpty(sqlTxt_Condition) && sqlTxt_Condition != "[]") + { + ConditionSQLClass[] list = JsonConvert.DeserializeObject(sqlTxt_Condition); + if (list != null && list.Length > 0) + { + for (int i = 0; i < list.Length; i++) + { + SqlText = SqlText.Replace(list[i].CIndex, list[i].Content); + } + + } + } + + if (SqlText.Contains("[AppConfig.WorkPointCode]")) + { + SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location); + } + if (SqlText.Contains("[AppConfig.UserId]")) + { + SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId); + } + if (SqlText.Contains("[AppConfig.UserCode]")) + { + SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode); + } + if (SqlText.Contains("[AppConfig.UserName]")) + { + SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName); + } + + // return SqlHelper.GetDataTableBySql_OtherConn(SqlText, DBName, null); + if (!string.IsNullOrEmpty(TempName)) + { + SqlText = SqlText + " select * from " + TempName + " "; + } + + DataTable dt = Repository().GetDataTableBySql_Other(SqlText, DBName, null); + //栏位权限控制 + string sql2 = @" + select distinct ColCaption,ColFiledName from ( + SELECT rr.ColCaption,rr.ColFiledName, rr.VisbleFlag, + (case when (select count(1) from Sys_FormColsVisible vv + where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"') + >0 then '1' else '0' end) RoleVisible + FROM dbo.Sys_ColsOfGridReport rr + left join Sys_FormDataSource ss on rr.SourceId=ss.id + where ss.menuid='" + MenuID + @"' ) fff + where VisbleFlag=1 and RoleVisible='1' + + "; + DataTable dtcol = Repository().FindTableBySql(sql2); + if (dtcol != null && dtcol.Rows.Count > 0) + { + List DelList = new List(); + for (int i = 0; i < dt.Columns.Count; i++) + { + DataRow[] dr = dtcol.Select("ColFiledName='" + dt.Columns[i].ColumnName + "'"); + if (dr != null && dr.Length > 0) + { + dt.Columns[i].ColumnName = dr[0]["ColCaption"].ToString(); + } + else + { + // dt.Columns.Remove(dt.Columns[i].ColumnName);这样子是错误的 删除的过程中 i会变化 + DelList.Add(i); + } + } + + for (int j = DelList.Count - 1; j >= 0; j--) + { + + dt.Columns.Remove(dt.Columns[DelList[j]]); + } + + return dt; + } + return null; + + + } + + + + + public DataTable GetGridJson(string sqlTxt, string DBName, string TempName) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string SqlText = sqlTxt; + if (SqlText.Contains("[AppConfig.WorkPointCode]")) + { + SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location); + } + if (SqlText.Contains("[AppConfig.UserId]")) + { + SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId); + } + if (SqlText.Contains("[AppConfig.UserCode]")) + { + SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode); + } + if (SqlText.Contains("[AppConfig.UserName]")) + { + SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName); + } + + if (!string.IsNullOrEmpty(TempName)) + { + SqlText = SqlText + " select * from " + TempName + " "; + } + + return Repository().GetDataTableBySql_Other(SqlText, DBName, null); + + + + } + + public DataTable GetGridJsonText(string sqlTxt, string DBName, string TempName) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string SqlText = sqlTxt; + if (SqlText.Contains("[AppConfig.WorkPointCode]")) + { + SqlText = SqlText.Replace("[AppConfig.WorkPointCode]", oo.Location); + } + if (SqlText.Contains("[AppConfig.UserId]")) + { + SqlText = SqlText.Replace("[AppConfig.UserId]", oo.UserId); + } + if (SqlText.Contains("[AppConfig.UserCode]")) + { + SqlText = SqlText.Replace("[AppConfig.UserCode]", oo.UserCode); + } + if (SqlText.Contains("[AppConfig.UserName]")) + { + SqlText = SqlText.Replace("[AppConfig.UserName]", oo.UserName); + } + + if (!string.IsNullOrEmpty(TempName)) + { + SqlText = SqlText + " select top 1 * from " + TempName + " "; + } + + return Repository().GetDataTableBySql_Other(SqlText, DBName, null); + + + + } + + + + //获取数据源DB + public DataTable GetAllDataBase() + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + //string sql = @" select DBSourceName,DBSourceDesc ,ID DbId from Sys_DataBase where WorkCode='" + oo.Location + "' "; + string sql = @" select DBSourceName,DBSourceDesc ,ID DbId from Sys_DataBase "; + return Repository().FindTableBySql(sql); + } + + //GetMenuID + public DataTable GetMenuID(string MenuTag) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string sql = @" + SELECT f_id MenuID FROM Sys_SRM_Module where F_UrlAddress like '%MenuTag=" + MenuTag + "' "; + return Repository().FindTableBySql(sql); + } + + //获取数据源sql等数据 + public DataTable GetMenuSQL(string MenuID) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string sql = @" + SELECT + isnull(ss.SqlTxt,'') SqlTxt , + isnull(ss.FormatSql,'') FormatSql , + isnull(SS.SysDataSourceFlag,'') SysDataSourceFlag, + isnull(ss.DbId,'') DbId , + isnull(ss.id,newid()) SourceID, + mm.f_id MenuID, + CASE WHEN ss.SysDataSourceFlag= '1' THEN 'connstr' + ELSE ( SELECT DBSourceName FROM sys_database db WHERE db.id = ss.dbid ) + END DBName , + case when ss.id is null then '0' else '1' end IsExistsDataSource, + isnull(STUFF((select',' + ColFiledName + from (SELECT DISTINCT ColFiledName FROM Sys_ColsOfGridReport + where ColSumFlag=1 and SourceId=ss.id + ) DD for xml path('')),1,1,'') ,'') footercols, + isnull(STUFF((select',' + ColFiledName + from (SELECT DISTINCT ColFiledName FROM Sys_ColsOfGridReport + where ColMerFlag=1 and SourceId=ss.id + ) DD for xml path('')),1,1,'') ,'') Mergercols, + isnull((select top 1 ColSumFlag from Sys_ColsOfGridReport where ColSumFlag=1 and SourceId=ss.id ),0) footerrow, + mm.F_FullName ReportName, + ss.TempName TempName, + ss.DbParameters, + isnull(ss.XCol,'') XCol + FROM Sys_SRM_Module mm + LEFT JOIN Sys_FormDataSource ss ON mm.f_id= ss.MenuID + + where mm.f_id='" + MenuID + @"' "; + return Repository().FindTableBySql(sql); + + } + + //获取列信息 + public string GetMenuCols(string SourceID) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string sql = @" SELECT * FROM dbo.Sys_ColsOfGridReport WHERE SourceID='" + SourceID + "' order by COrder "; + // ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag + DataTable dt = Repository().FindTableBySql(sql); + + if (dt != null && dt.Rows.Count > 0) + { + DataRow[] visidr = dt.Select("VisbleFlag=1", " COrder asc"); + if (visidr != null && visidr.Count() > 0) + { + Object[] colModel = new Object[visidr.Length + 1]; + for (int i = 0; i < visidr.Length; i++) + { + DataRow dr = visidr[i]; + + string ColCaption = dr["ColCaption"].ToString(); + string ColFiledName = dr["ColFiledName"].ToString(); + int DataType = Convert.ToInt32(dr["DataType"].ToString()); + string DataTypeStr = Enum.GetName(typeof(DataTypeEnum), DataType); + int ColWidth = Convert.ToInt32(dr["ColWidth"].ToString()); + int DeciamlNum = Convert.ToInt32(dr["DeciamlNum"].ToString()); + // bool VisbleFlag = !dr["VisbleFlag"].ToString().ToBool(); + bool SortFlag = dr["SortFlag"].ToString().ToBool(); + bool ColMerFlag = dr["ColMerFlag"].ToString().ToBool(); + string ReportName = dr["ReportName"].ToString(); + + + dynamic col = new System.Dynamic.ExpandoObject(); + col.label = ColCaption; + col.name = ColFiledName; + col.width = ColWidth; + col.align = "left"; + col.sortable = SortFlag; + col.ReportName = ReportName; + + switch (DataTypeStr) + { + + case "数值型": + var Formatoptions = new { decimalPlaces = DeciamlNum }; + col.formatter = "number"; + col.formatoptions = Formatoptions; + + + break; + case "字符型": + case "日期型": + case "布尔值": + + break; + + } + + if (ColMerFlag) + { + /////!!!!!!!???待做// + col.cellattr = "MerFunction"; + } + + colModel[i] = col; + + } + var collast = new { label = "", name = "", width = "20", align = "left" }; + colModel[visidr.Length] = collast; + return colModel.ToJson(); + } + + } + else + { + + } + return null; + + } + + //获取列项json 可见列版本 + #region 可见列版本 old + public string GetMenuColsNew20210204(string SourceID) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + + string sql = @" SELECT rr.*,(case when (select count(1) from Sys_FormatOfGridReport ff where ff.colid=rr.id)>0 then '1' else '0' end ) IsFormat, + (case when (select count(1) from Sys_FormColsVisible vv + where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"') + >0 then '1' else '0' end) RoleVisible + FROM dbo.Sys_ColsOfGridReport rr + left join Sys_FormDataSource ss on rr.SourceId=ss.id + WHERE SourceID='" + SourceID + "' order by COrder "; + // ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag + DataTable dt = Repository().FindTableBySql(sql); + + if (dt != null && dt.Rows.Count > 0) + { + DataRow[] visidr = dt.Select("VisbleFlag=1 and RoleVisible='1' ", " COrder asc"); + if (visidr != null && visidr.Count() > 0) + { + Object[] colModel = new Object[visidr.Length]; + for (int i = 0; i < visidr.Length; i++) + { + DataRow dr = visidr[i]; + + string ColCaption = dr["ColCaption"].ToString(); + string ColFiledName = dr["ColFiledName"].ToString(); + int DataType = Convert.ToInt32(dr["DataType"].ToString()); + string DataTypeStr = Enum.GetName(typeof(DataTypeEnum), DataType); + int ColWidth = Convert.ToInt32(dr["ColWidth"].ToString()); + int DeciamlNum = Convert.ToInt32(dr["DeciamlNum"].ToString()); + // bool VisbleFlag = !dr["VisbleFlag"].ToString().ToBool(); + bool SortFlag = dr["SortFlag"].ToString().ToBool(); + bool ColMerFlag = dr["ColMerFlag"].ToString().ToBool(); + string IsFormat = dr["IsFormat"].ToString(); + + + dynamic col = new System.Dynamic.ExpandoObject(); + + col.ColCaption = ColCaption; + col.ColFiledName = ColFiledName; + col.DataType = DataType; + col.DataTypeStr = DataTypeStr; + col.ColWidth = ColWidth; + col.DeciamlNum = DeciamlNum; + col.sortable = SortFlag; + col.ColMerFlag = ColMerFlag; + col.IsFormat = IsFormat; + colModel[i] = col; + + } + + return colModel.ToJson(); + } + + } + else + { + + } + return null; + + } + + #endregion + public string GetMenuColsNew(string SourceID) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + + string sql = @" SELECT rr.*,(case when (select count(1) from Sys_FormatOfGridReport ff where ff.colid=rr.id)>0 then '1' else '0' end ) IsFormat, + (case when (select count(1) from Sys_FormColsVisible vv + where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"') + >0 then '1' else '0' end) RoleVisible + FROM dbo.Sys_ColsOfGridReport rr + left join Sys_FormDataSource ss on rr.SourceId=ss.id + WHERE SourceID='" + SourceID + "' order by COrder "; + // ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag + DataTable dt = Repository().FindTableBySql(sql); + + if (dt != null && dt.Rows.Count > 0) + { + + Object[] colModel = new Object[dt.Rows.Count]; + for (int i = 0; i < dt.Rows.Count; i++) + { + DataRow dr = dt.Rows[i]; + + string ColCaption = dr["ColCaption"].ToString(); + string ColFiledName = dr["ColFiledName"].ToString(); + int DataType = Convert.ToInt32(dr["DataType"].ToString()); + string DataTypeStr = Enum.GetName(typeof(DataTypeEnum), DataType); + int ColWidth = Convert.ToInt32(dr["ColWidth"].ToString()); + int DeciamlNum = Convert.ToInt32(dr["DeciamlNum"].ToString()); + // bool VisbleFlag = !dr["VisbleFlag"].ToString().ToBool(); + bool SortFlag = dr["SortFlag"].ToString().ToBool(); + bool ColMerFlag = dr["ColMerFlag"].ToString().ToBool(); + string IsFormat = dr["IsFormat"].ToString(); + + + dynamic col = new System.Dynamic.ExpandoObject(); + + col.ColCaption = ColCaption; + col.ColFiledName = ColFiledName; + col.DataType = DataType; + col.DataTypeStr = DataTypeStr; + col.ColWidth = ColWidth; + col.DeciamlNum = DeciamlNum; + col.sortable = SortFlag; + col.ColMerFlag = ColMerFlag; + col.IsFormat = IsFormat; + colModel[i] = col; + + } + + return colModel.ToJson(); + } + + return null; + + } + + //获取不可见列 json + public string UnVisiblecols(string SourceID) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + + string sql = @" select distinct ColFiledName from ( SELECT rr.*,(case when (select count(1) from Sys_FormatOfGridReport ff where ff.colid=rr.id)>0 then '1' else '0' end ) IsFormat, + (case when (select count(1) from Sys_FormColsVisible vv + where vv.menuid=ss.menuid and rr.ColFiledName=vv.FieldName and vv.RoleId='" + oo.RoleId + @"') + >0 then '1' else '0' end) RoleVisible + FROM dbo.Sys_ColsOfGridReport rr + left join Sys_FormDataSource ss on rr.SourceId=ss.id + WHERE SourceID='" + SourceID + "' ) fff where VisbleFlag=0 or RoleVisible='0' "; + + DataTable dt = Repository().FindTableBySql(sql); + + if (dt != null && dt.Rows.Count > 0) + { + + Object[] colModel = new Object[dt.Rows.Count]; + for (int i = 0; i < dt.Rows.Count; i++) + { + DataRow dr = dt.Rows[i]; + + + string ColFiledName = dr["ColFiledName"].ToString(); + + + + dynamic col = new System.Dynamic.ExpandoObject(); + + + col.ColFiledName = ColFiledName; + + colModel[i] = col; + + } + + return colModel.ToJson(); + } + + return null; + + } + + + + //获取列个性化 + public DataTable Getformatcols(string SourceID) + { + + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string sql = @" select ff.*,cc.ColFiledName, + CASE + cc.datatype + WHEN 0 THEN '数值型' + WHEN 1 THEN '字符型' + WHEN 2 THEN '日期型' + WHEN 3 THEN '布尔值' + ELSE '' + END DataType + from Sys_FormatOfGridReport ff + left join Sys_ColsOfGridReport cc on cc.id=ff.colid + where cc.SourceID='" + SourceID + "' "; + + DataTable dt = Repository().FindTableBySql(sql); + return dt; + + + } + + + //提交数据源sql等信息 + public void SetDataSource(string SysDataSourceFlag, string FormatSql, string DbId, string MenuID, string DbParameters, string SourceID, string TempName, string XCol) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string sql = @" SELECT mm.f_id MenuID,ss.SqlTxt,SS.SysDataSourceFlag,ss.DbId ,isnull(ss.id,'') id--,oo.id otherSetid + FROM Sys_SRM_Module mm + left join Sys_FormDataSource ss on mm.f_id=ss.MenuID + -- left join Sys_FormDataSource_Other oo on oo.menuid=mm.f_id + where mm.f_id='" + MenuID + @"' "; + DataTable dt = Repository().FindTableBySql(sql); + string SqlTxt = ""; + string[] strs = DbParameters.Split(','); + + if (strs.Length == 0) + { + SqlTxt = FormatSql; + } + else + { + List pList = new List(); + foreach (string str in strs) + { + if (!string.IsNullOrEmpty(str)) + { + pList.Add(str); + } + } + if (pList.Count > 0) + { + SqlTxt = string.Format(FormatSql, pList.ToArray()); + } + else + { + SqlTxt = FormatSql; + } + } + + if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["id"].ToString())) + { + + string sqlupdate = @" update Sys_FormDataSource + set SqlTxt=N'" + ReSetStringTosql(SqlTxt) + @"', + SysDataSourceFlag='" + SysDataSourceFlag + @"', + DbId='" + DbId + @"', + FormatSql='" + ReSetStringTosql(FormatSql) + @"', + DbParameters='" + DbParameters + @"', + TempName='" + TempName + @"', + XCol='" + ReSetStringTosql(XCol) + @"' + WHERE ID='" + SourceID + @"' "; + StringBuilder sqlb = new StringBuilder(sqlupdate); + Repository().ExecuteBySql(sqlb); + } + else + { + + if (!string.IsNullOrEmpty(MenuID)) + { + string sqlupdate = @" insert into Sys_FormDataSource + (ID,MenuId,FilterButtonName,SysDataSourceFlag,DbId, + SqlTxt,FormatSql,DbParameters,AllowDbClickFlag,FormParameters, + DbClickMenuId,RowIndexWidth,ShowRowIndexFlag,ManyHeaderFlag,TempName, + XCol) + select '" + SourceID + @"','" + MenuID + @"','btnConfig','" + SysDataSourceFlag + @"','" + DbId + @"' + ,'" + ReSetStringTosql(SqlTxt) + @"','" + ReSetStringTosql(FormatSql) + @"','" + DbParameters + @"','0','' + ,'',35,'1','0' ,'" + TempName + @"', + '" + ReSetStringTosql(XCol) + @"' "; + StringBuilder sqlb = new StringBuilder(sqlupdate); + Repository().ExecuteBySql(sqlb); + } + else + { + throw new Exception("菜单信息异常:未找到菜单"); + } + } + + #region 设置默认看板信息 + //if (dt != null && dt.Rows.Count > 0 && string.IsNullOrEmpty(dt.Rows[0]["otherSetid"].ToString())) + //{ + // string sqlupdate = @" insert into Sys_FormDataSource_Other + // (ID,MenuId,PanelType,PanelGunDongTime,PanelGunDongNum, + // PanelRefreshTime,MUSER,MUSERName,MTIME,WorkPoint ) + // select newid(),'" + MenuID + @"','1',120,0 + // ,9000,'" + oo.UserCode + @"','" + oo.UserName + @"',getdate(),'"+oo.Location+@"' "; + // StringBuilder sqlb = new StringBuilder(sqlupdate); + // Repository().ExecuteBySql(sqlb); + //} + #endregion + //重新生成列信息 + // ReSetFormCols(MenuID); + + + } + + + public void SetDataSourceText(string SysDataSourceFlag, string FormatSql, string DbId, string DbParameters, string TempName, string XCol) + { + try + { + Pagination jqgridparam = new Pagination(); + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + string DBName = "connstr"; + if (SysDataSourceFlag != "1") + { + string sql = @" SELECT DBSourceName FROM sys_database db WHERE db.id = '" + DbId + @" ' "; + DataTable dt = Repository().FindTableBySql(sql); + if (dt != null && dt.Rows.Count > 0) + { + DBName = dt.Rows[0][0].ToString(); + } + else + { + throw new Exception("查找数据库异常"); + } + } + + string SqlTxt = ""; + string[] strs = DbParameters.Split(','); + + if (strs.Length == 0) + { + SqlTxt = FormatSql; + } + else + { + List pList = new List(); + foreach (string str in strs) + { + if (!string.IsNullOrEmpty(str)) + { + pList.Add(str); + } + } + if (pList.Count > 0) + { + SqlTxt = string.Format(FormatSql, pList.ToArray()); + } + else + { + SqlTxt = FormatSql; + } + } + + + if (SqlTxt.Contains("[AppConfig.WorkPointCode]")) + { + SqlTxt = SqlTxt.Replace("[AppConfig.WorkPointCode]", oo.Location); + } + if (SqlTxt.Contains("[AppConfig.UserId]")) + { + SqlTxt = SqlTxt.Replace("[AppConfig.UserId]", oo.UserId); + } + if (SqlTxt.Contains("[AppConfig.UserCode]")) + { + SqlTxt = SqlTxt.Replace("[AppConfig.UserCode]", oo.UserCode); + } + if (SqlTxt.Contains("[AppConfig.UserName]")) + { + SqlTxt = SqlTxt.Replace("[AppConfig.UserName]", oo.UserName); + } + if (!string.IsNullOrEmpty(TempName)) + { + SqlTxt = SqlTxt + " select * from " + TempName + " "; + } + SqlHelper.GetDataTableBySql_OtherConn(SqlTxt, DBName, ref jqgridparam, null); + if (!string.IsNullOrEmpty(TempName)) + { + SqlTxt = SqlTxt + " select * from " + TempName + " "; + } + if (!string.IsNullOrEmpty(XCol.Trim())) + { + SqlTxt = SqlTxt + " order by " + XCol.Trim() + " "; + } + + Repository().GetDataTableBySql_Other(SqlTxt, DBName, null); + } + catch (Exception ex) + { + throw new Exception(ex.ToString()); + + } + + + + } + + + + private string ReSetStringTosql(string sql) + { + sql = sql.Replace("'", "''"); + sql = sql.Replace("\r", "\r "); + sql = sql.Replace("\r\n", "\r\n "); + sql = sql.Replace("\n", "\n "); + return sql; + } + + public void ReSetCols(string MenuID) + { + ReSetFormCols(MenuID); + } + + public void ReSetFormCols(string MenuID) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + DataTable dt = GetMenuSQL(MenuID);//获取菜单配置信息 + if (dt != null && dt.Rows.Count > 0) + { + String SourceID = dt.Rows[0]["SourceID"].ToString(); + string SqlText = dt.Rows[0]["SqlTxt"].ToString(); + string DBName = dt.Rows[0]["DBName"].ToString(); + string TempName = dt.Rows[0]["TempName"].ToString(); + + //抓取现有列 + string sqlcol = @" SELECT * FROM Sys_ColsOfGridReport WHERE SourceID='" + SourceID + "' "; + // ColCaption ColFiledName DataType DefineFlag FunctionString DeciamlNum ColWidth ColMerFlag + //ColMerKeyFlag ColSumFlag HeaderId COrder VisbleFlag SortFlag + DataTable dtcol = Repository().FindTableBySql(sqlcol); + + //查询数据 + DataTable data = GetGridJsonText(SqlText, DBName, TempName); + if (data != null && data.Columns.Count > 0) + { + string InsertSQL = ""; + // DataRow drFirst = data.Rows[0];//首行 + for (int i = 0; i < data.Columns.Count; i++) + { + DataRow[] EXISRow = dtcol.Select("ColFiledName='" + data.Columns[i].ColumnName + "'"); + if (EXISRow == null || EXISRow.Count() == 0) + { + ColsOfGridClass CC = new ColsOfGridClass(); + Type dataType = data.Columns[i].DataType; + #region CC.dataType + if (dataType == typeof(int)) + { + CC.DataType = ((int)DataTypeEnum.数值型).ToString(); + } + if (dataType == typeof(Int16)) + { + CC.DataType = ((int)DataTypeEnum.数值型).ToString(); + } + if (dataType == typeof(Int32)) + { + CC.DataType = ((int)DataTypeEnum.数值型).ToString(); + } + if (dataType == typeof(Int64)) + { + CC.DataType = ((int)DataTypeEnum.数值型).ToString(); + } + if (dataType == typeof(float)) + { + CC.DataType = ((int)DataTypeEnum.数值型).ToString(); + } + + if (dataType == typeof(Decimal)) + { + CC.DataType = ((int)DataTypeEnum.数值型).ToString(); + } + if (dataType == typeof(decimal)) + { + CC.DataType = ((int)DataTypeEnum.数值型).ToString(); + } + if (dataType == typeof(Double)) + { + CC.DataType = ((int)DataTypeEnum.数值型).ToString(); + } + if (dataType == typeof(double)) + { + CC.DataType = ((int)DataTypeEnum.数值型).ToString(); + } + if (dataType == typeof(DateTime)) + { + CC.DataType = ((int)DataTypeEnum.日期型).ToString(); + } + if (dataType == typeof(string)) + { + CC.DataType = ((int)DataTypeEnum.字符型).ToString(); + } + if (dataType == typeof(String)) + { + CC.DataType = ((int)DataTypeEnum.字符型).ToString(); + } + if (dataType == typeof(Boolean)) + { + CC.DataType = ((int)DataTypeEnum.布尔值).ToString(); + } + if (dataType == typeof(bool)) + { + CC.DataType = ((int)DataTypeEnum.布尔值).ToString(); + + } + + #endregion + + CC.ColCaption = data.Columns[i].ColumnName; + CC.ColFiledName = data.Columns[i].ColumnName; + CC.DefineFlag = false; + CC.FunctionString = ""; + CC.DeciamlNum = 2; + CC.ColWidth = 90; + CC.ColMerFlag = false; + CC.ColMerKeyFlag = false; + CC.ColSumFlag = false; + CC.HeaderId = ""; + CC.COrder = i + 1; + CC.VisbleFlag = true; + CC.SortFlag = false; + + InsertSQL += @" insert into Sys_ColsOfGridReport + (Id, SourceID , ColCaption, ColFiledName, DataType, + DefineFlag, FunctionString, DeciamlNum, ColWidth, ColMerFlag, + ColMerKeyFlag, ColSumFlag, HeaderId, COrder, VisbleFlag, + SortFlag) + select newid(),'" + SourceID + @"','" + CC.ColCaption + @"','" + CC.ColFiledName + @"','" + CC.DataType + @"', + " + BoolToInt(CC.DefineFlag) + @",'" + ReSetStringTosql(CC.FunctionString) + @"'," + CC.DeciamlNum + @"," + CC.ColWidth + @"," + BoolToInt(CC.ColMerFlag) + @", + " + BoolToInt(CC.ColMerKeyFlag) + @"," + BoolToInt(CC.ColSumFlag) + @",'" + CC.HeaderId + @"','" + CC.COrder.ToString() + @"'," + BoolToInt(CC.VisbleFlag) + @", + " + BoolToInt(CC.SortFlag) + @" + where NOT EXISTS(SELECT 1 FROM Sys_ColsOfGridReport WHERE SourceID='" + SourceID + @"' AND ColCaption='" + CC.ColCaption + @"' ) +"; + } + + + } + + StringBuilder sqlb = new StringBuilder(InsertSQL); + Repository().ExecuteBySql(sqlb); + } + + } + } + + private int BoolToInt(bool flag) + { + if (flag) + { + return 1; + } + return 0; + } + + public DataTable GetCondition(string SourceID) + { + string sql = @" SELECT con.id IDStr, '0' IsNew, CSortSeq 排序,NotNullFlag 必填, CCaption 条件名称, CFiledName 字段名称, CIndex 替代符号, + CDefaultLogStirng 默认逻辑符号, CDataType 数据类型,CDefaultLogStirng 默认逻辑符号Data, CDataType 数据类型Data, + CDefaultValue 默认值 ,CSelectFlag 参照选择, CSelectSqlTxt 参照语句, CSelectSourceId 其他数据源, + SysDataSourceFlag 本系统数据源, ReturnCol 返回字段,CSelectSourceId 其他数据源Data + from Sys_FormFilterCondition con + where con.SourceID='" + SourceID + @"' order by CSortSeq"; + return Repository().FindTableBySql(sql); + } + + + public void SetCondition(string SourceID, string List_Condition) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + if (!string.IsNullOrEmpty(List_Condition) && List_Condition != "[]") + { + ConditionClass[] list = JsonConvert.DeserializeObject(List_Condition); + if (list != null) + { + string sql = ""; + string sqldel = ""; + string sqldel2 = ""; + string sqlinsert = ""; + string sqlupdate = ""; + + //@" delete from Sys_FormFilterCondition where SourceID='" + SourceID + @"' "; + + foreach (ConditionClass item in list) + { + if (item.ID == "")//insert + { + sqlinsert += @" INSERT INTO [Sys_FormFilterCondition] + ([ID],[SourceID] ,[NotNullFlag],[CCaption],[CFiledName], + [CIndex],[CLogString],[CDefaultLogStirng],[CDataType],[CDefaultValue], + [CSelectFlag],[CSelectSqlTxt],[CSelectSourceID],[SysDataSourceFlag],[ReturnCol], + [CSortSeq] ) + select newid(),'" + SourceID + @"'," + item.NotNullFlag + @",'" + item.CCaption + @"','" + ReSetStringTosql(item.CFiledName) + @"', + '" + item.CIndex + @"','" + item.CLogString + @"','" + item.CDefaultLogStirng + @"','" + item.CDataType + @"','" + item.CDefaultValue + @"', + " + item.CSelectFlag + @",'" + ReSetStringTosql(item.CSelectSqlTxt) + @"','" + item.CSelectSourceId + @"'," + item.SysDataSourceFlag + @",'" + item.ReturnCol + @"', + " + item.CSortSeq + @" "; + } + else//update + { + sqlupdate += @" update [Sys_FormFilterCondition] + set + [NotNullFlag]=" + item.NotNullFlag + @", + [CCaption]='" + item.CCaption + @"', + [CFiledName]='" + ReSetStringTosql(item.CFiledName) + @"', + [CIndex]='" + item.CIndex + @"', + [CLogString]='" + item.CLogString + @"', + [CDefaultLogStirng]='" + item.CDefaultLogStirng + @"', + [CDataType]='" + item.CDataType + @"', + [CDefaultValue]='" + item.CDefaultValue + @"', + [CSelectFlag]=" + item.CSelectFlag + @", + [CSelectSqlTxt]='" + ReSetStringTosql(item.CSelectSqlTxt) + @"', + [CSelectSourceID]='" + item.CSelectSourceId + @"', + [SysDataSourceFlag]=" + item.SysDataSourceFlag + @", + [ReturnCol]='" + item.ReturnCol + @"', + [CSortSeq]=" + item.CSortSeq + @" + where id='" + item.ID + "' and SourceID='" + SourceID + @"' + "; + + sqldel2 += " and FilterID!='" + item.ID + "' "; + sqldel += " and ID!='" + item.ID + "' "; + + } + + } + + sql = @" delete from Sys_FormFilterCondition where SourceID = '" + SourceID + @"' " + + sqldel + sqlupdate + sqlinsert; + sql += " delete from Sys_ColsDefaultRecord where SourceID = '" + SourceID + @"' " + sqldel2; + StringBuilder sqlb = new StringBuilder(sql); + Repository().ExecuteBySql(sqlb); + } + } + else + { + string sql = @" delete from Sys_FormFilterCondition where SourceID='" + SourceID + @"' + delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"'"; + StringBuilder sqlb = new StringBuilder(sql); + Repository().ExecuteBySql(sqlb); + } + + } + + + + public void SetDefaultRecord(string SourceID, string List_Record) + { + + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + if (!string.IsNullOrEmpty(List_Record) && List_Record != "[]") + { + DefaultRecordClass[] list = JsonConvert.DeserializeObject(List_Record); + if (list != null) + { + string sql = "delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"' "; + foreach (DefaultRecordClass item in list) + { + sql += @" INSERT INTO [dbo].[Sys_ColsDefaultRecord] + ([Id],[SourceId],[FilterID],[F_Account],[CCaption], + [CDefaultLogStirng],[CDefaultValue1],[CDefaultValue2],[WorkPoint],[MUSER], + [MUSERName],[MTIME],[EATTRIBUTE1],[EATTRIBUTE2]) + select + newid(), + '" + SourceID + @"', + '" + item.FilterID + @"', + '" + oo.UserCode + @"', + '" + ReSetStringTosql(item.CCaption) + @"', + + '" + item.CDefaultLogStirng + @"', + '" + ReSetStringTosql(item.CDefaultValue1) + @"', + '" + ReSetStringTosql(item.CDefaultValue2) + @"', + '" + oo.Location + @"', + '" + oo.UserCode + @"', + + '" + oo.UserName + @"', + getdate(), + null, + null + "; + } + StringBuilder sqlb = new StringBuilder(sql); + Repository().ExecuteBySql(sqlb); + + } + } + else + { + string sql = @" delete from Sys_ColsDefaultRecord where SourceID='" + SourceID + @"' "; + StringBuilder sqlb = new StringBuilder(sql); + Repository().ExecuteBySql(sqlb); + } + } + + public DataTable GetCols(string SourceID) + { + string sql = @" SELECT Id IDStr, SourceID SourceID , ColCaption , ColFiledName , DataType , + DefineFlag , FunctionString , DeciamlNum , ColWidth , ColMerFlag , + ColMerKeyFlag , ColSumFlag , HeaderId , COrder , VisbleFlag , + SortFlag , ColCaption 显示名称, ColFiledName 字段名称, DataType 数据类型, DefineFlag 自定义项, + FunctionString 自定义公式, DeciamlNum 小数点位数, ColWidth 字段宽度, ColMerFlag 合并相同项, ColMerKeyFlag as [合并相同项Key], + ColSumFlag 汇总, HeaderId 从属表头, COrder 显示顺序, VisbleFlag 显示, SortFlag 允许排序 + from Sys_ColsOfGridReport + where SourceID='" + SourceID + @"' order by COrder "; + return Repository().FindTableBySql(sql); + } + public DataTable GetGridFormat(string ColId) + { + string sql = @" SELECT * from Sys_formatofgridreport where ColId='" + ColId + @"' "; + return Repository().FindTableBySql(sql); + } + + + public void SetCols(string SourceID, string List_Cols) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + if (!string.IsNullOrEmpty(List_Cols) && List_Cols != "[]") + { + ColsStrOfGridClass[] list = JsonConvert.DeserializeObject(List_Cols); + if (list != null) + { + string sql = ""; + string del_sql = ""; + List IDList = new List(); + string sql_s = @" select id from Sys_ColsOfGridReport where SourceID='" + SourceID + @"' "; + DataTable dtid = Repository().FindTableBySql(sql_s); + if (dtid != null && dtid.Rows.Count > 0) + { + foreach (DataRow dr in dtid.Rows) + { + IDList.Add(dr["id"].ToString()); + } + } + foreach (ColsStrOfGridClass item in list) + { + if (string.IsNullOrEmpty(item.DefineFlag)) + { + item.DefineFlag = "0"; + } + if (string.IsNullOrEmpty(item.DeciamlNum)) + { + item.DeciamlNum = "2"; + } + if (string.IsNullOrEmpty(item.ColWidth)) + { + item.ColWidth = "90"; + } + if (string.IsNullOrEmpty(item.ColMerFlag)) + { + item.ColMerFlag = "0"; + } + if (string.IsNullOrEmpty(item.ColMerKeyFlag)) + { + item.ColMerKeyFlag = "0"; + } + if (string.IsNullOrEmpty(item.ColSumFlag)) + { + item.ColSumFlag = "0"; + } + if (string.IsNullOrEmpty(item.VisbleFlag)) + { + item.VisbleFlag = "1"; + } + if (string.IsNullOrEmpty(item.SortFlag)) + { + item.SortFlag = "0"; + } + if (string.IsNullOrEmpty(item.COrder)) + { + item.COrder = "0"; + } + + if (IDList.Contains(item.Id)) + { + del_sql += " and id!='" + item.Id + "' "; + sql += @" update [Sys_ColsOfGridReport] + set ColCaption='" + item.ColCaption + @"', + ColFiledName ='" + item.ColFiledName + @"', + DataType ='" + item.DataType + @"', + DefineFlag=" + item.DefineFlag + @", + FunctionString ='" + ReSetStringTosql(item.FunctionString) + @"', + DeciamlNum =" + item.DeciamlNum + @", + ColWidth =" + item.ColWidth + @", + ColMerFlag=" + item.ColMerFlag + @", + ColMerKeyFlag =" + item.ColMerKeyFlag + @", + ColSumFlag =" + item.ColSumFlag + @", + HeaderId ='" + item.HeaderId + @"', + COrder =" + item.COrder + @", + VisbleFlag =" + item.VisbleFlag + @", + SortFlag=" + item.SortFlag + @" + where SourceID='" + SourceID + @"' and ID='" + item.Id + @"' "; + + } + else + { + + sql += @" INSERT INTO [Sys_ColsOfGridReport] + ([ID],[SourceID], ColCaption , ColFiledName , DataType , + DefineFlag , FunctionString , DeciamlNum , ColWidth , ColMerFlag , + ColMerKeyFlag , ColSumFlag , HeaderId , COrder , VisbleFlag , + SortFlag) + select newid(),'" + SourceID + @"','" + item.ColCaption + @"','" + item.ColFiledName + @"','" + item.DataType + @"', + " + item.DefineFlag + @",'" + ReSetStringTosql(item.FunctionString) + @"'," + item.DeciamlNum + @"," + item.ColWidth + @"," + item.ColMerFlag + @", + " + item.ColMerKeyFlag + @"," + item.ColSumFlag + @",'" + item.HeaderId + @"'," + item.COrder + @"," + item.VisbleFlag + @", + " + item.SortFlag + @" "; + } + } + if (!string.IsNullOrEmpty(del_sql)) + { + del_sql = @" + ----删除sys_ColsOfGridReport 先删对应的Sys_formatofgridreport + delete from Sys_formatofgridreport + where ColId in(select id from sys_ColsOfGridReport where SourceID='" + SourceID + @"' " + del_sql + @" ) + + delete from sys_ColsOfGridReport where SourceID='" + SourceID + @"' " + del_sql; + } + sql = del_sql + sql; + StringBuilder sqlb = new StringBuilder(sql); + Repository().ExecuteBySql(sqlb); + } + else + { + string sql_D = @" DELETE from Sys_ColsOfGridReport where SourceID='" + SourceID + @"' "; + StringBuilder sqlb = new StringBuilder(sql_D); + Repository().ExecuteBySql(sqlb); + } + } + + } + + + public void SetGridFormat(string ColId, string List_GridFormat) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + if (!string.IsNullOrEmpty(List_GridFormat) && List_GridFormat != "[]") + { + GridFormatClass[] list = JsonConvert.DeserializeObject(List_GridFormat); + if (list != null) + { + string sql = @" delete from Sys_formatofgridreport where ColId='" + ColId + @"' "; + foreach (GridFormatClass item in list) + { + + sql += @" INSERT INTO [Sys_formatofgridreport] + (ID,ColId,LogStr,SValue,DValue,Color,AllRowFlag) + select newid(),'" + ColId + @"','" + item.LogStr + @"','" + item.SValue + @"','" + item.DValue + @"', + '" + item.Color + @"', " + item.AllRowFlag + @" "; + } + StringBuilder sqlb = new StringBuilder(sql); + Repository().ExecuteBySql(sqlb); + } + } + else + { + string sql = @" delete from Sys_formatofgridreport where ColId='" + ColId + @"' "; + StringBuilder sqlb = new StringBuilder(sql); + Repository().ExecuteBySql(sqlb); + } + + } + + + public DataTable GetFilter(string SourceID) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + // 替代符号, 字段名称,数据类型,默认逻辑符号,默认值,条件名称,逻辑符号,起始值,结束值 + string sql = @" + SELECT con.id FilterID, con.NotNullFlag 必填, con.CCaption 条件名称, con.CFiledName 字段名称, con.CIndex 替代符号, + isnull(rr.CDefaultLogStirng,con.CDefaultLogStirng) 默认逻辑符号, con.CDataType 数据类型, isnull(rr.CDefaultValue1,con.CDefaultValue) 默认值 ,'' 逻辑符号, + '' 起始值,'' 结束值,isnull(rr.CDefaultValue2,'') 默认值2,con.CSelectFlag 参照选择,con.ReturnCol 返回字段 + from Sys_FormFilterCondition con + left join Sys_ColsDefaultRecord rr on rr.FilterID=con.id and rr.F_Account='" + oo.UserCode + @"' and con.SourceID=rr.SourceID + where con.SourceID='" + SourceID + @"' order by con.CSortSeq"; + return Repository().FindTableBySql(sql); + } + + + + // 获取栏位的栏位筛选条件数据 + public DataTable GetColsSelectData(string SourceID, string ColsName, string InputKey) + { + + string sql = @" SELECT top 1 CSelectSqlTxt , + CASE WHEN SysDataSourceFlag= '1' THEN 'connstr' + ELSE ( SELECT DBSourceName FROM sys_database db WHERE db.id = CSelectSourceID ) + END DBName + from Sys_FormFilterCondition + where SourceID='" + SourceID + @"' and CCaption =N'" + ColsName + "' "; + DataTable dt = Repository().FindTableBySql(sql); + if (dt != null && dt.Rows.Count > 0) + { + string sqlcols = dt.Rows[0]["CSelectSqlTxt"].ToString(); + string DBName = dt.Rows[0]["DBName"].ToString(); + sqlcols = string.Format(sqlcols, InputKey); + DataTable dtcols = SqlHelper.GetDataTableBySql_OtherConn(sqlcols, DBName, null); + return dtcols; + } + return null; + } + + + public string GetColsSelectCols(DataTable dt) + { + if (dt != null && dt.Columns.Count > 0) + { + Object[] colModel = new Object[dt.Columns.Count + 1]; + for (int i = 0; i < dt.Columns.Count; i++) + { + string ColCaption = dt.Columns[i].ColumnName; + string ColFiledName = dt.Columns[i].ColumnName; + + var col = new Object(); + col = new + { + label = ColCaption, + name = ColFiledName, + align = "left", + }; + + colModel[i] = col; + + } + var collast = new { label = "", name = "", width = "20", align = "left" }; + colModel[dt.Columns.Count] = collast; + return colModel.ToJson(); + } + return ""; + + } + + public void ClearAll(string MenuID) + { + + string sql = @" DECLARE @SourceId VARCHAR (100) + SELECT @SourceId=id FROM Sys_FormDataSource WHERE menuid='" + MenuID + @"' + DELETE FROM Sys_formatofgridreport WHERE colid IN (SELECT id FROM Sys_ColsOfGridReport WHERE SourceId=@SourceId) + DELETE FROM Sys_HeaderOfGridReport WHERE Sourceid=@SourceId + DELETE FROM Sys_FormFilterCondition WHERE SourceId=@SourceId + DELETE FROM Sys_ColsOfGridReport WHERE SourceId=@SourceId + delete from Sys_FormDataSource WHERE id=@SourceId + delete from Sys_ColsDefaultRecord where SourceId=@SourceId + -- delete from Sys_FormDataSource_Other where menuid='" + MenuID + @"' + "; + + StringBuilder sqlb = new StringBuilder(sql); + Repository().ExecuteBySql(sqlb); + + } + + + public DataTable GetColsVisible(string MenuID, string Roles, string Cols, ref Pagination jqgridparam) + { + string sql = @" select cc.ID,FieldName 列字段, mm.f_fullname 角色 from Sys_FormColsVisible cc + left join Sys_SRM_role mm on mm.f_id =cc.RoleId where cc.MenuId='" + MenuID + "' "; + if (!string.IsNullOrEmpty(Roles.Trim())) + { + sql += " and cc.RoleId in('" + Roles.Replace(",", "','") + "') "; + } + if (!string.IsNullOrEmpty(Cols.Trim())) + { + sql += " and FieldName in('" + Cols.Replace(",", "','") + "') "; + } + DataTable dt = Repository().FindTablePageBySql(sql, ref jqgridparam); + return dt; + } + + public DataTable GetRoles() + { + string sql = @" select distinct mm.f_fullname Roles,f_id RolesID from Sys_SRM_role mm order by mm.f_fullname"; + DataTable dt = Repository().FindTableBySql(sql); + return dt; + } + + public DataTable GetColsFiledName(string MenuID) + { + string sql = @" select distinct cc.ColFiledName FiledName from Sys_SRM_Module mm + left join Sys_FormDataSource ss on ss.menuid=mm.f_id + left join Sys_ColsOfGridReport cc on cc.SourceId=ss.id and cc.visbleflag=1 + where mm.f_id='" + MenuID + @"' + and isnull(cc.ColFiledName ,'')!='' order by cc.ColFiledName"; + DataTable dt = Repository().FindTableBySql(sql); + return dt; + } + + + public void SetColsVisibleALL(string Cols, string IsCommon, string MenuID) + { + if (IsCommon == "Y")//通用报表 + { + string sql = @" delete from Sys_FormColsVisible where MenuId='" + MenuID + @"' + insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint) + select newid(),'" + MenuID + @"',RoleId,FiledName,1,'001' + from ( + select distinct cc.ColFiledName FiledName ,rr.f_fullname,rr.f_id RoleId + from Sys_SRM_Module mm + left join Sys_FormDataSource ss on ss.menuid=mm.f_id + left join Sys_ColsOfGridReport cc on cc.SourceId=ss.id and cc.visbleflag=1 + left join Sys_SRM_role rr on 1=1 + where 1=1 + and mm.f_id='" + MenuID + @"' + and isnull(cc.ColFiledName ,'')!='' + ) fff + "; + StringBuilder sqlb = new StringBuilder(sql); + Repository().ExecuteBySql(sqlb); + } + else//非通用报表 + { + if (!string.IsNullOrEmpty(Cols)) + { + string sql2 = @" delete from Sys_FormColsVisible where MenuId='" + MenuID + @"' + "; + + sql2 += @" insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint) + select newid(),'" + MenuID + @"',RoleId,FiledName,1,'001' + from ( + select distinct DDD.FiledName , rr.f_id RoleId + from (select distinct cc.items FiledName + from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc + where isnull(cc.items,'')!='' ) DDD + left join Sys_SRM_role rr on 1=1 + + ) fff + "; + + + + StringBuilder sqlb2 = new StringBuilder(sql2); + Repository().ExecuteBySql(sqlb2); + } + + } + + } + + public void SetColsVisibleAdd(string Cols, string Roles, string MenuID) + { + + if (!string.IsNullOrEmpty(Cols.Trim()) && !string.IsNullOrEmpty(Roles.Trim())) + { + string sql2 = @" + insert into Sys_FormColsVisible(ID ,MenuId ,RoleId ,FieldName, VisibleFlag, WorkPoint) + select newid(),'" + MenuID + @"',rr.items RoleId,cc.items FiledName,1,'001' + from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc + left join [dbo].[splitl]('" + Roles.Trim() + @"',',') rr on 1=1 + where isnull(cc.items,'')!='' + and isnull(rr.items,'')!='' + "; + + StringBuilder sqlb2 = new StringBuilder(sql2); + Repository().ExecuteBySql(sqlb2); + } + + } + + + public void SetColsVisibleDel(string MenuID, string IDList) + { + + if (!string.IsNullOrEmpty(IDList)) + { + string sql2 = @" + delete from Sys_FormColsVisible where MenuId='" + MenuID + @"' + and id in('" + IDList.Replace(",", "','") + @"') + "; + + StringBuilder sqlb2 = new StringBuilder(sql2); + Repository().ExecuteBySql(sqlb2); + } + + } + + + public DataTable GetHiddenCols(string MenuID, string Cols) + { + OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); + // 栏位权限控制 + string sql2 = @" + select distinct cc.items Col from [dbo].[splitl]('" + Cols.Trim() + @"',',') cc + left join Sys_FormColsVisible vv on cc.items=FieldName and vv.menuid='" + MenuID + @"' and vv.RoleId='" + oo.RoleId + @"' + where vv.id is null + + "; + DataTable dtcol = Repository().FindTableBySql(sql2); + + return dtcol; + + } + + } + +} diff --git a/NFine.Application/SystemManage/CustomerApp.cs b/NFine.Application/SystemManage/CustomerApp.cs new file mode 100644 index 0000000..3f533aa --- /dev/null +++ b/NFine.Application/SystemManage/CustomerApp.cs @@ -0,0 +1,66 @@ +using NFine.Code; +using NFine.Domain.Entity.SystemManage; +using NFine.Domain.IRepository.SystemManage; +using NFine.Repository.SystemManage; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace NFine.Application.SystemManage +{ + public class CustomerApp + { + private ICustomerRepository service = new CustomerRepository(); + + public List GetList() + { + return service.IQueryable().OrderBy(t => t.F_CreatorTime).ToList(); + } + + public List GetList(Pagination pagination, string keyword) + { + var expression = ExtLinq.True(); + if (!string.IsNullOrEmpty(keyword)) + { + expression = expression.And(t => t.F_CusCode.Contains(keyword)); + expression = expression.Or(t => t.F_CusName.Contains(keyword)); + } + expression = expression.And(t => t.F_CusCode != "admin"); + return service.FindList(expression, pagination); + } + + public List GetListCus() + { + var expression = ExtLinq.True(); + return service.IQueryable(expression).OrderBy(t => t.F_CusCode).ToList(); + } + + public CustomerEntity GetForm(string keyValue) + { + return service.FindEntity(keyValue); + } + + public void DeleteForm(string keyValue) + { + service.DeleteForm(keyValue); + } + + public void SubmitForm(CustomerEntity cusEntity, string keyValue) + { + if (!string.IsNullOrEmpty(keyValue)) + { + cusEntity.Modify(keyValue); + } + else + { + cusEntity.Create(); + } + service.SubmitForm(cusEntity, keyValue); + } + + public void UpdateForm(CustomerEntity cusEntity) + { + service.Update(cusEntity); + } + } +} diff --git a/NFine.Application/SystemManage/DutyApp.cs b/NFine.Application/SystemManage/DutyApp.cs new file mode 100644 index 0000000..c7adba9 --- /dev/null +++ b/NFine.Application/SystemManage/DutyApp.cs @@ -0,0 +1,51 @@ +using NFine.Code; +using NFine.Domain.Entity.SystemManage; +using NFine.Domain.IRepository.SystemManage; +using NFine.Repository.SystemManage; +using System.Collections.Generic; +using System.Linq; + +namespace NFine.Application.SystemManage +{ + public class DutyApp + { + private IRoleRepository service = new RoleRepository(); + + public List GetList(string keyword = "") + { + var expression = ExtLinq.True(); + if (!string.IsNullOrEmpty(keyword)) + { + expression = expression.And(t => t.F_FullName.Contains(keyword)); + expression = expression.Or(t => t.F_EnCode.Contains(keyword)); + } + expression = expression.And(t => t.F_Category == 2); + return service.IQueryable(expression).OrderBy(t => t.F_SortCode).ToList(); + } + + public RoleEntity GetForm(string keyValue) + { + return service.FindEntity(keyValue); + } + + public void DeleteForm(string keyValue) + { + service.Delete(t => t.F_Id == keyValue); + } + + public void SubmitForm(RoleEntity roleEntity, string keyValue) + { + if (!string.IsNullOrEmpty(keyValue)) + { + roleEntity.Modify(keyValue); + service.Update(roleEntity); + } + else + { + roleEntity.Create(); + roleEntity.F_Category = 2; + service.Insert(roleEntity); + } + } + } +} diff --git a/NFine.Application/SystemManage/ItemsApp.cs b/NFine.Application/SystemManage/ItemsApp.cs new file mode 100644 index 0000000..8525280 --- /dev/null +++ b/NFine.Application/SystemManage/ItemsApp.cs @@ -0,0 +1,58 @@ +using NFine.Domain.Entity.SystemManage; +using NFine.Domain.IRepository.SystemManage; +using NFine.Repository.SystemManage; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; + +namespace NFine.Application.SystemManage +{ + public class ItemsApp + { + private IItemsRepository service = new ItemsRepository(); + + public List GetList() + { + return service.IQueryable().ToList(); + } + + public ItemsEntity GetForm(string keyValue) + { + return service.FindEntity(keyValue); + } + + public ItemsEntity GetForm2(string keyValue) + { + Expression> predicate = null; + predicate = t => t.F_FullName == keyValue; + return service.FindEntity(predicate); + } + + public void DeleteForm(string keyValue) + { + if (service.IQueryable().Count(t => t.F_ParentId.Equals(keyValue)) > 0) + { + throw new Exception("删除失败!操作的对象包含了下级数据。"); + } + else + { + service.Delete(t => t.F_Id == keyValue); + } + } + + public void SubmitForm(ItemsEntity itemsEntity, string keyValue) + { + if (!string.IsNullOrEmpty(keyValue)) + { + itemsEntity.Modify(keyValue); + service.Update(itemsEntity); + } + else + { + itemsEntity.Create(); + service.Insert(itemsEntity); + } + } + } +} diff --git a/NFine.Application/SystemManage/ItemsDetailApp.cs b/NFine.Application/SystemManage/ItemsDetailApp.cs new file mode 100644 index 0000000..f01313e --- /dev/null +++ b/NFine.Application/SystemManage/ItemsDetailApp.cs @@ -0,0 +1,68 @@ +using NFine.Code; +using NFine.Domain.Entity.SystemManage; +using NFine.Domain.IRepository.SystemManage; +using NFine.Repository.SystemManage; +using System.Collections.Generic; +using System.Linq; + +namespace NFine.Application.SystemManage +{ + public class ItemsDetailApp + { + private IItemsDetailRepository service = new ItemsDetailRepository(); + + public List GetList(string itemId = "", string keyword = "") + { + var expression = ExtLinq.True(); + if (!string.IsNullOrEmpty(itemId)) + { + expression = expression.And(t => t.F_ItemId == itemId); + } + if (!string.IsNullOrEmpty(keyword)) + { + expression = expression.And(t => t.F_ItemName.Contains(keyword)); + expression = expression.Or(t => t.F_ItemCode.Contains(keyword)); + } + return service.IQueryable(expression).OrderBy(t => t.F_SortCode).ToList(); + } + + public List GetItemList(string enCode) + { + return service.GetItemList(enCode); + } + + public List GetItemListWH(string itemID) + { + var expression = ExtLinq.True(); + if (!string.IsNullOrEmpty(itemID)) + { + expression = expression.And(t => t.F_ItemId == itemID); + } + return service.IQueryable(expression).OrderBy(t => t.F_SortCode).ToList(); + } + + public ItemsDetailEntity GetForm(string keyValue) + { + return service.FindEntity(keyValue); + } + + public void DeleteForm(string keyValue) + { + service.Delete(t => t.F_Id == keyValue); + } + + public void SubmitForm(ItemsDetailEntity itemsDetailEntity, string keyValue) + { + if (!string.IsNullOrEmpty(keyValue)) + { + itemsDetailEntity.Modify(keyValue); + service.Update(itemsDetailEntity); + } + else + { + itemsDetailEntity.Create(); + service.Insert(itemsDetailEntity); + } + } + } +}