 |
|
การเขียนโปรแกรมที่มี User ใช้ หลาย ๆ คน นั้น อยากทราบแนวทางในการเขียนครับว่าควรคำนึงถึงอะไรบ้างครับ |
|
 |
|
|
 |
 |
|
โดยส่วนตัวผมมองว่า Database ตัวไหน หรือโปรแกรมที่ใช้เขียน ตัวไหน
ไม่สำคัญเท่าการออกแบบ Database ให้ใช้ได้ครอบคลุมทุกส่วนงานครับ
User ใช้ หลาย ๆ คนพร้อมกันนั้น โดยส่วนใหญ่มักจะให้ server เป็นตัวจัดการ Database (เท่าที่เห็นๆมานะครับ)
จึงไม่น่าจะมีปัญหา
แต่ก็อย่างว่าแหละครับขึ้นอยู่กับว่าออกแบบ Database ยังไง
ทุกวันนี้ผมยังสงสัยอยู่เลยว่าบางโปรแกรมแยกข้อมูล customer กับ suplier ออกจากกัน
ทั้งๆที่บางครั้งมันก็คือคนๆเดียวกันนั่นเอง(ทั้งนี้ก็เพื่อให้สะดวกต่องานหลายๆด้านนั่นเอง)
|
 |
 |
 |
 |
Date :
2016-07-07 13:42:01 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ คุณ lamaka.tor แสดงว่าโปรแกรมกับ Database ที่เราใช้พัฒนาโปรแกรมนั้นไม่เกี่ยวกับว่า User จะใช้กี่คน แต่อยู่ที่การออกแบบฐานข้อมูลเป็นหลักนะครับ
ขอบคุณอีกครั้งครับ
|
 |
 |
 |
 |
Date :
2016-07-07 13:51:35 |
By :
noonk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเกี่ยวกับ User สำหรับผมมีแค่สิทธิ์การใช้งานครับ
ถ้าเราออกแบบ สิทธิ์การใช้งาน ดีๆจะมองเห็นว่าข้อมูลหนึ่งมีไม่กี่คนหร่อกที่ใช้ร่วมกันจริงๆ
ข้อมูลที่ผมจะแยกออกแบบก็จะเป็นพวก ข้อมูลเสถียร ข้อมูลผันแปร ผมใช้ 2 ตัวนี้แยกแยะความละเอียดอ่อนของข็อมูลครับ
ปล. เอาไรมากกับผมไม่ได้หร่อกครับ ผมมันแค่นักวิทย์ หลักการจริงๆของโปรแกรมเมอร์มือนโปรจริงอาจจะไม่เป็นแบบนี้ก็ได้ครับ
|
 |
 |
 |
 |
Date :
2016-07-07 14:04:44 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อย่ามองที่ User เพียงอย่างเดียวครับ ในที่นี้ผมยกตัวอย่างเช่นเรื่อง Transaction ที่เข้ามาติดต่อกับ Database ว่าเยอะแค่ไหน ถ้าเยอะมากๆ Sql 2008 Express อย่าลืม ว่า มันรองรับได้แค่ 10 GB ถ้ามี Transaction เยอะรับไม่ไหวแน่ๆ Log เต็ม ทั้งนี้ทั้งนั้นมันก็ขึ้นอยู่ว่าคุณ จัดการ Database ดีแค่ไหน เช่นการจัดการเรื่อง Shrink Log ต่างๆนาๆ หรือแม้กระทั้ง การกำหนด Recovery Type ตั้งแต่สร้าง Database ก็มีผลกับการเก็บ Log ของ Database ไหนจะเรื่อง Host อีก พูดแล้วก็ยาว ไปดีกว่า อิอิ
|
ประวัติการแก้ไข 2016-07-07 16:11:12
 |
 |
 |
 |
Date :
2016-07-07 16:10:25 |
By :
taotechnocom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
@noon & TOR_CHEMISTRY
ผมให้พวกคุณเดาใจของผม (ด้วย Screen ตัวอย่าง และ SourceCode) ว่าผมต้องการอะไร?

