/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/purchasing/forecast.aspx.vb
179 строк
6 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
Imports System.IO Imports sharedClasses.dbFunctions Partial Class Common_schedule Inherits System.Web.UI.Page Private db As New SqlFunctions Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then fromDate.Text = Date.Today.ToString("yyyy-MM-dd") toDate.Text = Date.Today.AddDays(4).ToString("yyyy-MM-dd") End If message.Text = "" Dim sql As New StringBuilder Dim header As String = GetHeaderList(fromDate.Text, toDate.Text) 'message.Text = header sql.Append("SELECT * FROM ( ") sql.Append("SELECT ") sql.Append("Department, ") sql.Append("[date] + '|' + DAyNoNight + '|' + LineNoMan as TP, ") sql.Append("Qty ") sql.Append("FROM UserModules.[user].WORKING_SCHEDULE_AND_MANPOWER ") sql.Append(") as SourceTAble pivot (MAX(QTY) FOR TP IN ( ") sql.Append(header) sql.Append(")) as PivotTAble ") schedule.DataSource = db.GetData(sql.ToString) Try schedule.DataBind() Catch ex As Exception End Try End Sub Private Function GetHeaderList(_fromDate As String, _toDate As String) As String Dim header As New StringBuilder Dim f As Date = Date.ParseExact(_fromDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) Dim t As Date = Date.ParseExact(_toDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) Do If header.Length > 0 Then header.Append(",") header.AppendLine("[" & f.ToString("yyyy-MM-dd") & "|Day|Line],") header.AppendLine("[" & f.ToString("yyyy-MM-dd") & "|Day|Man],") header.AppendLine("[" & f.ToString("yyyy-MM-dd") & "|Night|Line],") header.AppendLine("[" & f.ToString("yyyy-MM-dd") & "|Night|Man]") f = f.AddDays(1) Loop While f <= t Return header.ToString End Function Private headerLabels As New Hashtable Protected Sub schedule_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles schedule.RowDataBound Dim i As Integer = 0 If e.Row.RowType = DataControlRowType.Header Then For Each cell As TableCell In e.Row.Cells headerLabels.Add(i, cell.Text) i += 1 Next End If If e.Row.RowType = DataControlRowType.DataRow Then For Each cell As TableCell In e.Row.Cells If i <> 0 Then cell.Attributes.Add("key", e.Row.Cells(0).Text & "|" & headerLabels(i)) cell.Attributes.Add("tid", "478") cell.CssClass = "click" End If i += 1 Next End If If e.Row.RowType = DataControlRowType.Footer Then e.Row.Cells(0).Text = "Total" For Each cell As TableCell In e.Row.Cells cell.Attributes.Add("key", e.Row.Cells(0).Text & "|" & headerLabels(i)) i += 1 Next End If End Sub Protected Sub Page_SaveStateComplete(sender As Object, e As EventArgs) Handles Me.SaveStateComplete Dim i As Integer = 0 Dim row1 = New GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal) Dim row2 = New GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal) For Each cell As TableCell In schedule.HeaderRow.Cells Dim c1 As New TableCell With {.Text = headerLabels(i).split("|")(0)} row1.Cells.Add(c1) If i > 0 Then Dim c2 As New TableCell With {.Text = headerLabels(i).split("|")(1)} row2.Cells.Add(c2) cell.Text = headerLabels(i).split("|")(2) Else Dim c2 As New TableCell With {.Text = " "} row2.Cells.Add(c2) cell.Text = " " End If i += 1 Next 'row1.Cells(0).RowSpan = 3 colSpan(row1) colSpan(row2) schedule.HeaderRow.Cells.RemoveAt(0) row2.Cells.RemoveAt(0) row1.Cells(0).RowSpan = 3 CType(schedule.Controls(0), Table).Rows.AddAt(0, row2) CType(schedule.Controls(0), Table).Rows.AddAt(0, row1) If isExcelDownload Then ExcelDownloadSub(schedule, "[WORKING SCHEDULE ]" & DateTime.Now.ToString) End If End Sub Private Sub colSpan(ByRef r As GridViewRow) Dim curtext As String = "" Dim curCell As TableCell = Nothing Dim span As Integer = 1 For Each c As TableCell In r.Cells c.Style.Add("text-align", " center") c.Style.Add("border", " 1px solid white") If curtext <> c.Text Then curtext = c.Text curCell = c span = 1 Else span += 1 curCell.ColumnSpan = span c.ColumnSpan = 100 End If Next Dim i As Integer = 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 End Sub Private isExcelDownload As Boolean = False Protected Sub ExcelDownload_Click(sender As Object, e As ImageClickEventArgs) Handles ExcelDownload.Click isExcelDownload = True End Sub Sub ExcelDownloadSub(ByVal gv As GridView, ByVal filename As String) Response.Clear() Response.Buffer = True Response.AddHeader("content-disposition", "attachment;filename=" & filename & ".xls") Response.ContentType = "application/vnd.xls" Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8") EnableViewState = False Response.Charset = "utf-8" Dim myCItrad As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US", True) gv.AllowSorting = False gv.AllowPaging = False Dim sw As StringWriter = New StringWriter(myCItrad) Dim hw As HtmlTextWriter = New HtmlTextWriter(sw) gv.RenderControl(hw) Response.Write(sw.ToString) 'Response.Write(sw.ToString) Response.End() End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub End Class