private void btnSubmit_Click(object sender, EventArgs e) { if (!MyWinForm.ValidateIBControls(Controls)) { //MessageBox.Show("请输入用户名!"); return; } var ibCommandList = MyWinForm.Instance.AutoUpdateIBFormData(this.Controls); if (dlbUID.Text == "" || dlbUID.Text == "0") { //====插入数据的模式==== IBCommand command = ibCommandList[0]; dlbUID.Text = command.InsertedID.ToString();//为自增数据的控件赋值 ////收集数据到实体类中 User user = new User(); MyWinForm.DataMap.CollectData(user, this.Controls, true); //添加实体类到主窗体的网格控件中 Form1 form1 = this.Owner as Form1; form1.AddUserModel(user); } else { //====修改数据的模式===== Form1 form1 = this.Owner as Form1; //找到主窗体中的实体类对象 User user1 = form1.GetUserByID(int.Parse(dlbUID.Text)); //收集当前窗体的数据到实体类中,从而同步更新主窗体的数据 MyWinForm.DataMap.CollectData(user1, this.Controls, true); } MessageBox.Show("保存成功!"); }
/// <summary> /// 对数据控件实现双向绑定 /// </summary> /// <param name="controls">要搜索数据控件的窗体控件集合</param> public void BindDataControls(Control.ControlCollection controls) { var dataControls = MyWinForm.GetIBControls(controls); foreach (IDataControl control in dataControls) { //control.LinkObject 这里都是 "DataContext" object dataSource = GetInstanceByMemberName(control.LinkObject); if (control is TextBox) { ((TextBox)control).DataBindings.Add("Text", dataSource, control.LinkProperty); } else if (control is Label) { ((Label)control).DataBindings.Add("Text", dataSource, control.LinkProperty); } else if (control is ListBox) { ((ListBox)control).DataBindings.Add("SelectedValue", dataSource, control.LinkProperty, false, DataSourceUpdateMode.OnPropertyChanged); } else if (control is DateTimePicker) { ((DateTimePicker)control).DataBindings.Add("Value", dataSource, control.LinkProperty, false, DataSourceUpdateMode.OnPropertyChanged); } else { //自定义处理控件类型 BindDataControl(control, dataSource, control.LinkProperty); } } }
public PageConfig() { InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("分页设置"); numericUpDown1.Value = (decimal)INI.GetPerPage(); MyTip.Set(label1, "设为 0 则不进行分页。"); }
public DataView() { InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("数据"); conA = MyDB.GetAccessConnection(AccessPath); conS = MyDB.GetSqlServerConnection("127.0.0.1", "111", "Northwind"); Catalog(); }
public Main() { InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("快捷命令"); process = new Process(); CmdTxtPath = INI.Root + @"\Backup\Commands.txt"; LoadCommands(); }
public Groups() { InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("日记本"); M = MyModel.GetInstance(Global.con); LB = new MyListBox(listBox1, "select * from DiaryGroups order by GroupOrder", "GroupName", "GroupID", Global.con, true); table = LB.DataTable; ToAdd(); }
public Groups() { InitializeComponent(); M = MyModel.GetInstance(Global.con); FM = new MyWinForm(this); LB = new MyListBox(listBox1, "select * from LabelGroups where LocationID=" + LocationID + " order by GroupOrder", "GroupName", "GroupID", Global.con, true); table = LB.DataTable; FM.SetDefaultStyle("标签分组 >> 地点:" + M.GetLocationNameByID(LocationID)); ToAdd(); }
public Locations() { InitializeComponent(); M = MyModel.GetInstance(Global.con); FM = new MyWinForm(this); FM.SetDefaultStyle("当前地点:" + M.GetLocationNameByID(INI.GetLocationID())); LB = new MyListBox(listBox1, "select * from LabelLocations order by LocationOrder", "LocationName", "LocationID", Global.con, true); table = LB.DataTable; ToAdd(); }
public LabelsUpdate(object GroupID) { this.GroupID = GroupID; InitializeComponent(); M = MyModel.GetInstance(Global.con); FM = new MyWinForm(this); LocationID = INI.GetLocationID(); FM.SetDefaultStyle("标签 >> 地点:" + M.GetLocationNameByID(LocationID)); LoadList(); DefineView(); }
private void MvvmForm_Load(object sender, EventArgs e) { var ibControls = MyWinForm.GetIBControls(this.Controls); ControlCollection coll = new ControlCollection(this); foreach (IDataControl ctr in ibControls) { coll.Add(ctr as Control); } BindDataControls(coll); }
public SelectDB(CentralControl CentralForm) { this.CentralForm = CentralForm; InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("选择数据库"); listBox1.Items.Clear(); foreach (FileInfo file in new DirectoryInfo(INI.Root).GetFiles("*.mdb")) { listBox1.Items.Add(file.Name); } }
public Labels(Form LoginForm = null) { this.LoginForm = LoginForm; M = MyModel.GetInstance(Global.con); InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("标签簿 >> 地点:" + M.GetLocationNameByID(INI.GetLocationID())); if (LoginForm == null) { button4.Enabled = false; } DefineView(); }
public Records(Form LoginForm = null) { this.LoginForm = LoginForm; M = MyModel.GetInstance(Global.con); InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("日记本"); if (LoginForm == null) { button6.Enabled = false; } DefineView(); }
public BindBox() { InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("选择"); conA = MyDB.GetAccessConnection(AccessPath); conS = MyDB.GetSqlServerConnection("127.0.0.1", "111", "Northwind"); CBB = new MyComboBox(comboBox1, "select CustomerID,ContactName from Customers", "ContactName", "CustomerID", conA); LB = new MyListBox(listBox1, "select CustomerID,ContactName from Customers", "CustomerID", "ContactName", conA); CLB = new MyCheckedListBox(checkedListBox1, "select CustomerID,ContactName from Customers", "ContactName", "CustomerID", conA); //checkedListBox1.Items.Add("selection1", true);//添加选中状态的项 }
public Notes(Form LoginForm = null) { this.LoginForm = LoginForm; M = MyModel.GetInstance(Global.con); InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("笔记本"); if (LoginForm == null) { button6.Enabled = false; } MyTip.Set(label1, "点击清空筛选"); DefineView(); }
public Form1() { InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("Test"); con = MyDB.GetAccessConnection(AccessPath); cmd.Connection = con; cmd.CommandText = "select EmployeeID as ID,LastName+FirstName as 姓名,TitleOfCourtesy as 尊称 from Employees"; adapter = new OleDbDataAdapter(cmd); adapter.Fill(dataset, "Tab"); table = dataset.Tables["Tab"]; BindDataToGVX(); BindDataToComboX(); }
public Maintenance(CentralControl CentralForm) { this.CentralForm = CentralForm; InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("软件维护"); if (Global.con == null) { groupBox1.Enabled = false; } else { M = MyModel.GetInstance(Global.con); } }
public Timer() { InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("Timer"); timer = new System.Windows.Forms.Timer(); timer.Tick += timer_Tick; timer.Interval = 10; timer.Enabled = true; //timer.Start(); //============================ timer2 = new System.Windows.Forms.Timer(); timer2.Interval = 1; timer2.Tick += timer2_Tick; gun = new MyScanGun("COM3", "9600");//根据实际情况设置 if (!gun.Open()) { return; } timer2.Start(); }
public Records(Form LoginForm = null) { this.LoginForm = LoginForm; InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("纪念簿"); if (LoginForm == null) { button5.Enabled = false; } M = MyModel.GetInstance(Global.con); LB = new MyListBox(listBox2, "select * from Anniversaries order by MonthN,DayN,ID", "Title", "ID", Global.con, true); table = LB.DataTable; ToAdd(); if (M.CountAnniRecords() != 0)//有数据 { row = M.GetAnnInfoByID(M.GetNearestDateID()).Rows[0]; LB.SelectedValue = row["ID"]; label2.Text = "最近的纪念日:"; label4.Text = row["Title"] + "," + row["MonthN"] + "月" + row["DayN"] + "日。"; } }
public Login() { InitializeComponent(); FM = new MyWinForm(this); FM.SetDefaultStyle("Windows助手"); }
private void MvvmForm_Load(object sender, EventArgs e) { var ibControls = MyWinForm.GetIBControls(this.Controls); BindDataControls(ibControls); }