อันนี้เป็น Source code เต็มของหน้าจอจากรูปภาพด้านบน และผมแถม Comment เอาไว้ด้วย
Code (VB.NET)
Public Class usrCtrSales3
Private bsSales As New BindingSource 'เก็บข้อมูลรายละเอียดการขาย (Item1, Item2, Item3, ...)
Private Sub usrCtrProduct_Load(sender As Object, e As EventArgs) Handles Me.Load
dgvSaleItems.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
dgvSaleItems.Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
dgvSaleItems.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
dgvSaleItems.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
Call MakeDataTableDEMO_Data()
End Sub
Private Sub MakeDataTableDEMO_Data()
Dim dtSales As New DataTable
dtSales.Columns.Add("Part_NO", GetType(String))
dtSales.Columns.Add("Part_Desc", GetType(String))
dtSales.Columns.Add("xQTY", GetType(Double))
dtSales.Columns.Add("xPrice", GetType(Double))
dtSales.Columns.Add("xTotal", GetType(Double))
dtSales.Columns.Add("xDiscount", GetType(Double))
dtSales.Rows.Add(New Object() {"P-001", "สินค้าตัวอย่าง1", 2, 50, 100, 0})
dtSales.Rows.Add(New Object() {"P-002", "สินค้าตัวอย่าง2", 5, 30, 150, 0})
dtSales.Rows.Add(New Object() {"P-003", "สินค้าตัวอย่าง3", 4, 6, 24, 0})
dtSales.AcceptChanges() 'Commit Change.
bsSales.DataSource = dtSales
SetDGVInfo(bsSales)
End Sub
Private Sub SetDGVInfo(ByVal bs As BindingSource)
dgvSaleItems.AutoGenerateColumns = False
dgvSaleItems.Columns(0).DataPropertyName = "Part_NO"
dgvSaleItems.Columns(1).DataPropertyName = "Part_Desc"
dgvSaleItems.Columns(2).DataPropertyName = "xQTY"
dgvSaleItems.Columns(3).DataPropertyName = "xPrice"
dgvSaleItems.Columns(4).DataPropertyName = "xTotal"
dgvSaleItems.Columns(5).DataPropertyName = "xDiscount"
dgvSaleItems.DataSource = bsSales
End Sub
'กลับไปก่อนหน้า
Private Sub BacktoPanelHead()
pnlDetail1.Visible = False
pnlDetail2.Visible = False
pnlHead.Visible = True
pnlDetail2.Dock = DockStyle.Bottom
pnlDetail1.Dock = DockStyle.Bottom
pnlHead.Dock = DockStyle.Fill
End Sub
'คลิ๊กปุ่ม เพิ่มข้อมูล
Private Sub tsbAction_Click(sender As Object, e As EventArgs) Handles tsbAdd.Click
Actions("A")
End Sub
'คลิ๊กปุ่มแก้ไขข้อมูล
Private Sub tsbEdit_Click(sender As Object, e As EventArgs) Handles tsbEdit.Click
Actions("E")
End Sub
'RowState (A/E/D)
Private Sub Actions(ByVal mode As String)
pnlDetail1.Visible = True
pnlDetail2.Visible = False
pnlHead.Visible = False
pnlDetail1.Dock = DockStyle.Fill
pnlDetail2.Dock = DockStyle.None
pnlHead.Dock = DockStyle.None
lblActions.Text = If(mode = "A", "เพิ่มข้อมูล", "แก้ไขข้อมูล")
If mode = "E" Then
'Binding to ALL TextBox
For i As Integer = 0 To Me.Controls.Count - 1
'Binding To TextBox Control
'Binding to ComboBox Control
'and so on.
Next
Else 'Edit Mode
'Reset All TextBox/ComboBox/etc...
mduControlManager.GetAllControl(pnlDetail1, GetType(WL_Controls.usrCtrlTextBox)).ToList().ForEach(Sub(x) DirectCast(x, WL_Controls.usrCtrlTextBox).ResetValue())
mduControlManager.GetAllControl(pnlDetail1, GetType(WL_Controls.usrCtrComboBox)).ToList().ForEach(Sub(x) DirectCast(x, WL_Controls.usrCtrComboBox).ResetValue())
End If
End Sub
'กลับไปก่อนหน้า
Private Sub tsbBack_Click(sender As Object, e As EventArgs) Handles tsbBack.Click
'ถ้าไม่มีการใช้ BindingSource (Me.dgvSaleItems.Rows.Clear())
BacktoPanelHead()
End Sub
Private Sub dgvSaleItems_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles dgvSaleItems.EditingControlShowing
'TODO
'More...
End Sub
Private Sub dgvSaleItems_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles dgvSaleItems.CellValidating
'Clear All error message.
dgvSaleItems.Rows(e.RowIndex).ErrorText = String.Empty
If dgvSaleItems.Rows(e.RowIndex).IsNewRow Then 'มีอยู่ 1 แถวและไม่มีอะไรเลย
Exit Sub 'Return 'Exist Sub
End If
If dgvSaleItems.CurrentCell.IsInEditMode Then
If e.ColumnIndex = 0 Then
dgvSaleItems.Rows(e.RowIndex).Cells(1).Value = Guid.NewGuid()
dgvSaleItems.Rows(e.RowIndex).Cells(2).Value = 1.0
dgvSaleItems.Rows(e.RowIndex).Cells(3).Value = 200.0
dgvSaleItems.Rows(e.RowIndex).Cells(4).Value = 200.0
dgvSaleItems.Rows(e.RowIndex).Cells(5).Value = 0.0
End If
End If
If e.ColumnIndex > 1 Then 'Column 2 is readonly (array zero base.)
Dim newDouble As Double
If Not Double.TryParse(If(e.FormattedValue = String.Empty, 0, e.FormattedValue.ToString()), newDouble) OrElse newDouble < 0 Then
e.Cancel = True
Me.dgvSaleItems.Rows(e.RowIndex).ErrorText = "ต้องป้อนเป็นตัวเลขเท่านั้น"
End If
End If
End Sub
'คำนวณ รวมเงิน = จำนวน x ราคา/หน่วย
Private Sub dgvSaleItems_CellValidated(sender As Object, e As DataGridViewCellEventArgs) Handles dgvSaleItems.CellValidated
If Not dgvSaleItems.CurrentRow.IsNewRow Then
If e.ColumnIndex > 1 Then
dgvSaleItems.Rows(e.RowIndex).Cells(4).Value = dgvSaleItems.Rows(e.RowIndex).Cells(2).Value * dgvSaleItems.Rows(e.RowIndex).Cells(3).Value
End If
End If
End Sub
Private Sub dgvSaleItems_CellMouseClickORDbClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvSaleItems.CellMouseClick, dgvSaleItems.CellMouseDoubleClick
Try
If String.IsNullOrEmpty(dgvSaleItems.Rows(e.RowIndex).Cells(0).Value) Then
dgvSaleItems.CurrentCell = dgvSaleItems(0, e.RowIndex)
Return
End If
Dim col As Short = dgvSaleItems.CurrentCell.ColumnIndex
If dgvSaleItems.Columns(col).Visible = False OrElse dgvSaleItems.Columns(col).ReadOnly = True OrElse dgvSaleItems.Columns(col).CellType.ToString = "System.Windows.Forms.DataGridViewImageCell" Then
For iSub As Short = col To dgvSaleItems.ColumnCount - 1
col = (col + 1) Mod dgvSaleItems.ColumnCount
If dgvSaleItems.Columns(col).Visible = True AndAlso dgvSaleItems.Columns(col).ReadOnly = False AndAlso _
dgvSaleItems.Columns(col).CellType.ToString <> "System.Windows.Forms.DataGridViewImageCell" Then
Exit For
End If
Next
End If
dgvSaleItems.CurrentCell = dgvSaleItems.CurrentRow.Cells(col)
Catch ex As Exception
'log hear.
End Try
End Sub
'
'ถ้าอยู่ใน EditMode มันจะไม่เข้ามาที่อีเวนต์นี้
Private Sub dgvSaleItems_KeyDown(sender As Object, e As KeyEventArgs) Handles dgvSaleItems.KeyDown
If dgvSaleItems.CurrentCell.ColumnIndex = 0 AndAlso e.KeyCode = Keys.Right Then
e.Handled = True
dgvSaleItems.CurrentCell = dgvSaleItems(2, dgvSaleItems.CurrentCell.RowIndex)
End If
If dgvSaleItems.CurrentCell.ColumnIndex = 2 AndAlso e.KeyCode = Keys.Left Then
e.Handled = True
dgvSaleItems.CurrentCell = dgvSaleItems(0, dgvSaleItems.CurrentCell.RowIndex)
End If
If dgvSaleItems.CurrentCell.ColumnIndex > 1 AndAlso (e.KeyCode = Keys.Down OrElse e.KeyCode = Keys.Enter) Then
e.Handled = True
If dgvSaleItems.CurrentCell.RowIndex + 2 >= dgvSaleItems.Rows.Count Then
dgvSaleItems.CurrentCell = dgvSaleItems(0, dgvSaleItems.Rows.Count - 1)
Else
If dgvSaleItems.CurrentCell.ColumnIndex = 5 Then
dgvSaleItems.CurrentCell = dgvSaleItems.Rows(dgvSaleItems.CurrentCell.RowIndex).Cells(0)
Else
dgvSaleItems.CurrentCell = dgvSaleItems.Rows(dgvSaleItems.CurrentCell.RowIndex).Cells(dgvSaleItems.CurrentCell.ColumnIndex + 1)
End If
End If
End If
End Sub
'แสดงลำดับที่ของแถว 1, 2, 3, ...
'
Private Sub dgvSaleItems_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgvSaleItems.RowPostPaint
Try
Dim length As String = dgvSaleItems.RowCount.ToString.Length
Dim row As String = (e.RowIndex + 1).ToString.PadLeft(length, " ")
Dim size As SizeF = e.Graphics.MeasureString("ก", Me.Font)
Using b As SolidBrush = New SolidBrush(dgvSaleItems.RowHeadersDefaultCellStyle.ForeColor)
e.Graphics.DrawString(row, dgvSaleItems.DefaultCellStyle.Font, b, e.RowBounds.Location.X + ((dgvSaleItems.RowHeadersWidth - size.Width) / 2) + 1, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
End Using
Catch
'logger error.
End Try
End Sub
'ทดสอบการลบข้อมูลโดยการ Double Click ณ. หัวแถวนั้นฯ (ทดสอบ)
Private Sub dgvSaleItems_RowHeaderMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvSaleItems.RowHeaderMouseDoubleClick
If bsSales.Position <> -1 Then
DirectCast(bsSales.DataSource, DataTable).Rows(bsSales.Position).Delete() 'By Ref
End If
End Sub
'ตรวจสอบ RowState (FoxPro ทำได้ตั้งแต่ 20 ปีที่แล้ว ทั้ง Field State และ Row State)
Private Sub btnGetRowState_Click(sender As Object, e As EventArgs) Handles btnGetRowState.Click
Dim dt = DirectCast(bsSales.DataSource, DataTable)
If dt IsNot Nothing Then
Dim rowStateDeleted = dt.GetChanges(DataRowState.Deleted)
Dim rowStateModifyed = dt.GetChanges(DataRowState.Modified)
Dim rowStateAdded = dt.GetChanges(DataRowState.Added)
'F9 Break
If "ขนขึ้น" <> "หอยไม่ขึ้น" Then
End If
End If
End Sub
End Class
|
 |
 |
 |
 |
Date :
2016-07-07 16:19:54 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บางคนเขียนโปรแกรมมาทั้งชีวิต
--- แต่ไม่เคยมีคำถามให้กับตัวเอง (นึกคำถามไม่ออก)
บางคนทำงานมาทั้งชีวิต
--- แต่ก็นึกคำถามให้กับตัวเองไม่ออก (ต้องให้คนอื่นถามให้)
...
...
...
ความต้องการของธุรกิจ (มันไม่ได้มาจากหัวสมองของโปรแกรมเมอร์)
|
 |
 |
 |
 |
Date :
2016-07-07 16:43:47 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมให้คุณกลับไปคิดเอาเอง
หัวสมองระดับโปรแกรมเมอร์ มันก็แค่ต้นทุนแฝงในบริษัทนั้นฯ
--- พนักงานรายวัน เรารับรู้ได้ถึงค่าใช้จ่าย/รายได้ (บวกเข้าไปในค่าแรง เพื่อคำนวณต้นทุน[โดยประมาณ])
ุ้ถ้าคุณพอมีเวลาก็ลองทบทวนดู (สิ่งไหนดีและมีประโยขน์ก็ไม่ควรเก็บเอามาคิดให้เปลืองสมอง)
ป.ล มันก็ไม่ใช่เรื่องง่ายฯ ผมปิดงบการเงินไม่เป็นแต่ผมอยากจะให้สมุห์บัญชียกมือไหว้ผม ฉันใดก็ฉันนั้น
|
 |
 |
 |
 |
Date :
2016-07-07 17:43:23 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบพระคุณทุกความเห็นครับ สำหรับคุณ "หน้าฮี" นั้น ไม่ธรรมดาเลย ระดับเทพเหมือนกัน ว่าแต่ว่าต้องทำความเข้าใจสำนวนของท่านหน่อยว่าท่านกำลังสื่อสารเรื่องอะไรออกมา ที่ผ่านมาพอได้ติดตามกระทู้/คำตอบของท่าน ... ท่านออกจะถนัดและเชี่ยวชาญ VB 6.0 มาก
ขอบพระคุณอีกครั้งครับ คุณ : taotechnocom / lamaka.tor / "หน้าฮี"
noon
|
 |
 |
 |
 |
Date :
2016-07-08 06:56:02 |
By :
noonk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คห.5 โปรแกรมคงจะสับสน รหัสสินค้า ช่องที่ 4-5 แน่ ๆ เลยครับ
|
 |
 |
 |
 |
Date :
2016-07-08 07:52:14 |
By :
ละอ่อน |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2016-07-11 07:39:26 |
By :
noonk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เมื่อวานผมถามเด็กว่า จะไปไหนล่ะ?
เด็กข้างบ้าน : ผมจะไปเรียนต่อครับ (ม.ในกรุงเทพมหานครนี่แหละ)
ผมก็ถามต่อ : เรียนสาขาอะไรล่ะ
เด็กข้างบ้าน : คอมพิวเตอร์ครับ
ผมคิดอยู่ในใจ : ผมเคยให้โอกาสเขา มานั่งเรียนกับผมซิ ทุกความรู้ที่ผมมีอยู่ผมให้หมดเลย (แต่ไม่มา)
ผมคิดแบบนี้นะถูกไม่รู้ผิดไม่รู้ "ความรู้แคบฯในมหาวิทยาลัย"
--- มันก็ไม่แตกต่างกับสุนัขตัวหนึ่งที่คุ้ยถังขยะเพื่อประทังชีวิตของมันก็เท่านั้นเองครับ


Code (VB.NET)
Imports System.Windows.Forms
Public Class myTextBoxColumn : Inherits System.Windows.Forms.DataGridViewColumn
Private mAllowDecimal As Boolean
Private mAllowMinus As Boolean
Private mAllowDateSep As Boolean
Private mAllowInputType As String
Private mMaxInputlength As Integer
Private mCelltemplate As myTextBoxCell
#Region "Properties"
Public Property AllowInputType As String
Get
Return mAllowInputType
End Get
Set(value As String)
mAllowInputType = value
mCelltemplate.AllowInputType = value
End Set
End Property
Public Property AllowDecimal() As Boolean
Get
Return mAllowDecimal
End Get
Set(ByVal value As Boolean)
mAllowDecimal = value
mCelltemplate.AllowDecimal = value
End Set
End Property
Public Property AllowMinus() As Boolean
Get
Return mAllowMinus
End Get
Set(ByVal value As Boolean)
mAllowMinus = value
mCelltemplate.AllowMinus = value
End Set
End Property
Public Property AllowDateSep() As Boolean
Get
Return mAllowDateSep
End Get
Set(ByVal value As Boolean)
mAllowDateSep = value
mCelltemplate.AllowDateSep = value
End Set
End Property
Public Property MaxInputLength() As Integer
Get
Return mMaxInputlength
End Get
Set(ByVal value As Integer)
mMaxInputlength = value
mCelltemplate.MaxInputLength = value
End Set
End Property
#End Region
Public Sub New()
MyBase.New(New myTextBoxCell)
mCelltemplate = MyBase.CellTemplate
End Sub
Public Sub New(ByVal dec As Boolean, ByVal min As Boolean, ByVal sep As Boolean, ByVal len As Integer, ByVal inputType As String)
MyBase.New(New myTextBoxCell(dec, min, sep, len, inputType))
mCelltemplate = MyBase.CellTemplate
Me.mAllowDecimal = dec
Me.mAllowMinus = min
Me.mAllowDateSep = sep
Me.mMaxInputlength = len
Me.mAllowInputType = inputType
End Sub
Public Overrides Property CellTemplate() As DataGridViewCell
Get
Return MyBase.CellTemplate
End Get
Set(ByVal value As DataGridViewCell)
MyBase.CellTemplate = value
End Set
End Property
''' <summary>
''' Fixed Bug Design time. lose value
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Overrides Function Clone() As Object
Dim myClone As myTextBoxColumn = CType(MyBase.Clone, myTextBoxColumn)
myClone.AllowDecimal = AllowDecimal
myClone.AllowMinus = AllowMinus
myClone.AllowDateSep = AllowDateSep
myClone.MaxInputLength = MaxInputLength
myClone.AllowInputType = AllowInputType
Return myClone
End Function
End Class
Code (VB.NET)
Imports System.Windows.Forms
Public Class myTextBoxEditingControl : Inherits DataGridViewTextBoxEditingControl
Private Const mDec As Char = "."
Private Const mMinus As Char = "-"c
Private Const mDateSep As Char = "/"c
Private mAllowDecimal As Boolean
Private mAllowMinus As Boolean
Private mAllowDateSep As Boolean
Private mMaxInputlength As Integer
Private mAllowInputType As String
#Region "Properties"
Public Property AllowInputType() As String
Get
Return mAllowInputType
End Get
Set(ByVal value As String)
mAllowInputType = value
End Set
End Property
Public Property AllowDecimal() As Boolean
Get
Return mAllowDecimal
End Get
Set(ByVal value As Boolean)
mAllowDecimal = value
End Set
End Property
Public Property AllowMinus() As Boolean
Get
Return mAllowMinus
End Get
Set(ByVal value As Boolean)
mAllowMinus = value
End Set
End Property
Public Property AllowDateSep() As Boolean
Get
Return mAllowDateSep
End Get
Set(ByVal value As Boolean)
mAllowDateSep = value
End Set
End Property
Public Property MaxInputLength() As Integer
Get
Return mMaxInputlength
End Get
Set(ByVal value As Integer)
mMaxInputlength = value
End Set
End Property
#End Region
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal dec As Boolean, ByVal min As Boolean, ByVal sla As Boolean, ByVal len As Integer, ByVal inputType As String)
MyBase.New()
mAllowDecimal = dec
mAllowMinus = min
mAllowDateSep = sla
mMaxInputlength = len
mAllowInputType = inputType
End Sub
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
Select Case AllowInputType.ToLower()
Case "integer"
If e.KeyChar < "0" Or e.KeyChar > "9" Then
If AscW(e.KeyChar) = Keys.Back Then 'Backspace
e.Handled = False
Else
e.Handled = True
End If
Else
MyBase.OnKeyPress(e)
End If
Case "double"
If e.KeyChar < "0" Or e.KeyChar > "9" Then
If AscW(e.KeyChar) = Keys.Back Then
e.Handled = False
Else
If e.KeyChar = "." And MyBase.Text.Contains(".") = False Then
e.Handled = False
ElseIf e.KeyChar = "-" And MyBase.Text.Contains("-") = False Then
e.Handled = False
Else
e.Handled = True
End If
End If
Else
MyBase.OnKeyPress(e)
End If
End Select
End Sub
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If Me.Text.Length >= mMaxInputlength Then
e.Handled = True
Else
MyBase.OnKeyDown(e)
End If
End Sub
End Class
Code (VB.NET)
Imports System.Windows.Forms
Public Class myTextBoxEditingControl : Inherits DataGridViewTextBoxEditingControl
Private Const mDec As Char = "."
Private Const mMinus As Char = "-"c
Private Const mDateSep As Char = "/"c
Private mAllowDecimal As Boolean
Private mAllowMinus As Boolean
Private mAllowDateSep As Boolean
Private mMaxInputlength As Integer
Private mAllowInputType As String
#Region "Properties"
Public Property AllowInputType() As String
Get
Return mAllowInputType
End Get
Set(ByVal value As String)
mAllowInputType = value
End Set
End Property
Public Property AllowDecimal() As Boolean
Get
Return mAllowDecimal
End Get
Set(ByVal value As Boolean)
mAllowDecimal = value
End Set
End Property
Public Property AllowMinus() As Boolean
Get
Return mAllowMinus
End Get
Set(ByVal value As Boolean)
mAllowMinus = value
End Set
End Property
Public Property AllowDateSep() As Boolean
Get
Return mAllowDateSep
End Get
Set(ByVal value As Boolean)
mAllowDateSep = value
End Set
End Property
Public Property MaxInputLength() As Integer
Get
Return mMaxInputlength
End Get
Set(ByVal value As Integer)
mMaxInputlength = value
End Set
End Property
#End Region
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal dec As Boolean, ByVal min As Boolean, ByVal sla As Boolean, ByVal len As Integer, ByVal inputType As String)
MyBase.New()
mAllowDecimal = dec
mAllowMinus = min
mAllowDateSep = sla
mMaxInputlength = len
mAllowInputType = inputType
End Sub
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
'If e.KeyChar < "0"c OrElse e.KeyChar > "9"c Then
' If e.KeyChar <> Convert.ToChar(System.Windows.Forms.Keys.Back) Then
' If mAllowDecimal AndAlso e.KeyChar = mDec _
' OrElse mAllowMinus AndAlso e.KeyChar = mMinus _
' OrElse mAllowDateSep AndAlso e.KeyChar = mDateSep Then
' MyBase.OnKeyPress(e)
' Else
' e.Handled = True
' End If
' Else
' MyBase.OnKeyPress(e)
' End If
'Else
' MyBase.OnKeyPress(e)
'End If
Select Case AllowInputType.ToLower()
Case "integer"
If e.KeyChar < "0" Or e.KeyChar > "9" Then
If AscW(e.KeyChar) = Keys.Back Then 'Backspace
e.Handled = False
Else
e.Handled = True
End If
Else
MyBase.OnKeyPress(e)
End If
Case "double"
If e.KeyChar < "0" Or e.KeyChar > "9" Then
If AscW(e.KeyChar) = Keys.Back Then
e.Handled = False
Else
If e.KeyChar = "." And MyBase.Text.Contains(".") = False Then
e.Handled = False
ElseIf e.KeyChar = "-" And MyBase.Text.Contains("-") = False Then
e.Handled = False
Else
e.Handled = True
End If
End If
Else
MyBase.OnKeyPress(e)
End If
End Select
End Sub
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If Me.Text.Length >= mMaxInputlength Then
e.Handled = True
Else
MyBase.OnKeyDown(e)
End If
End Sub
End Class
|
 |
 |
 |
 |
