/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/app_code/edgrid.vb
147 строк
6 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
Imports System.ServiceModel Imports System.ServiceModel.Activation Imports sharedClasses.dbFunctions '<ServiceContract(Namespace:="Services", SessionMode:=SessionMode.Allowed)> '<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> '<ServiceBehaviorAttribute(InstanceContextMode:=InstanceContextMode.PerSession)> <ServiceContract(Namespace:="Services")> <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> Public Class edGrid ' To use HTTP GET, add <WebGet()> attribute. (Default ResponseFormat is WebMessageFormat.Json) ' To create an operation that returns XML, ' add <WebGet(ResponseFormat:=WebMessageFormat.Xml)>, ' and include the following line in the operation body: ' WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml" <OperationContract()> Public Function GetControl(tid As Integer, field As String, type As String, data As String) As String Dim config As edGridNamespace.tableConfig = HttpContext.Current.Session("config_" & tid) Dim cntrl As System.Web.UI.WebControls.WebControl = Nothing Dim paramRow As Data.DataRow = config.GetParamRow(field) 'Dim fieldId As String = config.GetParam() Select Case type Case "DROPDOWNLIST" If Not IsNothing(paramRow) Then Dim sqlf As New SqlFunctions cntrl = New DropDownList With _ {.DataSource = sqlf.GetData("select fieldValue, fieldText from UserModules.dbo.FieldsValues where FieldId = " & paramRow("id") & " and Enabled = 'Y'"), _ .DataValueField = "fieldValue", .DataTextField = "fieldText"} cntrl.DataBind() Try CType(cntrl, DropDownList).Items.FindByText(data).Selected = True Catch ex As Exception End Try End If Case "TEXTBOX" cntrl = New TextBox With {.TextMode = TextBoxMode.MultiLine} Case "CHECKBOX" If data = "Y" Then cntrl = New CheckBox With {.Checked = True} Else cntrl = New CheckBox With {.Checked = False} End If Case Else cntrl = New TextBox End Select cntrl.ID = "foo" Dim myCItrad As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("EN-US", True) Dim sw As IO.StringWriter = New IO.StringWriter(myCItrad) Dim hw As HtmlTextWriter = New HtmlTextWriter(sw) cntrl.RenderControl(hw) 'Return "<input type='text' id='foo' value='" & config.dbTableName & "'></input>" Return sw.ToString End Function <OperationContract()> Public Function SaveData(tid As String, rowId As String, field As String, type As String, data As String) As String Dim config As edGridNamespace.tableConfig = HttpContext.Current.Session("config_" & tid) Dim sqlf As New SqlFunctions Dim com As New Data.SqlClient.SqlCommand field = field.Replace("-", "").Replace("'", "") com.CommandText = "UPDATE UserModules.[user]." & config.dbTableName & " SET [" & field & "]=@value WHERE id=@id" With com.Parameters Select Case type Case "TEXTBOX" Case "CHECKBOX" .AddWithValue("value", IIf(data = "true", "Y", "N")) .AddWithValue("id", rowId) Case Else .AddWithValue("value", data) .AddWithValue("id", rowId) End Select End With If sqlf.NonQuery(com) > 0 Then config.SaveHistory(com.Parameters, rowId, "USER", "IP") Select Case type Case "TEXTBOX" Dim literalText As String = "" For Each stringChar As Char In data If stringChar = Chr(10) Then literalText &= "<br>" Else literalText &= stringChar End If Next Return literalText Case "CHECKBOX" If data = "true" Then Return "<input id=""srv"" type=""checkbox"" checked=""true"" onclick=""return false"">" Else Return "<input id=""srv"" type=""checkbox"" onclick=""return false"">" End If End Select Return data Else Return "Error" End If 'Return tableName & "|" & rowId & "|" & fieldName & "|" & data End Function <OperationContract()> Public Function InsertOrUpdate(tid As String, key As String, data As String) As String Dim config As edGridNamespace.tableConfig = HttpContext.Current.Session("config_" & tid) Dim sqlf As New SqlFunctions Dim com As New Data.SqlClient.SqlCommand com.CommandText = "UPDATE UserModules.[user].WORKING_SCHEDULE_AND_MANPOWER SET [qty]=@value WHERE " & _ " DEPARTMENT = @DEPARTMENT AND " & _ " [DATE] = @DATE AND DAYNoNIGHT=@DAYNoNIGHT AND LINENoMAN=@LINENoMAN" With com.Parameters .AddWithValue("value", data) .AddWithValue("DEPARTMENT", key.Split("|")(0)) .AddWithValue("DATE", key.Split("|")(1)) .AddWithValue("DAYNoNIGHT", key.Split("|")(2)) .AddWithValue("LINENoMAN", key.Split("|")(3)) End With If sqlf.NonQuery(com) > 0 Then Return data Else com.CommandText = "INSERT INTO UserModules.[user].WORKING_SCHEDULE_AND_MANPOWER ([qty], DEPARTMENT ,[DATE],DAYNoNIGHT,LINENoMAN) VALUES " & _ "(@value, @DEPARTMENT ,@DATE, @DAYNoNIGHT, @LINENoMAN) " If sqlf.NonQuery(com) > 0 Then Return data Else Return "Error" End If End If End Function ' Add more operations here and mark them with <OperationContract()> End Class