private void opslaan2() { foreach (CheckBox control in panel1.Controls) { CheckBox checkbox = ((CheckBox)control); if (checkbox.Checked) { //count++; List1.Add(checkbox.Name.ToString()); } } string myConnectionString = "server=192.168.2.156;uid=newuser;" + "pwd=test;database=chadder"; var conn = new MySql.Data.MySqlClient.MySqlConnection(); conn.ConnectionString = myConnectionString; conn.Open(); MySqlCommand cmd; foreach (string naam in List1) { cmd = new MySqlCommand($"INSERT INTO privileges(naam)VALUE('{naam}')", conn); cmd.ExecuteNonQuery(); } conn.Close(); }
private void OnAddNew(string Name) { List1.Add(new Person { Name = Name }); PersonModel = new Person(); }
public DoubleReferenceClass(SimpleObject obj1, SimpleObject obj2) : this() { Object1 = obj1; Object2 = obj2; List1.Add(obj1); List1.Add(obj2); }
private void ListView_Drop2(object sender, DragEventArgs e) { if (list == 2) { if (e.Data.GetDataPresent("myFormat")) { Model.Softver soft = e.Data.GetData("myFormat") as Model.Softver; if (SaveList2 == null) { SaveList2 = new List <Softver>(); foreach (Softver s in List2) { if (s != null) { SaveList2.Add(s); } } } List2.Remove(soft); List1.Add(soft); SaveList2.Remove(soft); /* SaveList2 = new List<Softver>(); * foreach (Softver s in List2) * if (s != null) * SaveList2.Add(s); * Search = ""; * just_do_it();*/ } } }
public VMTest1() { List1.Add(new KeyValuePair <string, string>("aaa", "111")); List1.Add(new KeyValuePair <string, string>("bbb", "222")); List1.Add(new KeyValuePair <string, string>("ccc", "333")); List1.Add(new KeyValuePair <string, string>("ddd", "444")); List1SelectedValue = "222"; UserList = new BindingList <MUser>(); UserList.Add(new MUser() { USER_ID = "a1", UNIQUE_SEQ = 1, REG_DATE = DateTime.Now.AddDays(-1) }); UserList.Add(new MUser() { USER_ID = "b2", NAME = "고길동", UNIQUE_SEQ = 2, REG_DATE = DateTime.Now.AddDays(-2) }); UserList.Add(new MUser() { USER_ID = "c3", NAME = "홍길홍", UNIQUE_SEQ = 3, REG_DATE = DateTime.Now.AddDays(-3) }); UserList.Add(new MUser() { USER_ID = "d4", NAME = "길길동", UNIQUE_SEQ = 4, REG_DATE = DateTime.Now.AddDays(-4) }); UserList.Add(new MUser() { USER_ID = "e5", NAME = "동길동", UNIQUE_SEQ = 5, REG_DATE = DateTime.Now.AddDays(-5) }); }
private void Execute_button_creature(object o) { My_thread temp = new My_thread(My_Thread); _ThreadHive.Add(temp); List1.Add(temp); OnPropertyChanged(nameof(List1)); }
public View_Model_Main() { s = new Semaphore(1, 0xFFFFF, "My_SEMAPHORE"); My_thread temp = new My_thread(My_Thread); _ThreadHive.Add(temp); List1.Add(temp); }
public Task TransformAsync(object item, TypeAccessor typeAccessor, IGraphRequestContext context) { if (item.GetType() == typeof(MockModel1)) { List1.Add((MockModel1)item); } if (item.GetType() == typeof(MockModel2)) { List2.Add((MockModel2)item); } if (item.GetType() == typeof(MockModel3)) { List3.Add((MockModel3)item); } if (item.GetType() == typeof(MockModel4)) { List4.Add((MockModel4)item); } return(Task.CompletedTask); }
public DoubleReferenceClass(SimpleObject obj) : this() { Object1 = obj; Object2 = obj; List1.Add(obj); }
public void AddItem(T item) { _List.Add(item); }
public VMTest1() { var list = new CustomList <MAdmin>(); list.Add(new MAdmin() { ADMIN_SEQ = 1, ADMIN_NAME = "관리자1" }); list.Add(new MAdmin() { ADMIN_SEQ = 2, ADMIN_NAME = "관리자2" }); list.Add(new MAdmin() { ADMIN_SEQ = 3, ADMIN_NAME = "관리자3" }); list.Add(new MAdmin() { ADMIN_SEQ = 4, ADMIN_NAME = "관리자4" }); AdminList = list; Button1Command.ExecuteTargets += Button1Command_ExecuteTargets; Button2Command.ExecuteTargets += Button2Command_ExecuteTargets; UserListAddCommand.ExecuteTargets += () => { //non ThreadSafe 로 오류 발생 return(Task.Run(() => { UserList.Add(new MUser() { isNew = true, isEdit = true }); UserList.Add(new MUser() { isNew = true, isEdit = true }); UserList.Add(new MUser() { isNew = true, isEdit = true }); UserList.Add(new MUser() { isNew = true, isEdit = true }); UserList.Add(new MUser() { isNew = true, isEdit = true }); })); //UI 쓰레드를 통해 추가 return(Application.Current.Dispatcher.InvokeAsync(() => { UserList.Add(new MUser() { isNew = true, isEdit = true }); UserList.Add(new MUser() { isNew = true, isEdit = true }); UserList.Add(new MUser() { isNew = true, isEdit = true }); UserList.Add(new MUser() { isNew = true, isEdit = true }); UserList.Add(new MUser() { isNew = true, isEdit = true }); }).Task); }; UserListDeleteCommand.ExecuteTargets += (item) => { //원래대로라면 UI ThreadSafe 오류 발생함 return(Task.Run(() => { if (item == null) { return; } if (item.isNew) { UserList.Remove(item); } else { item.isDelete = true; } //UserList.OnNotifyCollectionChanged(); })); }; /* * return Task.Run(async () => * { * if (item == null) * return; * * if (item.isNew) * { * await Application.Current.Dispatcher.InvokeAsync(() => * { * UserList.Remove(item); * }); * } * else * item.isDelete = true; * }); * }; */ List1.Add(new KeyValuePair <string, string>("aaa", "111")); List1.Add(new KeyValuePair <string, string>("bbb", "222")); List1.Add(new KeyValuePair <string, string>("ccc", "333")); List1.Add(new KeyValuePair <string, string>("ddd", "444")); List1SelectedValue = "222"; UserList.Add(new MUser() { USER_ID = "a1", UNIQUE_SEQ = 1, REG_DATE = DateTime.Now.AddDays(-1), ADMIN_SEQ = 1 }); UserList.Add(new MUser() { USER_ID = "b2", NAME = "고길동", UNIQUE_SEQ = 2, REG_DATE = DateTime.Now.AddDays(-2) }); UserList.Add(new MUser() { USER_ID = "c3", NAME = "홍길홍", UNIQUE_SEQ = 3, REG_DATE = DateTime.Now.AddDays(-3) }); UserList.Add(new MUser() { USER_ID = "d4", NAME = "길길동", UNIQUE_SEQ = 4, REG_DATE = DateTime.Now.AddDays(-4) }); UserList.Add(new MUser() { USER_ID = "e5", NAME = "동길동", UNIQUE_SEQ = 5, REG_DATE = DateTime.Now.AddDays(-5) }); foreach (var item in UserList) { item.Initialize(); } }
void Init() { //initialize cs1, cs2 to suit the database connection details. try { string servername1 = server1.ToString(); string uname1 = uid1.ToString(); string pass1 = pwd1.ToString(); string dbName1 = dbname1.ToString(); string tbl1 = table1.ToString(); string tbl2 = table2.ToString(); conn1 = new MySqlConnection(cs1); conn1.Open(); conn2 = new MySqlConnection(cs2); conn2.Open(); tbl1 = "abc"; tbl2 = "def"; // Load target list's ids and timestamps string stmt1 = "SELECT seriennummer, DATE_FORMAT(fdate, '%Y-%M-%D %H:%i:%s') FROM " + tbl1; MySqlCommand cmd1 = new MySqlCommand(stmt1, conn1); List& lt; IdTsEntry> A = new List & lt; IdTsEntry> (); using (MySqlDataReader reader = cmd1.ExecuteReader()) { //while (reader.Read()) //{ // I assume the fields are set to NOT NULL // A.Add(new IdTsEntry() // { // fid = reader.GetInt64(0), // fdate = reader.GetString(1) // }); //} while (reader.Read()) { // I assume the fields are set to NOT NULL A.Add(new IdTsEntry() { fid = reader.IsDBNull(0) ? -1L : reader.GetInt64(0), fdate = reader.IsDBNull(1) ? "" : reader.GetString(1) }); } } // Load source list's ids and timestamps string stmt2 = "SELECT fid, DATE_FORMAT(fdate, '%Y-%M-%D %H:%i:%s') FROM " + tbl2; MySqlCommand cmd2 = new MySqlCommand(stmt2, conn2); List< IdTsEntry> B = new List & lt; IdTsEntry> (); using (MySqlDataReader reader = cmd2.ExecuteReader()) { while (reader.Read()) { // I assume the fields are set to NOT NULL B.Add(new IdTsEntry() { fid = reader.GetInt64(0), fdate = reader.GetString(1) }); } } // Filter lists List< Int64> List1 = new List & lt; Int64> (); List< Int64> List2 = new List & lt; Int64> (); foreach (IdTsEntry b in B) { var a = A.FirstOrDefault(e = > e.fid.Equals(b.fid)); if (a == null) { List2.Add(b.fid); // b.id not in A -&gt; new row } else if (!a.fdate.Equals(b.fdate)) { List1.Add(b.fid); // b.id in A but other timestamp -&gt; altered row } } // Update altered rows //string ct1 = "SELECT variante,charge,DATE_FORMAT(fdate, '%Y-%M-%D %H:%i:%s') FROM " + tbl2 + " WHERE fid = {0}"; //string ct2 = "UPDATE " + tbl1 + " SET variante = @val1,charge = @val2, fdate = @val3 WHERE seriennummer = {0}"; foreach (Int64 id in List1) { // Read all entry values into parameters // cmd1.CommandText = String.Format(ct1, id); cmd1.CommandText = "SELECT variante,charge,DATE_FORMAT(fdate, '%Y-%M-%D %H:%i:%s') FROM " + tbl2 + " WHERE fid = " + id.ToString(); // MessageBox.Show(cmd1.CommandText); cmd2.Parameters.Clear(); int i = 0; using (MySqlDataReader reader = cmd1.ExecuteReader()) { if (!reader.Read()) { continue; } for (int n = 0; n< reader.FieldCount; n++) { cmd2.Parameters.AddWithValue(String.Format("val{0}", ++i), reader.IsDBNull(n) ? DBNull.Value : reader.GetValue(n)); } } // Update row //cmd2.CommandText = String.Format(ct2, id); cmd2.CommandText = "UPDATE " + tbl1 + " SET variante = @val1,charge = @val2, fdate = @val3 WHERE seriennummer = " + id.ToString(); cmd2.ExecuteNonQuery(); } // Insert new rows //ct1 = "SELECT fid, variante,charge,DATE_FORMAT(fdate, '%Y-%M-%D %H:%i:%s') FROM " + tbl2 + " WHERE fid = {0}"; //ct2 = "INSERT INTO " + tbl1 + " (seriennummer, variante,charge,fdate) " + // "VALUES (@val1, @val2, @val3, @val4)"; // cmd2.CommandText = ct2; cmd2.CommandText = "INSERT INTO " + tbl1 + " (seriennummer,variante,charge,fdate) " + "VALUES (@val1, @val2, @val3, @val4)"; foreach (Int64 id in List2) { // Read all values into parameters //cmd1.CommandText = String.Format(ct1, id); cmd1.CommandText = "SELECT fid,variante,charge,DATE_FORMAT(fdate, '%Y-%M-%D %H:%i:%s') FROM " + tbl2 + " WHERE fid = " + id.ToString(); cmd2.Parameters.Clear(); int i = 0; using (MySqlDataReader reader = cmd1.ExecuteReader()) { if (!reader.Read()) { continue; } for (int n = 0; n< reader.FieldCount; n++) { cmd2.Parameters.AddWithValue(String.Format("val{0}", ++i), reader.IsDBNull(n) ? DBNull.Value : reader.GetValue(n)); } } // Insert row cmd2.ExecuteNonQuery(); } } catch (MySqlException ex) { MessageBox.Show("Error: " + ex.ToString()); } }