/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/ga/month_report_new.aspx.vb
384 строки
14 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
Imports sharedClasses.dbFunctions Partial Class GA_month_report_new Inherits System.Web.UI.Page Private sqlf As New SqlFunctions Private groups As New Collection Private Structure Group Dim Title As String Dim Command As String Dim StartIndex As Integer Dim Len As Integer Dim FoldingRange As IEnumerable(Of Integer) Dim GroupingRange As IEnumerable(Of Integer) End Structure Private Function IsGroupingRange(i As Integer, gg As Collection) As Boolean Dim result As Boolean = False For Each g As Group In gg If g.GroupingRange.Contains(i) Then result = True End If Next Return result End Function Private Function IsFoldingRange(i As Integer, gg As Collection) As Boolean Dim result As Boolean = False For Each g As Group In gg If g.FoldingRange.Contains(i) Then result = True End If Next Return result End Function Private Function GetGroupByIndex(idx As Integer, gg As Collection) As Group For Each g As Group In gg If g.StartIndex = idx Then Return g End If Next 'Nothing does not works Return Nothing End Function Private a As sharedClasses.Auth.auth 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_PreLoad(sender As Object, e As EventArgs) Handles Me.PreLoad End Sub Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load authorize("SSO") 'TODO: HARDCODING!! If a.userId <> "sergei.kim" And a.userId <> "i.krivokon" Then Response.Clear() Response.Write("NO ACCESS, CONTACT MI") Response.End() Return End If lblMessage.Text = a.userId 'Preparing ranges for colums folding Dim group As New Group With { .Title = "Worked days", .Command = "work_days", .StartIndex = 3, .Len = 8, .GroupingRange = Enumerable.Range(4, 7), .FoldingRange = Enumerable.Range(3, 7) } groups.Add(group) group = New Group With { .Title = "Total payment", .Command = "total_payment", .StartIndex = 21, .Len = 3, .GroupingRange = Enumerable.Range(22, 2), .FoldingRange = Enumerable.Range(21, 2) } groups.Add(group) group = New Group With { .Title = "Advance payment", .Command = "advance_payment", .StartIndex = 24, .Len = 3, .GroupingRange = Enumerable.Range(25, 2), .FoldingRange = Enumerable.Range(24, 2) } groups.Add(group) group = New Group With { .Title = "Final payment", .Command = "final_payment", .StartIndex = 27, .Len = 3, .GroupingRange = Enumerable.Range(28, 2), .FoldingRange = Enumerable.Range(27, 2) } groups.Add(group) 'Define MROT parameter values depending on selected year If Not Page.IsPostBack Then month.DataBind() End If Dim year As String = month.SelectedValue.Substring(0, 4) Select Case year Case "2025" : lblMrotNogiVRot.Text = "33600.00" Case "2026" : lblMrotNogiVRot.Text = "40639.50" Case Else : lblMrotNogiVRot.Text = "NDF" End Select lblFormula.Text = "TAX 30.8 = (Gross salary-" + lblMrotNogiVRot.Text + ")*0.158 + " + lblMrotNogiVRot.Text + "*0.308 // 1.5 MROT = " End Sub Protected Sub report_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles report.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If CType(e.Row.DataItem, Data.DataRowView)("CONFIRMED") = 1 Then e.Row.Style.Add("background", "LightGreen") End If End If End Sub Protected Sub report_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles report.RowCreated If ExcelDownload Then Exit Sub End If '------------------ Dim g As New Group Dim i As Integer = 0 Dim gg As New Group For Each cc As TableCell In e.Row.Cells g = GetGroupByIndex(i, groups) If g.Title <> "" Then gg = g End If If IsFoldingRange(i, groups) Then cc.CssClass = gg.Command End If i += 1 Next If e.Row.RowType = DataControlRowType.Header Then Dim grid As GridView grid = CType(sender, GridView) Dim subHeader As GridViewRow subHeader = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert) i = -1 For Each c As TableCell In e.Row.Cells i += 1 If IsGroupingRange(i, groups) Then Continue For End If Dim cc As New TableCell cc.CopyBaseAttributes(c) g = GetGroupByIndex(i, groups) If g.Title <> "" Then StuffButtons(cc, g.Title, g.Command, g.Len) StuffScripts(phScripts, g.Command, g.Len) Else cc.Text = c.Text End If subHeader.Cells.Add(cc) Next For i = e.Row.Cells.Count - 1 To 0 Step -1 If Not IsGroupingRange(i, groups) And Not IsFoldingRange(i, groups) Then e.Row.Cells.RemoveAt(i) End If Next For Each cc In subHeader.Cells If cc.ColumnSpan = 0 Then cc.RowSpan = 2 End If Next report.Controls(0).Controls.AddAt(0, subHeader) End If End Sub Private Sub StuffScripts(ph As PlaceHolder, command As String, colSpan As Int16) Dim script As New StringBuilder With script .AppendLine(" <script type=""text/javascript"">") .AppendLine("$(document).ready(function () { ") .AppendLine(" $(""." + command + """).hide(); ") .AppendLine(" $(""." + command + "_header"").attr('colSpan', 1); ") .AppendLine(" $(""." + command + """).hide(); ") .AppendLine(" $(""#min_" + command + """).hide(); ") .AppendLine(" $(""#max_" + command + """).show(); ") .AppendLine("}); ") .AppendLine("$(""#min_" + command + """).on(""click"", function (event) {") .AppendLine("$(""." + command + """).fadeOut(); ") .AppendLine("$(""." + command + "_header"").attr('colSpan', 1);") .AppendLine("$(""." + command + """).fadeOut(); ") .AppendLine("$(""#min_" + command + """).hide(""slow""); ") .AppendLine("$(""#max_" + command + """).show(""slow""); ") .AppendLine(" }); ") .AppendLine(" $(""#max_" + command + """).on(""click"", function (event) {") .AppendLine("$(""." + command + """).fadeIn(); ") .AppendLine("$(""." + command + "_header"").attr('colSpan', " + colSpan.ToString + "); ") .AppendLine("$(""." + command + """).fadeIn(); ") .AppendLine("$(""#max_" + command + """).hide(""slow""); ") .AppendLine("$(""#min_" + command + """).show(""slow""); ") .AppendLine(" });") .AppendLine("</script>") End With Dim s As New Literal With { .Text = script.ToString } ph.Controls.Add(s) End Sub Private Sub StuffButtons(ByRef cc As TableCell, title As String, command As String, colspan As Integer) cc.ColumnSpan = colspan cc.CssClass = command + "_header" Dim btn_plus As New Image With { .ID = "max_" + command, .ImageUrl = "plus_square.png", .ClientIDMode = ClientIDMode.Static } cc.Controls.Add(btn_plus) Dim btn_minus As New Image With { .ID = "min_" + command, .ImageUrl = "minus_square.png", .ClientIDMode = ClientIDMode.Static } cc.Controls.Add(btn_minus) Dim br As New Literal With { .Text = "</br>" } cc.Controls.Add(br) Dim lbl As New Label With { .Text = title } cc.Controls.Add(lbl) cc.BackColor = Drawing.Color.DarkCyan End Sub Protected Sub Page_PreRenderComplete(sender As Object, e As EventArgs) Handles Me.PreRenderComplete Using sqlf Dim periodStart, periodEnd As String periodStart = Date.Parse(month.SelectedValue & "-01").ToString("yyyy-MM-dd") periodEnd = Date.Parse(month.SelectedValue & "-01").AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd") If sqlf.GetScalar("Select ISNULL(SUM(CONFIRMED), 0) FROM HR.dbo.TB_FN_DRIVERS_MONTHLY_PAYMENTS WHERE [MONTH]='" & month.SelectedValue & "'") = "0" Then 'Month not fixed yet, prepare reqltime report 'Updating period 'sqlf.NonQuery("UPDATE UserModules.[user].[DRIVER_DAILY] " & ' "SET PERIOD = '" & month.SelectedValue & "'" & ' "WHERE [DATE] BETWEEN '" & periodStart & "' AND '" & periodEnd & "'") report.DataSource = sdsReport Else ' month is fixed , taking data from table report.DataSource = sdsConfirmedReport End If lblPeriod.Text = periodStart & " / " & periodEnd report.DataBind() If ExcelDownload Then DoExcelDownload() End If End Using End Sub Sub DoExcelDownload() Response.Clear() ' Set the type and filename Response.AddHeader("content-disposition", "attachment;filename=drivers_monthly_" + month.SelectedValue.Replace("-", "") + ".xls") Response.Charset = "UTF-8" Response.ContentType = "application/vnd.xls" ' Add the HTML from the GridView to a StringWriter so we can write it out later Dim sw As System.IO.StringWriter = New System.IO.StringWriter Dim hw As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(sw) report.RenderControl(hw) ' Write out the data Dim htmlStart As New StringBuilder htmlStart.AppendLine("<!DOCTYPE html>") htmlStart.AppendLine("<html xmlns=""http: //www.w3.org/1999/xhtml"">") htmlStart.AppendLine("<head>") htmlStart.AppendLine("<meta charset=""UTF-8"">") htmlStart.AppendLine("</head>") htmlStart.AppendLine("<body>") Dim htmlEnd As New StringBuilder htmlEnd.AppendLine("</body>") htmlEnd.AppendLine("</html>") Response.Write(htmlStart.ToString) Response.Write(sw.ToString) Response.Write(htmlEnd.ToString) Response.End() End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub Protected Sub Page_SaveStateComplete(sender As Object, e As EventArgs) Handles Me.SaveStateComplete Try Dim ttlROw As GridViewRow = report.Rows(report.Rows.Count - 1) For Each c As TableCell In ttlROw.Cells c.Style.Add("background-color", "SteelBlue") c.Style.Add("color", "White") c.Style.Add("font-weight", "bold") Next ttlROw.Cells(0).ColumnSpan = 3 ttlROw.Cells(0).Text = "Total" ttlROw.Cells(0).HorizontalAlign = HorizontalAlign.Center ttlROw.Cells.RemoveAt(2) ttlROw.Cells.RemoveAt(1) Catch ex As Exception End Try End Sub Protected Sub refresh_Click(sender As Object, e As ImageClickEventArgs) Handles refresh.Click 'month.DataBind() End Sub Protected Sub confirm_Click(sender As Object, e As ImageClickEventArgs) Handles ibMonthConfirmation.Click Using sqlf Dim sql As New StringBuilder sql.AppendLine("DELETE From HR.dbo.TB_FN_DRIVERS_MONTHLY_PAYMENTS ") sql.AppendLine("Where month = '" & month.SelectedValue & "' ") sqlf.NonQuery(sql.ToString) sql.Clear() sql.AppendLine("INSERT ") sql.AppendLine("INTO HR.dbo.TB_FN_DRIVERS_MONTHLY_PAYMENTS ") sql.AppendLine("Select *, 1 as CONFIRMED, getdate() as UPDATED ") sql.AppendLine("From HR.dbo.FN_DRIVERS_MONTHLY_PAYMENTS ('" & month.SelectedValue & "', 40639.50, 0.308, 0.158, 0.13, 0.06, 0.05, 100000.00) ") sqlf.NonQuery(sql.ToString) End Using End Sub Protected Sub ImageButton1_Click(sender As Object, e As ImageClickEventArgs) Handles ibUndoMonthConfirmation.Click Using sqlf Dim sql As New StringBuilder sql.AppendLine("DELETE From HR.dbo.TB_FN_DRIVERS_MONTHLY_PAYMENTS ") sql.AppendLine("Where month = '" & month.SelectedValue & "' ") sqlf.NonQuery(sql.ToString) End Using End Sub Dim ExcelDownload As Boolean = False Protected Sub ibExcelDownload_Click(sender As Object, e As ImageClickEventArgs) Handles ibExcelDownload.Click ExcelDownload = True End Sub Protected Sub month_SelectedIndexChanged(sender As Object, e As EventArgs) Handles month.SelectedIndexChanged Dim m As String = month.SelectedValue If m < "2025-01" Then Response.Redirect("month_report.aspx?month=" + m) End If End Sub Protected Sub month_DataBound(sender As Object, e As EventArgs) Handles month.DataBound Try Dim m As String = Request.QueryString("month") If m <> "" Then month.SelectedValue = m End If Catch ex As Exception End Try End Sub End Class