Imports iMESExceptionManager Public Class frmStuBasisDef Inherits COM_Kit.frmDefTemplat '//Public Variables Public EditDataRow As DataRow Public DefMode As Integer = 0 '0. ADD, 1.Edit, 2. Copy Public PrivFunNo As String = defString '//Web Service相關變數 ' 2016 YF, Dim wsENT As New wsENT.wsENT Dim InXml As String Dim OutXml As String Dim strIdentity As String Dim strParameter As String Friend WithEvents Sex As Infragistics.Win.UltraWinEditors.UltraTextEditor Friend WithEvents lblStudentSex As Label Dim intDataStamp As Integer '紀錄DataStamp #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents txtDescription As System.Windows.Forms.RichTextBox Friend WithEvents lblDescription As System.Windows.Forms.Label Friend WithEvents lblStudentId As System.Windows.Forms.Label Friend WithEvents lblStudentName As System.Windows.Forms.Label Friend WithEvents lblSex As System.Windows.Forms.Label Friend WithEvents gbxStudentData As System.Windows.Forms.GroupBox Friend WithEvents txtStuBasisNo As Infragistics.Win.UltraWinEditors.UltraTextEditor Friend WithEvents txtStuBasisName As Infragistics.Win.UltraWinEditors.UltraTextEditor Friend WithEvents txtSex As Infragistics.Win.UltraWinEditors.UltraTextEditor Private Sub InitializeComponent() Dim Appearance1 As Infragistics.Win.Appearance = New Infragistics.Win.Appearance() Dim Appearance2 As Infragistics.Win.Appearance = New Infragistics.Win.Appearance() Dim Appearance3 As Infragistics.Win.Appearance = New Infragistics.Win.Appearance() Me.gbxStudentData = New System.Windows.Forms.GroupBox() Me.Sex = New Infragistics.Win.UltraWinEditors.UltraTextEditor() Me.lblStudentSex = New System.Windows.Forms.Label() Me.txtDescription = New System.Windows.Forms.RichTextBox() Me.lblDescription = New System.Windows.Forms.Label() Me.lblStudentId = New System.Windows.Forms.Label() Me.lblStudentName = New System.Windows.Forms.Label() Me.txtStuBasisNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor() Me.txtStuBasisName = New Infragistics.Win.UltraWinEditors.UltraTextEditor() CType(Me.gbxBasisData, System.ComponentModel.ISupportInitialize).BeginInit() Me.gbxStudentData.SuspendLayout() CType(Me.Sex, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.txtStuBasisNo, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.txtStuBasisName, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'gbxBasisData ' Me.gbxBasisData.Location = New System.Drawing.Point(12, 257) Me.gbxBasisData.Size = New System.Drawing.Size(512, 70) ' 'btnApply ' Me.btnApply.Location = New System.Drawing.Point(436, 336) ' 'btnConfirm ' Me.btnConfirm.Location = New System.Drawing.Point(248, 336) ' 'btnClose ' Me.btnClose.Location = New System.Drawing.Point(342, 336) ' 'gbxStudentData ' Me.gbxStudentData.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.gbxStudentData.Controls.Add(Me.Sex) Me.gbxStudentData.Controls.Add(Me.lblStudentSex) Me.gbxStudentData.Controls.Add(Me.txtDescription) Me.gbxStudentData.Controls.Add(Me.lblDescription) Me.gbxStudentData.Controls.Add(Me.lblStudentId) Me.gbxStudentData.Controls.Add(Me.lblStudentName) Me.gbxStudentData.Controls.Add(Me.txtStuBasisNo) Me.gbxStudentData.Controls.Add(Me.txtStuBasisName) Me.gbxStudentData.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.gbxStudentData.Location = New System.Drawing.Point(12, 8) Me.gbxStudentData.Name = "gbxStudentData" Me.gbxStudentData.Size = New System.Drawing.Size(512, 241) Me.gbxStudentData.TabIndex = 7 Me.gbxStudentData.TabStop = False Me.gbxStudentData.Text = "Student Data" ' 'Sex ' Appearance1.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer)) Me.Sex.Appearance = Appearance1 Me.Sex.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer)) Me.Sex.Location = New System.Drawing.Point(128, 88) Me.Sex.Name = "Sex" Me.Sex.Size = New System.Drawing.Size(154, 30) Me.Sex.TabIndex = 15 ' 'lblStudentSex ' Me.lblStudentSex.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblStudentSex.Location = New System.Drawing.Point(10, 88) Me.lblStudentSex.Name = "lblStudentSex" Me.lblStudentSex.Size = New System.Drawing.Size(112, 32) Me.lblStudentSex.TabIndex = 14 Me.lblStudentSex.Text = "Student Sex" Me.lblStudentSex.TextAlign = System.Drawing.ContentAlignment.TopRight ' 'txtDescription ' Me.txtDescription.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtDescription.Location = New System.Drawing.Point(126, 131) Me.txtDescription.Name = "txtDescription" Me.txtDescription.Size = New System.Drawing.Size(334, 67) Me.txtDescription.TabIndex = 2 Me.txtDescription.Text = "" ' 'lblDescription ' Me.lblDescription.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblDescription.Location = New System.Drawing.Point(56, 131) Me.lblDescription.Name = "lblDescription" Me.lblDescription.Size = New System.Drawing.Size(64, 14) Me.lblDescription.TabIndex = 13 Me.lblDescription.Text = "Description" Me.lblDescription.TextAlign = System.Drawing.ContentAlignment.TopRight ' 'lblStudentId ' Me.lblStudentId.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblStudentId.Location = New System.Drawing.Point(24, 24) Me.lblStudentId.Name = "lblStudentId" Me.lblStudentId.Size = New System.Drawing.Size(96, 32) Me.lblStudentId.TabIndex = 5 Me.lblStudentId.Text = "Student ID" Me.lblStudentId.TextAlign = System.Drawing.ContentAlignment.TopRight ' 'lblStudentName ' Me.lblStudentName.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblStudentName.Location = New System.Drawing.Point(8, 56) Me.lblStudentName.Name = "lblStudentName" Me.lblStudentName.Size = New System.Drawing.Size(112, 32) Me.lblStudentName.TabIndex = 9 Me.lblStudentName.Text = "Student Name" Me.lblStudentName.TextAlign = System.Drawing.ContentAlignment.TopRight ' 'txtStuBasisNo ' Appearance2.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer)) Me.txtStuBasisNo.Appearance = Appearance2 Me.txtStuBasisNo.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer)) Me.txtStuBasisNo.Location = New System.Drawing.Point(128, 24) Me.txtStuBasisNo.Name = "txtStuBasisNo" Me.txtStuBasisNo.Size = New System.Drawing.Size(152, 30) Me.txtStuBasisNo.TabIndex = 0 ' 'txtStuBasisName ' Appearance3.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer)) Me.txtStuBasisName.Appearance = Appearance3 Me.txtStuBasisName.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer)) Me.txtStuBasisName.Location = New System.Drawing.Point(128, 55) Me.txtStuBasisName.Name = "txtStuBasisName" Me.txtStuBasisName.Size = New System.Drawing.Size(152, 30) Me.txtStuBasisName.TabIndex = 1 ' 'frmStuBasisDef ' Me.ClientSize = New System.Drawing.Size(536, 381) Me.Controls.Add(Me.gbxStudentData) Me.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Name = "frmStuBasisDef" Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "ENT Student Define" Me.Controls.SetChildIndex(Me.btnClose, 0) Me.Controls.SetChildIndex(Me.btnConfirm, 0) Me.Controls.SetChildIndex(Me.btnApply, 0) Me.Controls.SetChildIndex(Me.gbxBasisData, 0) Me.Controls.SetChildIndex(Me.gbxStudentData, 0) CType(Me.gbxBasisData, System.ComponentModel.ISupportInitialize).EndInit() Me.gbxStudentData.ResumeLayout(False) Me.gbxStudentData.PerformLayout() CType(Me.Sex, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.txtStuBasisNo, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.txtStuBasisName, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub frmStuBasisDef_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Cursor.Current = Cursors.WaitCursor Select Case DefMode Case 0 Me.Text = Me.Text & "(ADD)" Case 1 Me.Text = Me.Text & "(EDIT)" Case 2 Me.Text = Me.Text & "(Copy)" Case Else Me.Text = Me.Text & "(Unknown)" End Select '做為MainForm判斷是否重新LoadData的依據 gReturnKeyValue = "" ' 2016 YF, wsENT.Url = LocalizeWebService(wsENT.Url.ToString) ' 2016 YF, wsENT.EnableDecompression = True If Not EditDataRow Is Nothing Then txtStuBasisNo.Text = EditDataRow.Item("StuBasisNo").ToString txtStuBasisName.Text = EditDataRow.Item("StuBasisName").ToString 'txtDescription是RichTextBox Control,因為TextBox無法正常顯示多行換行的資料 txtDescription.Text = EditDataRow.Item("Description").ToString End If If DefMode = 0 Or DefMode = 2 Then 'Add or Copy SetCreator(gUserNo) SetCreateDate(Now) ElseIf DefMode = 1 Then 'Edit txtStuBasisNo.ReadOnly = True SetCreator(EditDataRow.Item("Creator").ToString) SetCreateDate(Convert.ToDateTime(EditDataRow.Item("CreateDate"))) SetReviser(gUserNo) SetReviseDate(Now) intDataStamp = EditDataRow.Item("DataStamp") End If btnApplyEnabled = False '語系切換 Call ExeChangeResource(Me, gLanguageMode) ExeGroupControlPriv(Me, PrivFunNo) Cursor.Current = Cursors.Default End Sub Private Sub frmStuBasisDef_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated If DefMode = 0 Or DefMode = 2 Then txtStuBasisNo.Focus() Else txtStuBasisName.Focus() End If End Sub Protected Overrides Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click Try ' 调用funAddorEdit函数并将sender作为参数传递 Dim result As Integer = funAddorEdit(sender) ' 根据需要处理结果 If result = 0 Then ' 函数成功执行 Me.Close() Else ' 函数遇到错误或验证失败 End If Catch ex As Exception ' 处理意外错误 ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace) End Try End Sub Protected Overrides Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.Close() End Sub Protected Overrides Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Cursor.Current = Cursors.WaitCursor If funAddorEdit(sender) < 0 Then Exit Sub If DefMode = 0 Or DefMode = 2 Then txtStuBasisNo.Focus() Else txtStuBasisName.Focus() End If Cursor.Current = Cursors.Default btnApplyEnabled = False End Sub Private Sub frmStuBasisDef_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing ' 2016 YF, If Not wsENT Is Nothing Then wsENT.Dispose() End Sub #Region "Control KeyPress" Private Sub txtStuBasisNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStuBasisNo.Click txtStuBasisNo.SelectAll() End Sub Private Sub txtStuBasisNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStuBasisNo.Enter txtStuBasisNo.SelectAll() End Sub Private Sub txtStuBasisNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtStuBasisNo.KeyPress If e.KeyChar = Convert.ToChar(13) Then SendKeys.Send("{TAB}") End If End Sub Private Sub txtStuBasisNo_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStuBasisNo.Leave txtStuBasisNo.Text = UCase(txtStuBasisNo.Text) End Sub Private Sub txtStuBasisNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStuBasisNo.TextChanged btnApplyEnabled = True End Sub Private Sub txtStuBasisName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStuBasisName.Click txtStuBasisName.SelectAll() End Sub Private Sub txtStuBasisName_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStuBasisName.Enter txtStuBasisName.SelectAll() End Sub Private Sub txtStuBasisName_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtStuBasisName.KeyPress If e.KeyChar = Convert.ToChar(13) Then SendKeys.Send("{TAB}") End If End Sub Private Sub txtStuBasisName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStuBasisName.TextChanged btnApplyEnabled = True End Sub Private Sub txtDescription_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDescription.Click txtDescription.SelectAll() End Sub Private Sub txtDescription_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDescription.Enter txtDescription.SelectAll() End Sub Private Sub txtDescription_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDescription.TextChanged btnApplyEnabled = True End Sub #End Region #Region "Others" Private Function funAddorEdit(sender As Object) As Integer funAddorEdit = -1 '****************************************************************************** '1.基本檢查 '****************************************************************************** If txtStuBasisNo.Text = "" Then iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200001", "[%StuBasisNo%]"), MsgBoxStyle.Exclamation, Me.Text) txtStuBasisNo.Focus() Exit Function End If If txtStuBasisName.Text = "" Then iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200001", "[%StuBasisName%]"), MsgBoxStyle.Exclamation, Me.Text) txtStuBasisName.Focus() Exit Function End If If Sex.Text = "" Then iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200001", "[%Sex%]"), MsgBoxStyle.Exclamation, Me.Text) Sex.Focus() Exit Function End If '2. '****************************************************************************** '寫回資料庫 '****************************************************************************** Dim XmlDoc As New XmlDocument Try strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow()) strParameter = CombineXMLParameter("stubasisno", "StuBasisNo", "String", CInput(txtStuBasisNo.Text), "") strParameter = strParameter & CombineXMLParameter("stubasisname", "StuBasisName", "String", CInput(txtStuBasisName.Text), "") strParameter = strParameter & CombineXMLParameter("sex", "Sex", "String", CInput(Sex.Text), "") strParameter = strParameter & CombineXMLParameter("description", "Description", "String", CInput(txtDescription.Text), "") If DefMode = 0 Or DefMode = 2 Then 'Add or Copy strParameter = strParameter & CombineXMLParameter("creator", "Creator", "String", gUserNo, "") strParameter = strParameter & CombineXMLParameter("createdate", "CreateDate", "DateTime", Format(Now, "yyyy/MM/dd HH:mm:ss"), "") InXml = CombineXMLRequest(strIdentity, strParameter) ' 2016 YF, OutXml = ws_21685.AddStuBasis(InXml) OutXml = InvokeSrv("SXS.ws_21685.AddStuBasis", InXml) Else '修改 strParameter = strParameter & CombineXMLParameter("issuestate", "IssueState", "String", EditDataRow.Item("IssueState").ToString, "") ' 增加Datastamp strParameter += CombineXMLParameter("datastamp", "Datastamp", "Integer", intDataStamp, "") InXml = CombineXMLRequest(strIdentity, strParameter) ' 2016 YF, OutXml = wsENT.EditStuBasis(InXml) OutXml = InvokeSrv("SXS.ws_21685.EditStuBasis", InXml) End If XmlDoc.LoadXml(OutXml) If ChkExecutionSuccess(XmlDoc) Then gReturnKeyValue = txtStuBasisNo.Text funAddorEdit = 0 If sender.Equals(btnApply) Then intDataStamp += 1 End If Else ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc)) End If Catch ex As Exception 'MsgBox("Unexpected Error. Add or Edit ENT StuBasis Failed!," & e1.Message, MsgBoxStyle.Exclamation) ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace) End Try XmlDoc = Nothing End Function Private Sub lblStuBasisNo_Click(sender As Object, e As EventArgs) Handles lblStudentId.Click End Sub Private Sub lblDescription_Click(sender As Object, e As EventArgs) Handles lblDescription.Click End Sub Private Sub UltraTextEditor1_ValueChanged(sender As Object, e As EventArgs) Handles Sex.ValueChanged End Sub #End Region End Class