เวลาผมเขียน winapp ผมไม่เขียนให้มันผูกกัน ให้ยุ่งยากครับ
แต่ ผมจะใช้ list เก็บ form pointer แยกเป็น form ไปเลยครับ
เวลา create new form ก็แค่ส่ง พารามิเตอร์ เข้าไปในแต่ละ form
ทำงานอิสระ แยกกันไปเลย
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim db As New dbBigDataContext
Dim kUnit = db.Units
Dim frmUnitCode As New BasicCode2(kUnit)
frmUnitCode.Show()
End Sub
End Class
Public Class BasicCode2
Private kTargetTable As Data.Linq.Table(Of Units)
Sub New(ByVal kTableName As Data.Linq.Table(Of Units))
kTargetTable = kTableName
Call LoadData()
End Sub
Private Sub LoadData()
'/// ตรงนี้ยังติดปัญหาเรื่อง การเปลียนค่าชื่อตารางทีต้องการ ในที่นี้คือ Units เป็นอืน ๆ เช่น Categories , Colors ว่าจะทำอย่างไร ///
Dim kBasicCodes = From k In kTargetTable Select k.UnitCode, k.Description
Order By UnitCode
'code C R U D
dgvBasicCode.DataSource = kBasicCodes.ToList()
End Sub
End Class
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Vol.SampleForm
{
public partial class frmBase : Form
{
private string childObj;
public frmBase(string _childObj)
{
InitializeComponent();
this.childObj = _childObj;
this.Text = _childObj;
this.label1.Text = _childObj;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.button1.Click += new EventHandler(Save);
}
private void Save(object sender, EventArgs e)
{
string objectToInstantiate = "Vol.SampleForm."+this.childObj+ ", Vol.SampleForm";
var objectType = Type.GetType(objectToInstantiate);
var instantiatedObject = Activator.CreateInstance(objectType) as ITestClass;
// set a property value
instantiatedObject.Name = "Test Name";
// get a property value
var name = instantiatedObject.Name;
// call a method - this outputs "My name is MyNewTestClass"
//Console.Write(instantiatedObject.DoSpecialThing());
MessageBox.Show(instantiatedObject.DoSpecialThing());
}
private void button2_Click(object sender, EventArgs e)
{
string objectToInstantiate = "Vol.SampleForm." + this.childObj + ", Vol.SampleForm";
var objectType = Type.GetType(objectToInstantiate);
var instantiatedObject = Activator.CreateInstance(objectType) as ITestClass;
// set a property value
instantiatedObject.Name = "Test Name";
// get a property value
var name = instantiatedObject.Name;
// call a method - this outputs "My name is MyNewTestClass"
//Console.Write(instantiatedObject.DoSpecialThing());
MessageBox.Show(instantiatedObject.Save());
}
}
public interface ITestClass
{
int Id { get; set; }
string Name { get; set; }
string DoSpecialThing();
string Save();
}
public class Product : ITestClass
{
public int Id { get; set; }
public string Name { get; set; }
public string DoSpecialThing()
{
return "My name is Product";
}
public string Save()
{
//Code บลาๆๆๆๆๆๆ
return "Save Product เด้อ";
}
}
public class Unit : ITestClass
{
public int Id { get; set; }
public string Name { get; set; }
public string Save()
{
//Code บลาๆๆๆๆๆๆ
return "Save Unit เด้อ";
}
public string DoSpecialThing()
{
return "My name is Unit";
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Vol.SampleForm
{
public partial class frmBase : Form
{
private string childObj;
public frmBase(string _childObj)
{
InitializeComponent();
this.childObj = _childObj;
this.Text = _childObj;
this.label1.Text = _childObj;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.button1.Click += new EventHandler(Save);
}
private void Save(object sender, EventArgs e)
{
string objectToInstantiate = "Vol.SampleForm."+this.childObj+ ", Vol.SampleForm";
var objectType = Type.GetType(objectToInstantiate);
var instantiatedObject = Activator.CreateInstance(objectType) as ITestClass;
// set a property value
instantiatedObject.Details.Name = "Test Name";
// get a property value
var name = instantiatedObject.Details.Name;
// call a method - this outputs "My name is MyNewTestClass"
//Console.Write(instantiatedObject.DoSpecialThing());
MessageBox.Show(instantiatedObject.DoSpecialThing());
}
private void button2_Click(object sender, EventArgs e)
{
string objectToInstantiate = "Vol.SampleForm." + this.childObj + ", Vol.SampleForm";
var objectType = Type.GetType(objectToInstantiate);
var instantiatedObject = Activator.CreateInstance(objectType) as ITestClass;
// set a property value
instantiatedObject.Details.Name = "Test Name";
// get a property value
var name = instantiatedObject.Details.Name;
// call a method - this outputs "My name is MyNewTestClass"
//Console.Write(instantiatedObject.DoSpecialThing());
MessageBox.Show(instantiatedObject.Save());
}
}
public interface ITestClass
{
TempDetails Details { get; set; }
string DoSpecialThing();
string Save();
}
public class Product : ITestClass
{
public TempDetails Details { get; set; } = new TempDetails();
public string DoSpecialThing()
{
return "My name is Product";
}
public string Save()
{
//Code บลาๆๆๆๆๆๆ
return "Save Product เด้อ";
}
}
public class Unit : ITestClass
{
public TempDetails Details { get; set; } = new TempDetails();
public string Save()
{
//Code บลาๆๆๆๆๆๆ
return "Save Unit เด้อ";
}
public string DoSpecialThing()
{
return "My name is Unit";
}
}
public class TempDetails
{
public int Id { get; set; }
public string Name { get; set; }
}
}
public class Product : ITestClass
{
public int Id { get; set; }
public string Name { get; set; }
public string DoSpecialThing()
{
return "My name is Product";
}
public string Save()
{
//Code บลาๆๆๆๆๆๆ
return "Save Product เด้อ";
}
}
public class Product : ITestClass
{
public int Id { get; set; }
public string Name { get; set; }
public string DoSpecialThing()
{
return "My name is Product";
}
public string Save()
{
//Code บลาๆๆๆๆๆๆ
return "Save Product เด้อ";
}
}
public class Product : ITestClass
{
public int Id { get; set; }
public string Name { get; set; }
public string DoSpecialThing()
{
return "My name is Product";
}
public string Save()
{
//Code บลาๆๆๆๆๆๆ
MessageBox.Show("Save Product เด้อ");
return "Save Product เด้อ";
}
}
public class Product : ITestClass
{
public int Id { get; set; }
public string Name { get; set; }
public string DoSpecialThing()
{
return "My name is Product";
}
public string Save()
{
//Code บลาๆๆๆๆๆๆ
MessageBox.Show("Save Product เด้อ");
return "Save Product เด้อ";
}
}