Date :
2016-07-11 08:04:44 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO15 พึ่งเขียนเมื่อเช้านี้ (หามาจากเวปไซต์ของฝรั่งเขา)
--- นี่มันก็ไม่ได้ให้มานะ (แถม BUG ตัวเบ่อเร่อ)
Code (VB.NET)
''' <summary>
''' Fixed Bug Design time. lose value
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Overrides Function Clone() As Object
Dim myClone As myTextBoxColumn = CType(MyBase.Clone, myTextBoxColumn)
myClone.AllowDecimal = AllowDecimal
myClone.AllowMinus = AllowMinus
myClone.AllowDateSep = AllowDateSep
myClone.MaxInputLength = MaxInputLength
myClone.AllowInputType = AllowInputType
Return myClone
End Function
ผมยังทำไม่เสร็จ แต่ให้รุ่นน้องเอาไปใช้งานจริง (Design Screen)
--- จะเพิ่มเติม/แก้ไข ค่อยทำในภายหลัง ก็ว่ากันไป
คุณลองพิจารณาดู Screen Design

แบบนี้ผมก็เขียนโปรแกรมตายห่ากันพอดี (หลายร้อยหน้าจอ)
|
 |
 |
 |
 |
Date :
2016-07-11 08:22:38 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยอมรับว่า "ไม่ธรรมดา" จริง ๆ เลยครับ
|
 |
 |
 |
 |
Date :
2016-07-11 13:03:02 |
By :
noon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|