/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/production/catalog(old).aspx.vb
1 322 строки
68 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
Imports System.Data Imports System.Data.SqlClient Imports System.IO Partial Class Xml_viewTable Inherits System.Web.UI.Page Private sqlf As New sharedClasses.dbFunctions.SqlFunctions Private a As sharedClasses.Auth.auth 'Public dt As DataTable Public dr_w As DataRowCollection Public dr_w1 As DataRowCollection Public dt_plan As Data.DataTable Public dr_plan As DataRowCollection Public dt_gmes As Data.DataTable Public dr_gmes As DataRowCollection Public dt_today As Data.DataTable Public dr_today As DataRowCollection Dim sql_sop As New StringBuilder Dim sql_gmes As New StringBuilder Dim sql As New StringBuilder Public sop_flag As Boolean Public gmes_flag As Boolean Public today_flag As Boolean Private Sub authorize(mode As String) a = New sharedClasses.Auth.auth(mode, IIf(Request.UserHostAddress = "::1", "106.109.72.69", Request.UserHostAddress)) End Sub Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load Dim dt_w As DataTable Dim dt_w1 As DataTable 'В dt_w1 получаем список всех моделей, которые БУДУТ производиться на следующей неделе по SOP 'dt = sqlf.GetData("select distinct material from [UserModules].[user].[SOP_for_TT_CAPA] where (W_1 is not null and W_1 <> 0) or (W is not null and W <> 0)") dt_w1 = sqlf.GetData("select distinct material from [UserModules].[user].[SOP_for_TT_CAPA] where W_1 is not null and W_1 <> 0") 'Создаём первичный ключ, чтобы потом пользоваться им для поиска Dim primaryKey(1) As DataColumn primaryKey(0) = dt_w1.Columns(0) dt_w1.PrimaryKey = primaryKey 'Коллекцию рядов из dt кладём в dr. В ней будем искать dr_w1 = dt_w1.Rows 'В dt_w получаем список всех моделей, которые БУДУТ производиться на этой неделе по SOP dt_w = sqlf.GetData("select distinct material from [UserModules].[user].[SOP_for_TT_CAPA] where W is not null and W <> 0") 'Создаём первичный ключ, чтобы потом пользоваться им для поиска 'Dim primaryKey(1) As DataColumn primaryKey(0) = dt_w.Columns(0) dt_w.PrimaryKey = primaryKey 'Коллекцию рядов из dt кладём в dr. В ней будем искать dr_w = dt_w.Rows 'В dt_today получаем список всех id строк, которые были изменены сегодня dt_today = sqlf.GetData("select distinct change_id from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] where cast(change_date as date) = cast(getdate() as date)") 'Создаём первичный ключ, чтобы потом пользоваться им для поиска primaryKey(0) = dt_today.Columns(0) dt_today.PrimaryKey = primaryKey 'Коллекцию рядов из dt кладём в dr. В ней будем искать dr_today = dt_today.Rows sql_sop.Clear() sql_sop.AppendLine("select ") sql_sop.AppendLine("model ") sql_sop.AppendLine(",isnull(cast([M01] as varchar), '') as [M01] ") sql_sop.AppendLine(",isnull(cast([M03] as varchar), '') as [M03] ") sql_sop.AppendLine(",isnull(cast([M04] as varchar), '') as [M04] ") sql_sop.AppendLine(",isnull(cast([M05] as varchar), '') as [M05] ") sql_sop.AppendLine(",isnull(cast([M07] as varchar), '') as [M07] ") sql_sop.AppendLine(",isnull(cast([M08] as varchar), '') as [M08] ") sql_sop.AppendLine("from ") sql_sop.AppendLine("( ") sql_sop.AppendLine("select ") sql_sop.AppendLine("model as Model ") sql_sop.AppendLine(",cast(pc.TT as decimal(20,2)) as [Planner's TackTime] ") sql_sop.AppendLine(",LINE ") sql_sop.AppendLine("from [UserModules].[user].[PLANNING_TT] as PC ") sql_sop.AppendLine("where cast(CREATE_DATE as date) = (select max(cast(create_date as date)) from [UserModules].[user].[PLANNING_TT]) ") sql_sop.AppendLine(") as SourceTable ") sql_sop.AppendLine("pivot ") sql_sop.AppendLine("( ") sql_sop.AppendLine("max([Planner's TackTime]) ") sql_sop.AppendLine("for Line in ([M01],[M03],[M04],[M05],[M07],[M08]) ") sql_sop.AppendLine(") as PivotTable ") 'В таблицу dt_plan получаем список всего, что запланировал проконтрол. Потом по ней будем сравнивать значения ТТ со справочником и подсвечивать расхождения dt_plan = sqlf.GetData(sql_sop.ToString) 'Создаём первичный ключ, чтобы потом пользоваться им для поиска Dim primaryKey_plan(1) As DataColumn primaryKey_plan(0) = dt_plan.Columns(0) dt_plan.PrimaryKey = primaryKey_plan 'Коллекцию рядов из dt_plan кладём в dr_plan. В ней будем искать dr_plan = dt_plan.Rows sql_gmes.Clear() sql_gmes.AppendLine("select ") sql_gmes.AppendLine("model ") sql_gmes.AppendLine(",cast([M01] as decimal(20,1)) as [M01] ") sql_gmes.AppendLine(",cast([M03] as decimal(20,1)) as [M03] ") sql_gmes.AppendLine(",cast([M04] as decimal(20,1)) as [M04] ") sql_gmes.AppendLine(",cast([M05] as decimal(20,1)) as [M05] ") sql_gmes.AppendLine(",cast([M07] as decimal(20,1)) as [M07] ") sql_gmes.AppendLine(",cast([M08] as decimal(20,1)) as [M08] ") sql_gmes.AppendLine("from ") sql_gmes.AppendLine("( ") sql_gmes.AppendLine("SELECT ") sql_gmes.AppendLine("TT_RPRS_MODEL_CODE as model ") sql_gmes.AppendLine(",LINE_NM as line ") sql_gmes.AppendLine(",cast(FINZE_TT as decimal(20,1)) as tt ") sql_gmes.AppendLine("FROM OPENQUERY ") sql_gmes.AppendLine("(GMES20, ") sql_gmes.AppendLine("'SELECT ") sql_gmes.AppendLine("T1.TT_RPRS_MODEL_CODE ") sql_gmes.AppendLine(",T1.LINE_CODE ") sql_gmes.AppendLine(",T2.LINE_NM ") sql_gmes.AppendLine(",T1.FINZE_TT ") sql_gmes.AppendLine("FROM TBP_PM_FINZE_TT T1 ") sql_gmes.AppendLine("LEFT JOIN TBM_MD_LINE T2 ") sql_gmes.AppendLine("ON T1.LINE_CODE = T2.LINE_CODE' ") sql_gmes.AppendLine(") ") sql_gmes.AppendLine(") as SourceTable ") sql_gmes.AppendLine("pivot ") sql_gmes.AppendLine("( ") sql_gmes.AppendLine("max([tt]) ") sql_gmes.AppendLine("for Line in ([M01],[M03],[M04],[M05],[M07],[M08]) ") sql_gmes.AppendLine(") as PivotTable ") 'Саму таблицу заполняем в data_selected только в случае, если включен режим сравнения с G-MES, в других случаях тратить время на выборку смысла нет Dim userid As String = "" If Not IsNothing(Request.QueryString("OrchUserLogin")) Then userid = Request.QueryString("OrchUserLogin") End If If Not IsNothing(Request.QueryString("u")) Then userid = Request.QueryString("u") End If If userid = "" Then authorize("SSO") userid = a.userId edTableToView.Message = "By SSO: " & a.userId End If Dim tableId As String = "1141" Dim viewId As String = "" 'If Not IsNothing(Request.QueryString("tableId")) Then ' tableId = Request.QueryString("tableId") 'End If 'If Not IsNothing(Request.QueryString("t")) Then ' tableId = Request.QueryString("t") 'End If 'If Not IsNothing(Request.QueryString("viewid")) Then ' viewId = Request.QueryString("viewid") 'End If 'If Not IsNothing(Request.QueryString("v")) Then ' viewId = Request.QueryString("v") 'End If 'If Not IsNothing(Request.QueryString("debug")) Then ' edTableToView.debugMode = (Request.QueryString("debug") = "true") 'End If If flag.Value.Equals("true") Then sop_flag = True Else sop_flag = False End If If compare.Value.Equals("true") Then gmes_flag = True Else gmes_flag = False End If If today.Value.Equals("true") Then today_flag = True Else today_flag = False End If If Not IsPostBack Then If Not IsNothing(Request.QueryString("p")) Then If IsNumeric(Request.QueryString("p")) Then edTableToView.PageSize = Request.QueryString("p") End If End If End If edTableToView.IsReadOnly = True edTableToView.UserName = userid.ToUpper If Not IsNothing(Request.QueryString("viewonly")) Then If Request.QueryString("viewonly").ToString.ToUpper = "YES" Then edTableToView.UserName = "" End If End If Try If Not IsNothing(Request.QueryString("mailscheduleid")) Then Try Dim ScheduleParams As DataRow ScheduleParams = sqlf.GetData("SELECT * FROM UserModules.dbo.Mail_Schedule WHERE id = " & Request.QueryString("mailscheduleid") & " and enabled='Y'").Rows(0) tableId = ScheduleParams("table_id") edTableToView.TableId = tableId graphForTable.TableId = tableId Dim mailRecepients As DataTable = sqlf.GetData("SELECT * from UserModules.dbo.Mail_Groups WHERE MAIL_GROUP_NAME = '" & ScheduleParams("MAIL_GROUP") & "' and enabled = 'Y'") If mailRecepients.Rows.Count > 0 Then UpdteMessageSendLog(Request.QueryString("mailscheduleid"), "OK", "START") For Each dr As DataRow In mailRecepients.Rows If dr("single_id") <> "" Then 'Dim UserTableName As String = (New SqlFunctions).GetScalar("SELECT tablename FROM UserModules.dbo.ModuleTables where id = " & tableId) Dim messageBody As String = ScheduleParams("body_text") & "<hr />" edTableToView.AuthorityCheck() edTableToView.BuildColumnsConfiguration() Select Case ScheduleParams("message_Type") Case "Graph" messageBody &= graphForTable.GetHTMLGraph Case "Table" messageBody &= edTableToView.GetHTMLGrid Case "Table & Graph" messageBody &= edTableToView.GetHTMLGrid messageBody &= "<hr />" messageBody &= graphForTable.GetHTMLGraph End Select CommonFunctions.SendEmail(dr("single_id"), ScheduleParams("subject_text"), messageBody) UpdteMessageSendLog(Request.QueryString("mailscheduleid"), "OK", dr("single_id")) End If Next UpdteMessageSendLog(Request.QueryString("mailscheduleid"), "OK", "FINISH") End If Catch ex As Exception End Try Response.Write("Message send.") Response.End() End If If IsNumeric(tableId) Then edTableToView.TableId = tableId graphForTable.TableId = tableId Else edTableToView.TableId = -1 graphForTable.TableId = -1 End If If IsNumeric(viewId) Then edTableToView.ViewID = viewId Else edTableToView.ViewID = -1 End If graphForTable.SelectCondition = edTableToView.SelectConditionByFilters Catch ex As Exception End Try End Sub Private Sub UpdteMessageSendLog(mailScheduleId As Integer, result As String, message As String) Dim sql As String = "INSERT Into UserModules.DBO.MAIL_SEND_LOG (MAIL_SCHEDULE_ID, LAST_RUN, RESULT,[MESSAGE]) VALUES (" & mailScheduleId & ",'" & DateTime.Now.ToString("yyyy-MM-dd HH:mm") & "','OK','" & message & "')" sqlf.NonQuery(sql) End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub Protected Sub filterChanged() Handles edTableToView.GridFilterChanged End Sub Private Sub dataselecting(ByRef sql As String) Handles edTableToView.DataSelecting Dim separator() As String = {"ORDER BY"} Dim st_arr As Array = sql.Split(separator, StringSplitOptions.None) Dim add_sql_code As New StringBuilder Dim add_sql_head_code As New StringBuilder If today_flag Then add_sql_code.AppendLine("and id in (select change_id from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] where cast(change_date as date) = cast(getdate() as date))") sql = st_arr(0) + add_sql_code.ToString + "ORDER BY" + st_arr(1) + add_sql_code.ToString + "ORDER BY" + st_arr(2) End If If sop_flag Then add_sql_code.AppendLine("and case when exists( ") add_sql_code.AppendLine("select distinct material ") add_sql_code.AppendLine("from [UserModules].[user].[SOP_for_TT_CAPA] ") add_sql_code.AppendLine("where ((W_1 is not null and W_1 <> 0 ) ") add_sql_code.AppendLine("or (W is not null and W <> 0 )) ") add_sql_code.AppendLine("and material = PRODUCT ") add_sql_code.AppendLine(") then 'Y' ") add_sql_code.AppendLine("else 'N' ") add_sql_code.AppendLine("end = 'Y' ") sql = st_arr(0) + add_sql_code.ToString + "ORDER BY" + st_arr(1) + add_sql_code.ToString + "ORDER BY" + st_arr(2) End If If gmes_flag Then add_sql_head_code.Clear() add_sql_head_code.AppendLine("declare @tmp as table (product varchar(max)) ") add_sql_head_code.AppendLine("insert into @tmp ") add_sql_head_code.AppendLine("select ") add_sql_head_code.AppendLine("product ") add_sql_head_code.AppendLine("from [UserModules].[user].[PRODUCTION_TT] as [catalog] ") add_sql_head_code.AppendLine(" ") add_sql_head_code.AppendLine(" ") add_sql_head_code.AppendLine("left join ( ") add_sql_head_code.AppendLine(" select ") add_sql_head_code.AppendLine(" model ") add_sql_head_code.AppendLine(" ,cast([M01] as decimal(20,1)) as [M01] ") add_sql_head_code.AppendLine(" ,cast([M03] as decimal(20,1)) as [M03] ") add_sql_head_code.AppendLine(" ,cast([M04] as decimal(20,1)) as [M04] ") add_sql_head_code.AppendLine(" ,cast([M05] as decimal(20,1)) as [M05] ") add_sql_head_code.AppendLine(" ,cast([M07] as decimal(20,1)) as [M07] ") add_sql_head_code.AppendLine(" ,cast([M08] as decimal(20,1)) as [M08] ") add_sql_head_code.AppendLine(" from ") add_sql_head_code.AppendLine(" ( ") add_sql_head_code.AppendLine(" SELECT ") add_sql_head_code.AppendLine(" TT_RPRS_MODEL_CODE as model ") add_sql_head_code.AppendLine(" ,LINE_NM as line ") add_sql_head_code.AppendLine(" ,cast(FINZE_TT as decimal(20,1)) as tt ") add_sql_head_code.AppendLine(" FROM OPENQUERY ") add_sql_head_code.AppendLine(" (GMES20, ") add_sql_head_code.AppendLine(" 'SELECT ") add_sql_head_code.AppendLine(" T1.TT_RPRS_MODEL_CODE ") add_sql_head_code.AppendLine(" ,T1.LINE_CODE ") add_sql_head_code.AppendLine(" ,T2.LINE_NM ") add_sql_head_code.AppendLine(" ,T1.FINZE_TT ") add_sql_head_code.AppendLine(" FROM TBP_PM_FINZE_TT T1 ") add_sql_head_code.AppendLine(" LEFT JOIN TBM_MD_LINE T2 ") add_sql_head_code.AppendLine(" ON T1.LINE_CODE = T2.LINE_CODE' ") add_sql_head_code.AppendLine(" ) ") add_sql_head_code.AppendLine(" ) as SourceTable ") add_sql_head_code.AppendLine(" pivot ") add_sql_head_code.AppendLine(" ( ") add_sql_head_code.AppendLine(" max([tt]) ") add_sql_head_code.AppendLine(" for Line in ([M01],[M03],[M04],[M05],[M07],[M08]) ") add_sql_head_code.AppendLine(" ) as PivotTable ") add_sql_head_code.AppendLine(") as [G-MES] ") add_sql_head_code.AppendLine("on [G-MES].model collate Cyrillic_General_CI_AI = [catalog].PRODUCT collate Cyrillic_General_CI_AI ") add_sql_head_code.AppendLine(" ") add_sql_head_code.AppendLine(" ") add_sql_head_code.AppendLine(" ") add_sql_head_code.AppendLine("where ( ") add_sql_head_code.AppendLine(" (cast(case ") add_sql_head_code.AppendLine(" when M01_TT = '' then null ") add_sql_head_code.AppendLine(" else M01_TT ") add_sql_head_code.AppendLine(" end as decimal(20,1)) <> cast(isnull(M01,'0') as decimal(20,1)) ") add_sql_head_code.AppendLine(" and M01_TT <> '' and M01_TT is not null) ") add_sql_head_code.AppendLine("or ") add_sql_head_code.AppendLine(" (cast(case ") add_sql_head_code.AppendLine(" when M03_TT = '' then null ") add_sql_head_code.AppendLine(" else M03_TT ") add_sql_head_code.AppendLine(" end as decimal(20,1)) <> cast(isnull(M03,'0') as decimal(20,1)) ") add_sql_head_code.AppendLine(" and M03_TT <> '' and M03_TT is not null) ") add_sql_head_code.AppendLine("or ") add_sql_head_code.AppendLine(" (cast(case ") add_sql_head_code.AppendLine(" when M04_TT = '' then null ") add_sql_head_code.AppendLine(" else M04_TT ") add_sql_head_code.AppendLine(" end as decimal(20,1)) <> cast(isnull(M04,'0') as decimal(20,1)) ") add_sql_head_code.AppendLine(" and M04_TT <> '' and M04_TT is not null) ") add_sql_head_code.AppendLine("or ") add_sql_head_code.AppendLine(" (cast(case ") add_sql_head_code.AppendLine(" when M05_TT = '' then null ") add_sql_head_code.AppendLine(" else M05_TT ") add_sql_head_code.AppendLine(" end as decimal(20,1)) <> cast(isnull(M05,'0') as decimal(20,1)) ") add_sql_head_code.AppendLine(" and M05_TT <> '' and M05_TT is not null) ") add_sql_head_code.AppendLine("or ") add_sql_head_code.AppendLine(" (cast(case ") add_sql_head_code.AppendLine(" when M07_TT = '' then null ") add_sql_head_code.AppendLine(" else M07_TT ") add_sql_head_code.AppendLine(" end as decimal(20,1)) <> cast(isnull(M07,'0') as decimal(20,1)) ") add_sql_head_code.AppendLine(" and M07_TT <> '' and M07_TT is not null) ") add_sql_head_code.AppendLine("or ") add_sql_head_code.AppendLine(" (cast(case ") add_sql_head_code.AppendLine(" when M08_TT = '' then null ") add_sql_head_code.AppendLine(" else M08_TT ") add_sql_head_code.AppendLine(" end as decimal(20,1)) <> cast(isnull(M08,'0') as decimal(20,1)) ") add_sql_head_code.AppendLine(" and M08_TT <> '' and M08_TT is not null) ") add_sql_head_code.AppendLine(") ") st_arr(0) = add_sql_head_code.ToString + st_arr(0) add_sql_code.AppendLine("and product in ( ") add_sql_code.AppendLine("select ") add_sql_code.AppendLine("product collate Cyrillic_General_CI_AS ") add_sql_code.AppendLine("from @tmp ") add_sql_code.AppendLine(" ) ") sql = st_arr(0) + add_sql_code.ToString + "ORDER BY" + st_arr(1) + add_sql_code.ToString + "ORDER BY" + st_arr(2) End If End Sub Private Sub DataSelected(dt As DataTable) Handles edTableToView.DataSelected 'If flag.Value.Equals("true") Then ' sop_flag = True 'Else ' sop_flag = False 'End If If gmes_flag = True Then 'В таблицу dt_gms получаем список всего, что есть в G-MES. Потом по ней будем сравнивать значения ТТ со справочником и подсвечивать расхождения dt_gmes = sqlf.GetData(sql_gmes.ToString) 'Создаём первичный ключ, чтобы потом пользоваться им для поиска Dim primaryKey_gmes(1) As DataColumn primaryKey_gmes(0) = dt_gmes.Columns(0) dt_gmes.PrimaryKey = primaryKey_gmes 'Коллекцию рядов из dt_plan кладём в dr_gmes. В ней будем искать dr_gmes = dt_gmes.Rows End If End Sub Protected Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender 'ClientScript.RegisterStartupScript(Me.GetType(), "CreateGridHeader", "<script>CreateGridHeader('DataDiv', 'editableGrid1_GridView1', 'HeaderDiv');</script>") graphForTable.SelectCondition = edTableToView.SelectConditionByFilters graphForTable.Visible = graphForTable.DrawGraph() If (Request.QueryString("tableId") IsNot Nothing) And graphForTable.Visible Then lnkGraphView.Visible = True lnkGraphView.Text = "View graph in a new window" lnkGraphView.NavigateUrl = "~/viewgraph.aspx?tableid=" & Request.QueryString("tableId") Else lnkGraphView.Visible = False End If If edTableToView.IsReadOnly Then edTableToView.CollectHeaderColumn(1) End If 'Title = edTableToView.TableDescription Title = "Capa and T/T catalog" 'If edTableToView.copyFlag Then ' edTableToView.AddFormMode(edTableToView.copyId) 'End If edTableToView.SubReport.Controls.Add(createSubreport(edTableToView.TableId)) Dim script As String = sqlf.GetScalar("SELECT Gridcommand_handler FROM UserModules.dbo.ModuleTables WHERE id=" & edTableToView.TableId) If script <> "" Then gridcommandhandlerscript.Controls.Add(New Literal With {.Text = "<script type=""text/javascript"">" & script & "</script>"}) End If Dim refresh_flag As String = sqlf.GetScalar("SELECT refresh_after_event FROM UserModules.dbo.ModuleTables WHERE id=" & edTableToView.TableId) If refresh_flag <> "" Then edTableToView.refresh_after_event = refresh_flag refresh_after_event.Value = refresh_flag End If End Sub Private Function createSubreport(tid As String) As GridView Dim gv As New GridView Dim query As String = sqlf.GetScalar("SELECT isnull(SUBREPORT_QUERY,'') from usermodules.dbo.moduletables where id = " & tid) If query <> "" And Not (query.Contains("update") Or query.Contains("delete") Or query.Contains("exec") Or query.Contains("truncate") Or query.Contains("drop")) Then gv.DataSource = sqlf.GetData(query) Try gv.DataBind() Catch ex As Exception Return Nothing End Try End If Return gv End Function Protected Sub UpdateUserInfo(ByRef com As SqlCommand) Handles edTableToView.NewRecordSaving Try com.Parameters("@CHANGED_BY").Value = a.userId ' auth Request.QueryString("orchuserlogin") Catch ex As Exception End Try End Sub Protected Sub Page_SaveStateComplete(sender As Object, e As EventArgs) Handles Me.SaveStateComplete edTableToView.CreateGroupingText() End Sub Protected Sub GetGraphData(ByRef graphData As String) Handles edTableToView.RequestForGraphData graphData = graphForTable.GetHTMLGraph End Sub Protected Sub edTableToView_PreRender(sender As Object, e As System.EventArgs) Handles edTableToView.PreRender For Each row As GridViewRow In edTableToView.rows 'edTableToView.rows.remove(row) Next End Sub Protected Sub Page_Unload(sender As Object, e As EventArgs) Handles Me.Unload End Sub Private Sub edTableToView_RowDataBinding(ByRef row As GridViewRow, ByRef canEdit As Boolean) Handles edTableToView.RowDataBinding 'Цвет модели в зависимости от года If row.RowType = DataControlRowType.DataRow Then row.Cells(6).BackColor = Drawing.Color.FromArgb(255, 255, 204) row.Cells(8).BackColor = Drawing.Color.FromArgb(255, 255, 204) row.Cells(10).BackColor = Drawing.Color.FromArgb(255, 255, 204) row.Cells(12).BackColor = Drawing.Color.FromArgb(255, 255, 204) row.Cells(14).BackColor = Drawing.Color.FromArgb(255, 255, 204) row.Cells(16).BackColor = Drawing.Color.FromArgb(255, 255, 204) If row.Cells(3).Text.Contains("2019") Then row.Cells(3).BackColor = Drawing.Color.FromArgb(66, 99, 66) If row.Cells(3).Text.Contains("2018") Then row.Cells(3).BackColor = Drawing.Color.FromArgb(255, 255, 51) If row.Cells(3).Text.Contains("2017") Then row.Cells(3).BackColor = Drawing.Color.FromArgb(204, 204, 153) If row.Cells(3).Text.Contains("2016") Then row.Cells(3).BackColor = Drawing.Color.FromArgb(33, 204, 255) If row.Cells(3).Text.Contains("2015") Then row.Cells(3).BackColor = Drawing.Color.FromArgb(255, 99, 33) If row.Cells(3).Text.Contains("2014") Then row.Cells(3).BackColor = Drawing.Color.FromArgb(255, 204, 33) If row.Cells(3).Text.Contains("2013") Then row.Cells(3).BackColor = Drawing.Color.FromArgb(204, 204, 204) 'Попап для истории изменений при наведении на модель Dim history As String = PrepareTooltip_History(row.Cells(0).Text) If Not history.Equals("<div>" & vbCrLf & vbCrLf & "</div>") Then row.Cells(4).Text = "<div data-toggle=""tooltip"" data-placement=""auto"" data-html=""True"" data-original-title=""" + history + """ style=""cursor pointer;"">" + row.Cells(4).Text + "</div>" End If 'Если сегодня были изменеия для этой строки If dr_today.Contains(row.Cells(0).Text) Then Dim color As Drawing.Color = Drawing.Color.FromArgb(255, 0, 204) Dim dr_temp = dr_today.Find(row.Cells(0).Text) Dim row_count As Integer = 0 Dim sql_today As New StringBuilder sql_today.AppendLine("select") sql_today.AppendLine("count(*) ") sql_today.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") sql_today.AppendLine("where isnull(old_val, '') <> isnull(new_val,'') ") sql_today.AppendLine("and cast(change_date as date) = cast(getdate() as date)") sql_today.AppendLine("and CHANGE_FIELD = 'M01_CAPA' ") sql_today.AppendLine("and change_id = '" + row.Cells(0).Text + "' ") row_count = 0 Integer.TryParse(sqlf.GetScalar(sql_today.ToString), row_count) If row_count > 0 Then row.Cells(6).BackColor = color row.Cells(6).Text = "<div data-toggle=""tooltip"" data-placement=""auto"" data-html=""True"" data-original-title=""" + PrepareTooltip(row.Cells(0).Text, "M01_CAPA") + """ style=""cursor pointer;"">" + row.Cells(6).Text + "</div>" End If sql_today.Clear() sql_today.AppendLine("select") sql_today.AppendLine("count(*) ") sql_today.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") sql_today.AppendLine("where isnull(old_val, '') <> isnull(new_val,'') ") sql_today.AppendLine("and cast(change_date as date) = cast(getdate() as date)") sql_today.AppendLine("and CHANGE_FIELD = 'M03_CAPA' ") sql_today.AppendLine("and change_id = '" + row.Cells(0).Text + "' ") row_count = 0 Integer.TryParse(sqlf.GetScalar(sql_today.ToString), row_count) If row_count > 0 Then row.Cells(8).BackColor = color row.Cells(8).Text = "<div data-toggle=""tooltip"" data-placement=""auto"" data-html=""True"" data-original-title=""" + PrepareTooltip(row.Cells(0).Text, "M03_CAPA") + """ style=""cursor pointer;"">" + row.Cells(8).Text + "</div>" End If sql_today.Clear() sql_today.AppendLine("select") sql_today.AppendLine("count(*) ") sql_today.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") sql_today.AppendLine("where isnull(old_val, '') <> isnull(new_val,'') ") sql_today.AppendLine("and cast(change_date as date) = cast(getdate() as date)") sql_today.AppendLine("and CHANGE_FIELD = 'M04_CAPA' ") sql_today.AppendLine("and change_id = '" + row.Cells(0).Text + "' ") row_count = 0 Integer.TryParse(sqlf.GetScalar(sql_today.ToString), row_count) If row_count > 0 Then row.Cells(10).BackColor = color row.Cells(10).Text = "<div data-toggle=""tooltip"" data-placement=""auto"" data-html=""True"" data-original-title=""" + PrepareTooltip(row.Cells(0).Text, "M04_CAPA") + """ style=""cursor pointer;"">" + row.Cells(10).Text + "</div>" End If sql_today.Clear() sql_today.AppendLine("select") sql_today.AppendLine("count(*) ") sql_today.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") sql_today.AppendLine("where isnull(old_val, '') <> isnull(new_val,'') ") sql_today.AppendLine("and cast(change_date as date) = cast(getdate() as date)") sql_today.AppendLine("and CHANGE_FIELD = 'M05_CAPA' ") sql_today.AppendLine("and change_id = '" + row.Cells(0).Text + "' ") row_count = 0 Integer.TryParse(sqlf.GetScalar(sql_today.ToString), row_count) If row_count > 0 Then row.Cells(12).BackColor = color row.Cells(12).Text = "<div data-toggle=""tooltip"" data-placement=""auto"" data-html=""True"" data-original-title=""" + PrepareTooltip(row.Cells(0).Text, "M05_CAPA") + """ style=""cursor pointer;"">" + row.Cells(12).Text + "</div>" End If sql_today.Clear() sql_today.AppendLine("select") sql_today.AppendLine("count(*) ") sql_today.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") sql_today.AppendLine("where isnull(old_val, '') <> isnull(new_val,'') ") sql_today.AppendLine("and cast(change_date as date) = cast(getdate() as date)") sql_today.AppendLine("and CHANGE_FIELD = 'M07_CAPA' ") sql_today.AppendLine("and change_id = '" + row.Cells(0).Text + "' ") row_count = 0 Integer.TryParse(sqlf.GetScalar(sql_today.ToString), row_count) If row_count > 0 Then row.Cells(14).BackColor = color row.Cells(14).Text = "<div data-toggle=""tooltip"" data-placement=""auto"" data-html=""True"" data-original-title=""" + PrepareTooltip(row.Cells(0).Text, "M07_CAPA") + """ style=""cursor pointer;"">" + row.Cells(14).Text + "</div>" End If sql_today.Clear() sql_today.AppendLine("select") sql_today.AppendLine("count(*) ") sql_today.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") sql_today.AppendLine("where isnull(old_val, '') <> isnull(new_val,'') ") sql_today.AppendLine("and cast(change_date as date) = cast(getdate() as date)") sql_today.AppendLine("and CHANGE_FIELD = 'M08_CAPA' ") sql_today.AppendLine("and change_id = '" + row.Cells(0).Text + "' ") row_count = 0 Integer.TryParse(sqlf.GetScalar(sql_today.ToString), row_count) If row_count > 0 Then row.Cells(16).BackColor = color row.Cells(16).Text = "<div data-toggle=""tooltip"" data-placement=""auto"" data-html=""True"" data-original-title=""" + PrepareTooltip(row.Cells(0).Text, "M08_CAPA") + """ style=""cursor pointer;"">" + row.Cells(16).Text + "</div>" End If End If 'Если модель присутствует в SOP на эту неделю If dr_w.Contains(row.Cells(5).Text) Then row.Cells(5).BackColor = Drawing.Color.FromArgb(153, 204, 153) End If 'Если модель присутствует в SOP на следующую неделю If dr_w1.Contains(row.Cells(5).Text) Then row.Cells(5).BackColor = Drawing.Color.FromArgb(0, 255, 0) End If If Not gmes_flag Then 'Подсветка ТТ по текущему SOP (совпадающий - зелёный, несовпадающий - красный) If dr_plan.Contains(row.Cells(5).Text) Then Dim dr_temp = dr_plan.Find(row.Cells(5).Text) Dim t_tt As Decimal ' ТТ из справочника Dim p_tt As Decimal ' ТТ из данных планёров Decimal.TryParse(dr_temp("M01").ToString, p_tt) Decimal.TryParse(row.Cells(7).Text, t_tt) If p_tt = t_tt And p_tt <> 0 Then row.Cells(7).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And p_tt <> 0 Then row.Cells(7).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M03").ToString, p_tt) Decimal.TryParse(row.Cells(9).Text, t_tt) If p_tt = t_tt And p_tt <> 0 Then row.Cells(9).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And p_tt <> 0 Then row.Cells(9).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M04").ToString, p_tt) Decimal.TryParse(row.Cells(11).Text, t_tt) If p_tt = t_tt And p_tt <> 0 Then row.Cells(11).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And p_tt <> 0 Then row.Cells(11).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M05").ToString, p_tt) Decimal.TryParse(row.Cells(13).Text, t_tt) If p_tt = t_tt And p_tt <> 0 Then row.Cells(13).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And p_tt <> 0 Then row.Cells(13).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M07").ToString, p_tt) Decimal.TryParse(row.Cells(15).Text, t_tt) If p_tt = t_tt And p_tt <> 0 Then row.Cells(15).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And p_tt <> 0 Then row.Cells(15).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M08").ToString, p_tt) Decimal.TryParse(row.Cells(17).Text, t_tt) If p_tt = t_tt And p_tt <> 0 Then row.Cells(17).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And p_tt <> 0 Then row.Cells(17).BackColor = Drawing.Color.FromArgb(255, 0, 0) End If Else 'Подсветка по расхождениям с G-MES If dr_gmes.Contains(row.Cells(5).Text) Then Dim dr_temp = dr_gmes.Find(row.Cells(5).Text) Dim t_tt As Decimal ' ТТ из справочника Dim p_tt As Decimal ' ТТ из данных G-MES Decimal.TryParse(dr_temp("M01").ToString, p_tt) Decimal.TryParse(row.Cells(7).Text, t_tt) If p_tt = t_tt And p_tt <> 0 And t_tt <> 0 Then row.Cells(7).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And t_tt <> 0 Then row.Cells(7).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M03").ToString, p_tt) Decimal.TryParse(row.Cells(9).Text, t_tt) If p_tt = t_tt And p_tt <> 0 And t_tt <> 0 Then row.Cells(9).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And t_tt <> 0 Then row.Cells(9).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M04").ToString, p_tt) Decimal.TryParse(row.Cells(11).Text, t_tt) If p_tt = t_tt And p_tt <> 0 And t_tt <> 0 Then row.Cells(11).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And t_tt <> 0 Then row.Cells(11).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M05").ToString, p_tt) Decimal.TryParse(row.Cells(13).Text, t_tt) If p_tt = t_tt And p_tt <> 0 And t_tt <> 0 Then row.Cells(13).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And t_tt <> 0 Then row.Cells(13).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M07").ToString, p_tt) Decimal.TryParse(row.Cells(15).Text, t_tt) If p_tt = t_tt And p_tt <> 0 And t_tt <> 0 Then row.Cells(15).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And t_tt <> 0 Then row.Cells(15).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(dr_temp("M08").ToString, p_tt) Decimal.TryParse(row.Cells(17).Text, t_tt) If p_tt = t_tt And p_tt <> 0 And t_tt <> 0 Then row.Cells(17).BackColor = Drawing.Color.FromArgb(0, 255, 0) If p_tt <> t_tt And t_tt <> 0 Then row.Cells(17).BackColor = Drawing.Color.FromArgb(255, 0, 0) Else Dim t_tt As Decimal ' ТТ из справочника Decimal.TryParse(row.Cells(7).Text, t_tt) If t_tt <> 0 Then row.Cells(7).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(row.Cells(9).Text, t_tt) If t_tt <> 0 Then row.Cells(9).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(row.Cells(11).Text, t_tt) If t_tt <> 0 Then row.Cells(11).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(row.Cells(13).Text, t_tt) If t_tt <> 0 Then row.Cells(13).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(row.Cells(15).Text, t_tt) If t_tt <> 0 Then row.Cells(15).BackColor = Drawing.Color.FromArgb(255, 0, 0) Decimal.TryParse(row.Cells(17).Text, t_tt) If t_tt <> 0 Then row.Cells(17).BackColor = Drawing.Color.FromArgb(255, 0, 0) End If End If End If End Sub Private Sub ActionRequest(ByVal sender As Object, ByVal e As CommandEventArgs) Handles edTableToView.ActionRequest If e.CommandArgument = "SOP" Then If flag.Value.Equals("true") Then sop_flag = False flag.Value = "false" SOP.ForeColor = Drawing.Color.FromArgb(204, 204, 204) Else sop_flag = True flag.Value = "true" SOP.ForeColor = Drawing.Color.FromArgb(0, 0, 255) End If edTableToView.RefreshData() End If If e.CommandArgument = "TODAY" Then If today.Value.Equals("true") Then today_flag = False today.Value = "false" Today_change.ForeColor = Drawing.Color.FromArgb(204, 204, 204) Else today_flag = True today.Value = "true" Today_change.ForeColor = Drawing.Color.FromArgb(0, 0, 255) End If edTableToView.RefreshData() End If If e.CommandArgument = "COMPARE" Then If compare.Value.Equals("true") Then gmes_flag = False compare.Value = "false" GMES.ForeColor = Drawing.Color.FromArgb(204, 204, 204) Else gmes_flag = True compare.Value = "true" GMES.ForeColor = Drawing.Color.FromArgb(0, 0, 255) End If edTableToView.RefreshData() End If If e.CommandArgument = "SYNC" Then If selected_rows.Value <> "" Then Dim separator(1) As Char separator(0) = ";" Dim id_arr As String() = selected_rows.Value.Split(separator) Dim sql_mes_change As New StringBuilder For i = 0 To id_arr.Length - 1 sql_mes_change.Clear() sql_mes_change.AppendLine("declare @id integer ") sql_mes_change.AppendLine("set @id =" & id_arr(i)) sql_mes_change.AppendLine("declare @cur_id integer, @cur_product varchar(max), @cur_group varchar(max) ") sql_mes_change.AppendLine("declare @cur_M01_TT varchar(max), @cur_M03_TT varchar(max), @cur_M04_TT varchar(max), @cur_M05_TT varchar(max), @cur_M07_TT varchar(max), @cur_M08_TT varchar(max) ") sql_mes_change.AppendLine("declare @cur_M01 varchar(max), @cur_M03 varchar(max), @cur_M04 varchar(max), @cur_M05 varchar(max), @cur_M07 varchar(max), @cur_M08 varchar(max) ") sql_mes_change.AppendLine("select top 1 ") sql_mes_change.AppendLine("@cur_id = id ") sql_mes_change.AppendLine(",@cur_product = PRODUCT ") sql_mes_change.AppendLine(",@cur_group = [GROUP] ") sql_mes_change.AppendLine(",@cur_M01_TT = M01_TT ") sql_mes_change.AppendLine(",@cur_M03_TT = M03_TT ") sql_mes_change.AppendLine(",@cur_M04_TT = M04_TT ") sql_mes_change.AppendLine(",@cur_M05_TT = M05_TT ") sql_mes_change.AppendLine(",@cur_M07_TT = M07_TT ") sql_mes_change.AppendLine(",@cur_M08_TT = M08_TT ") sql_mes_change.AppendLine(",@cur_M01 = M01 ") sql_mes_change.AppendLine(",@cur_M03 = M03 ") sql_mes_change.AppendLine(",@cur_M04 = M04 ") sql_mes_change.AppendLine(",@cur_M05 = M05 ") sql_mes_change.AppendLine(",@cur_M07 = M07 ") sql_mes_change.AppendLine(",@cur_M08 = M08 ") sql_mes_change.AppendLine("from [UserModules].[user].[PRODUCTION_TT] as [catalog] ") sql_mes_change.AppendLine("left join ( ") sql_mes_change.AppendLine(" select ") sql_mes_change.AppendLine(" model ") sql_mes_change.AppendLine(" ,cast([M01] as decimal(20,1)) as [M01] ") sql_mes_change.AppendLine(" ,cast([M03] as decimal(20,1)) as [M03] ") sql_mes_change.AppendLine(" ,cast([M04] as decimal(20,1)) as [M04] ") sql_mes_change.AppendLine(" ,cast([M05] as decimal(20,1)) as [M05] ") sql_mes_change.AppendLine(" ,cast([M07] as decimal(20,1)) as [M07] ") sql_mes_change.AppendLine(" ,cast([M08] as decimal(20,1)) as [M08] ") sql_mes_change.AppendLine(" from ") sql_mes_change.AppendLine(" ( ") sql_mes_change.AppendLine(" SELECT ") sql_mes_change.AppendLine(" TT_RPRS_MODEL_CODE as model ") sql_mes_change.AppendLine(" ,LINE_NM as line ") sql_mes_change.AppendLine(" ,cast(FINZE_TT as decimal(20,1)) as tt ") sql_mes_change.AppendLine(" FROM OPENQUERY ") sql_mes_change.AppendLine(" (GMES20, ") sql_mes_change.AppendLine(" 'SELECT ") sql_mes_change.AppendLine(" T1.TT_RPRS_MODEL_CODE ") sql_mes_change.AppendLine(" ,T1.LINE_CODE ") sql_mes_change.AppendLine(" ,T2.LINE_NM ") sql_mes_change.AppendLine(" ,T1.FINZE_TT ") sql_mes_change.AppendLine(" FROM TBP_PM_FINZE_TT T1 ") sql_mes_change.AppendLine(" LEFT JOIN TBM_MD_LINE T2 ") sql_mes_change.AppendLine(" ON T1.LINE_CODE = T2.LINE_CODE' ") sql_mes_change.AppendLine(" ) ") sql_mes_change.AppendLine(" ) as SourceTable ") sql_mes_change.AppendLine(" pivot ") sql_mes_change.AppendLine(" ( ") sql_mes_change.AppendLine(" max([tt]) ") sql_mes_change.AppendLine(" for Line in ([M01],[M03],[M04],[M05],[M07],[M08]) ") sql_mes_change.AppendLine(" ) as PivotTable ") sql_mes_change.AppendLine(") as [G-MES] ") sql_mes_change.AppendLine("on [G-MES].model collate Cyrillic_General_CI_AI = [catalog].PRODUCT collate Cyrillic_General_CI_AI ") sql_mes_change.AppendLine("where ( ") sql_mes_change.AppendLine(" (cast(case ") sql_mes_change.AppendLine(" when M01_TT = '' then null ") sql_mes_change.AppendLine(" else M01_TT ") sql_mes_change.AppendLine(" end as decimal(20,1)) <> cast(M01 as decimal(20,1)) ") sql_mes_change.AppendLine(" and M01_TT <> '' and M01_TT is not null) ") sql_mes_change.AppendLine("or ") sql_mes_change.AppendLine(" (cast(case ") sql_mes_change.AppendLine(" when M03_TT = '' then null ") sql_mes_change.AppendLine(" else M03_TT ") sql_mes_change.AppendLine(" end as decimal(20,1)) <> cast(M03 as decimal(20,1)) ") sql_mes_change.AppendLine(" and M03_TT <> '' and M03_TT is not null) ") sql_mes_change.AppendLine("or ") sql_mes_change.AppendLine(" (cast(case ") sql_mes_change.AppendLine(" when M04_TT = '' then null ") sql_mes_change.AppendLine(" else M04_TT ") sql_mes_change.AppendLine(" end as decimal(20,1)) <> cast(M04 as decimal(20,1)) ") sql_mes_change.AppendLine(" and M04_TT <> '' and M04_TT is not null) ") sql_mes_change.AppendLine("or ") sql_mes_change.AppendLine(" (cast(case ") sql_mes_change.AppendLine(" when M05_TT = '' then null ") sql_mes_change.AppendLine(" else M05_TT ") sql_mes_change.AppendLine(" end as decimal(20,1)) <> cast(M05 as decimal(20,1)) ") sql_mes_change.AppendLine(" and M05_TT <> '' and M05_TT is not null) ") sql_mes_change.AppendLine("or ") sql_mes_change.AppendLine(" (cast(case ") sql_mes_change.AppendLine(" when M07_TT = '' then null ") sql_mes_change.AppendLine(" else M07_TT ") sql_mes_change.AppendLine(" end as decimal(20,1)) <> cast(M07 as decimal(20,1)) ") sql_mes_change.AppendLine(" and M07_TT <> '' and M07_TT is not null) ") sql_mes_change.AppendLine("or ") sql_mes_change.AppendLine(" (cast(case ") sql_mes_change.AppendLine(" when M08_TT = '' then null ") sql_mes_change.AppendLine(" else M08_TT ") sql_mes_change.AppendLine(" end as decimal(20,1)) <> cast(M08 as decimal(20,1)) ") sql_mes_change.AppendLine(" and M08_TT <> '' and M08_TT is not null) ") sql_mes_change.AppendLine(") ") sql_mes_change.AppendLine("and id = @id ") sql_mes_change.AppendLine(" if @cur_M01_TT <> @cur_M01 and @cur_M01_TT is not null and @cur_M01_TT <> '' ") sql_mes_change.AppendLine(" update [UserModules].[user].[PRODUCTION_TT] ") sql_mes_change.AppendLine(" set M01_TT = round(cast(@cur_M01 as decimal(20,1)), 1) ") sql_mes_change.AppendLine(" , M01_CAPA = cast(round(28800 / cast(@cur_M01 as decimal(20,1)), 1) as numeric) ") sql_mes_change.AppendLine(" where [group] = @cur_group ") sql_mes_change.AppendLine(" if @cur_M03_TT <> @cur_M03 and @cur_M03_TT is not null and @cur_M03_TT <> '' ") sql_mes_change.AppendLine(" update [UserModules].[user].[PRODUCTION_TT] ") sql_mes_change.AppendLine(" set M03_TT = round(cast(@cur_M03 as decimal(20,1)), 1) ") sql_mes_change.AppendLine(" , M03_CAPA = cast(round(28800 / cast(@cur_M03 as decimal(20,1)), 1) as numeric) ") sql_mes_change.AppendLine(" where [group] = @cur_group ") sql_mes_change.AppendLine(" if @cur_M04_TT <> @cur_M04 and @cur_M04_TT is not null and @cur_M04_TT <> '' ") sql_mes_change.AppendLine(" update [UserModules].[user].[PRODUCTION_TT] ") sql_mes_change.AppendLine(" set M04_TT = round(cast(@cur_M04 as decimal(20,1)), 1) ") sql_mes_change.AppendLine(" , M04_CAPA = cast(round(28800 / cast(@cur_M04 as decimal(20,1)), 1) as numeric) ") sql_mes_change.AppendLine(" where [group] = @cur_group ") sql_mes_change.AppendLine(" if @cur_M05_TT <> @cur_M05 and @cur_M05_TT is not null and @cur_M05_TT <> '' ") sql_mes_change.AppendLine(" update [UserModules].[user].[PRODUCTION_TT] ") sql_mes_change.AppendLine(" set M05_TT = round(cast(@cur_M05 as decimal(20,1)), 1) ") sql_mes_change.AppendLine(" , M05_CAPA = cast(round(28800 / cast(@cur_M05 as decimal(20,1)), 1) as numeric) ") sql_mes_change.AppendLine(" where [group] = @cur_group ") sql_mes_change.AppendLine(" if @cur_M07_TT <> @cur_M07 and @cur_M07_TT is not null and @cur_M07_TT <> '' ") sql_mes_change.AppendLine(" update [UserModules].[user].[PRODUCTION_TT] ") sql_mes_change.AppendLine(" set M07_TT = round(cast(@cur_M07 as decimal(20,1)), 1) ") sql_mes_change.AppendLine(" , M07_CAPA = cast(round(28800 / cast(@cur_M07 as decimal(20,1)), 1) as numeric) ") sql_mes_change.AppendLine(" where [group] = @cur_group ") sql_mes_change.AppendLine(" if @cur_M08_TT <> @cur_M08 and @cur_M08_TT is not null and @cur_M08_TT <> '' ") sql_mes_change.AppendLine(" update [UserModules].[user].[PRODUCTION_TT] ") sql_mes_change.AppendLine(" set M08_TT = round(cast(@cur_M08 as decimal(20,1)), 1) ") sql_mes_change.AppendLine(" , M08_CAPA = cast(round(28800 / cast(@cur_M08 as decimal(20,1)), 1) as numeric) ") sql_mes_change.AppendLine(" where [group] = @cur_group ") sqlf.NonQuery(sql_mes_change.ToString) Next selected_rows.Value = "" edTableToView.RefreshData() End If End If End Sub Private Sub edTableToView_RowDataBoundComplete(ByRef row As GridViewRow) Handles edTableToView.RowDataBoundComplete If row.RowType = DataControlRowType.DataRow Then row.Cells(2).Controls.Add(New CheckBox With {.ID = row.Cells(0).Text, .ClientIDMode = UI.ClientIDMode.Static, .CssClass = "check", .ToolTip = "Check to print this row"}) End If End Sub Private Function PrepareTooltip(row_id As String, field As String, Optional headerGRoups As Collection = Nothing, Optional removeLastColumn As Boolean = False, Optional collectHeaders As Collection = Nothing, Optional showfooter As Boolean = False ) As String Dim dt As DataTable Dim request As New StringBuilder request.AppendLine("select distinct ") request.AppendLine("cast(change_date as smalldatetime) as [Time] ") request.AppendLine(",old_val as [Old value]") request.AppendLine(",new_val as [New value]") request.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") request.AppendLine("where isnull(old_val, '') <> isnull(new_val,'') ") request.AppendLine("and cast (change_date as date) = cast(getdate() as date) ") request.AppendLine("and CHANGE_FIELD = '" + field + "' ") request.AppendLine("and change_id = '" + row_id + "' ") request.AppendLine("order by cast(change_date as smalldatetime) asc ") dt = sqlf.GetData(request.ToString) Dim result As String = "" Dim gv As New GridView gv.ShowFooter = showfooter gv.BackColor = Drawing.Color.FromArgb(204, 204, 204) gv.DataSource = dt gv.DataBind() 'If Not IsNothing(headerGRoups) Then ' ApplyGridViewHeader(ID.ToString, gv, headerGRoups) 'End If 'If Not IsNothing(collectHeaders) Then ' For Each c In collectHeaders ' CollectHeaderColumn(gv, c) ' Next 'Else ' CollectHeaderColumn(gv, 0) ' CollectHeaderColumn(gv, 1) 'End If Dim myCItrad As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("EN-US", True) Dim sw As StringWriter = New StringWriter(myCItrad) Dim hw As HtmlTextWriter = New HtmlTextWriter(sw) gv.CssClass = "detailTable" 'gv.FooterStyle.BackColor = Drawing.Color.SteelBlue 'gv.FooterStyle.ForeColor = Drawing.Color.White 'gv.FooterRow.Cells(2).Text = TTLTruck 'gv.FooterRow.Cells(0).ColumnSpan = 2 'gv.FooterRow.Cells(0).Text = "Total" 'gv.FooterRow.Cells(1).Visible = False 'If showfooter Then ' Dim GridRow As GridViewRow = New GridViewRow(gv.Rows.Count, 0, DataControlRowType.Footer, DataControlRowState.Normal) ' Dim TabCell As TableCell = New TableCell ' TabCell.Text = "Total in trucks" ' TabCell.ColumnSpan = 2 ' GridRow.Cells.Add(TabCell) ' TabCell = New TableCell ' TabCell.Text = TTL_In_Track ' GridRow.Cells.Add(TabCell) ' gv.Controls(0).Controls.Add(GridRow) 'End If gv.RenderControl(hw) result = sw.ToString.Replace("""", "'") gv.Dispose() Return result End Function Private Function PrepareTooltip_History(row_id As String) As String Dim dt As DataTable Dim request As New StringBuilder request.AppendLine("declare @id as varchar(max) ") request.AppendLine("set @id = '" + row_id + "' ") request.AppendLine(" ") request.AppendLine("select * from ") request.AppendLine("( ") request.AppendLine("select top 1 ") request.AppendLine("'M01' as Line ") request.AppendLine(",cast(change_date as smalldatetime) as [Time] ") request.AppendLine(",OLD_VAL as [Old value] ") request.AppendLine(",NEW_VAL as [New value] ") request.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") request.AppendLine("where change_id = @id ") request.AppendLine("and isnull(old_val, '') <> isnull(new_val,'') ") request.AppendLine("and CHANGE_FIELD = 'M01_CAPA' ") request.AppendLine("and cast(CHANGE_DATE as date) < cast(getdate() as date) ") request.AppendLine("order by cast(change_date as smalldatetime) desc ") request.AppendLine(") as M01 ") request.AppendLine(" ") request.AppendLine("union all ") request.AppendLine(" ") request.AppendLine("select * from ") request.AppendLine("( ") request.AppendLine("select top 1 ") request.AppendLine("'M03' as Line ") request.AppendLine(",cast(change_date as smalldatetime) as [Time] ") request.AppendLine(",OLD_VAL as [Old value] ") request.AppendLine(",NEW_VAL as [New value] ") request.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") request.AppendLine("where change_id = @id ") request.AppendLine("and isnull(old_val, '') <> isnull(new_val,'') ") request.AppendLine("and CHANGE_FIELD = 'M03_CAPA' ") request.AppendLine("and cast(CHANGE_DATE as date) < cast(getdate() as date) ") request.AppendLine("order by cast(change_date as smalldatetime) desc ") request.AppendLine(") M03 ") request.AppendLine(" ") request.AppendLine(" ") request.AppendLine("union all ") request.AppendLine(" ") request.AppendLine("select * from ") request.AppendLine("( ") request.AppendLine("select top 1 ") request.AppendLine("'M04' as Line ") request.AppendLine(",cast(change_date as smalldatetime) as [Time] ") request.AppendLine(",OLD_VAL as [Old value] ") request.AppendLine(",NEW_VAL as [New value] ") request.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") request.AppendLine("where change_id = @id ") request.AppendLine("and isnull(old_val, '') <> isnull(new_val,'') ") request.AppendLine("and CHANGE_FIELD = 'M04_CAPA' ") request.AppendLine("and cast(CHANGE_DATE as date) < cast(getdate() as date) ") request.AppendLine("order by cast(change_date as smalldatetime) desc ") request.AppendLine(") M04 ") request.AppendLine(" ") request.AppendLine("union all ") request.AppendLine(" ") request.AppendLine("select * from ") request.AppendLine("( ") request.AppendLine("select top 1 ") request.AppendLine("'M05' as Line ") request.AppendLine(",cast(change_date as smalldatetime) as [Time] ") request.AppendLine(",OLD_VAL as [Old value] ") request.AppendLine(",NEW_VAL as [New value] ") request.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") request.AppendLine("where change_id = @id ") request.AppendLine("and isnull(old_val, '') <> isnull(new_val,'') ") request.AppendLine("and CHANGE_FIELD = 'M05_CAPA' ") request.AppendLine("and cast(CHANGE_DATE as date) < cast(getdate() as date) ") request.AppendLine("order by cast(change_date as smalldatetime) desc ") request.AppendLine(") M05 ") request.AppendLine(" ") request.AppendLine("union all ") request.AppendLine(" ") request.AppendLine("select * from ") request.AppendLine("( ") request.AppendLine("select top 1 ") request.AppendLine("'M07' as Line ") request.AppendLine(",cast(change_date as smalldatetime) as [Time] ") request.AppendLine(",OLD_VAL as [Old value] ") request.AppendLine(",NEW_VAL as [New value] ") request.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") request.AppendLine("where change_id = @id ") request.AppendLine("and isnull(old_val, '') <> isnull(new_val,'') ") request.AppendLine("and CHANGE_FIELD = 'M07_CAPA' ") request.AppendLine("and cast(CHANGE_DATE as date) < cast(getdate() as date) ") request.AppendLine("order by cast(change_date as smalldatetime) desc ") request.AppendLine(") M07 ") request.AppendLine(" ") request.AppendLine("union all ") request.AppendLine(" ") request.AppendLine("select * from ") request.AppendLine("( ") request.AppendLine("select top 1 ") request.AppendLine("'M08' as Line ") request.AppendLine(",cast(change_date as smalldatetime) as [Time] ") request.AppendLine(",OLD_VAL as [Old value] ") request.AppendLine(",NEW_VAL as [New value] ") request.AppendLine("from [UserModules].[user].[CAPA_AND_T_T_CATALOG_TODAY_CHANGE] ") request.AppendLine("where change_id = @id ") request.AppendLine("and isnull(old_val, '') <> isnull(new_val,'') ") request.AppendLine("and CHANGE_FIELD = 'M08_CAPA' ") request.AppendLine("and cast(CHANGE_DATE as date) < cast(getdate() as date) ") request.AppendLine("order by cast(change_date as smalldatetime) desc ") request.AppendLine(") M08 ") request.AppendLine(" ") request.AppendLine(" ") dt = sqlf.GetData(request.ToString) Dim result As String = "" Dim gv As New GridView gv.BackColor = Drawing.Color.FromArgb(204, 204, 204) gv.DataSource = dt gv.DataBind() Dim myCItrad As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("EN-US", True) Dim sw As StringWriter = New StringWriter(myCItrad) Dim hw As HtmlTextWriter = New HtmlTextWriter(sw) gv.CssClass = "detailTable" gv.RenderControl(hw) result = sw.ToString.Replace("""", "'") gv.Dispose() Return result End Function Public Shared Sub ApplyGridViewHeader(ParentId As String, ByRef gv As GridView, ByRef a As Collection) 'процедура написана таким образом, что в нее всегда должны передаваться индексы с учетом только фактически отображаемых колонок 'т.е. при вычислении индекса объединяемой колонки (передаваемой в качестве параметра в процедуру) считается, 'что колонок со свойством Visible = false в таблице как бы нет. 'индексы (передаваемые в качестве параметров в процедуру) указываются по исходному порядку необъединенных колонок Dim AllowSorting As Boolean = gv.AllowSorting If gv.Rows.Count > 0 Then Dim row = New GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal) Dim r = gv.HeaderRow Dim cell As TableHeaderCell Dim i, j As Integer Dim invisibleColsCount As Integer = 0 Dim cnt As Integer = 0 'i = 1 For Each rcell As TableCell In r.Cells cell = New TableHeaderCell If AllowSorting Then Dim lb As New HyperLink Try lb.Style("color") = "White" lb.Text = CType(rcell.Controls(0), LinkButton).Text lb.NavigateUrl = "javascript:__doPostBack('" & ParentId & "$" & gv.ID & "','Sort$" & CType(rcell.Controls(0), LinkButton).CommandArgument & "')" cell.Controls.Add(lb) Catch ex As Exception cell.Text = rcell.Text End Try Else cell.Text = rcell.Text End If cell.Style("text-align") = "center" cell.Visible = rcell.Visible 'If cnt > a(i)(1) And cnt < a(i)(1) + a(i)(2) Then ' If Not rcell.Visible Then ' invisibleColsCount += 1 ' End If 'End If cnt += 1 row.Cells.Add(cell) 'End If Next 'для нужных ячеек в верхней строке, прописываем тексты объединяющих ячеек и их ColumnSpan For i = 1 To a.Count row.Cells(a(i)(1)).Text = a(i)(0) row.Cells(a(i)(1)).ColumnSpan = a(i)(2) - invisibleColsCount Next 'идем по верхней строке у оставшихся ячеек (не задействованных) в предыдущем цикле ставим им RowSpan = 2 'одновременно ячееки с таким же индексом в нижней строке помечаем на удаление For i = 0 To row.Cells.Count - 1 If row.Cells(i).Visible Then If row.Cells(i).ColumnSpan < 2 Then row.Cells(i).RowSpan = 2 r.Cells(i).ColumnSpan = 100 Else 'пропускаем ячейки на которые распространяется ColumnSpan i = i + row.Cells(i).ColumnSpan - 1 + invisibleColsCount End If End If Next 'удаляем помеченные ячейки в нижней строке i = 0 While i < r.Cells.Count If r.Cells(i).ColumnSpan = 100 Then r.Cells.RemoveAt(i) Else : i = i + 1 End If End While 'идем по верхней строке удаляем соответствующее ColumnSpan количество ячеек после ячеек имеющих ColumnSpan > 1 i = 0 While i < row.Cells.Count If row.Cells(i).ColumnSpan > 1 Then For j = 1 To row.Cells(i).ColumnSpan - 1 + invisibleColsCount row.Cells.RemoveAt(i + 1) Next End If i = i + 1 End While CType(gv.Controls(0), Table).Rows.AddAt(0, row) End If End Sub Public Sub CollectHeaderColumn(ByRef gv As GridView, colNumber As Integer, Optional referenceColNumber As Integer = -1) Dim curCell As New TableCell With {.Text = "."} Dim rowSpan As Integer = 1 Dim ColNumberToCheckText As Integer If referenceColNumber = -1 Then ColNumberToCheckText = colNumber Else ColNumberToCheckText = referenceColNumber End If Dim curText As String = "." For Each dr As GridViewRow In gv.Rows If dr.Cells(ColNumberToCheckText).Text <> curText Then 'curCell.Text Then If rowSpan > 1 Then curCell.RowSpan = rowSpan End If curCell = dr.Cells(colNumber) curText = dr.Cells(ColNumberToCheckText).Text rowSpan = 1 Else dr.Cells(colNumber).Visible = False rowSpan += 1 End If Next If rowSpan > 1 Then curCell.RowSpan = rowSpan End If End Sub End Class