protected override void DataAdapterUpdate(System.Data.DataSet tabela, string strNomeTabela) { if (m_bUserCanUpdateDB) { OpenConnection(); if (m_Connection.State == System.Data.ConnectionState.Open) { if (tabela.GetChanges() != null) { m_Transaction = m_Connection.BeginTransaction(); m_CommandSelect.Transaction = m_Transaction; try { m_DataAdapter.Update(tabela, strNomeTabela); m_Transaction.Commit(); DataPersist = false; } catch (System.Exception eEcp) { m_excError = eEcp; m_Transaction.Rollback(); ShowDialogUpdateError(strNomeTabela); } } } CloseConnection(); } }
public string LoadDataToTargetTable(string tableName, MySql.Data.MySqlClient.MySqlConnection connection, ref DataTable dtTarget) { string errorMessage = ""; try { using (MySql.Data.MySqlClient.MySqlTransaction tran = connection.BeginTransaction(System.Data.IsolationLevel.Serializable)) { using (MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand()) { cmd.Connection = connection; cmd.Transaction = tran; cmd.CommandText = "SELECT * FROM MTG.Cards"; using (MySql.Data.MySqlClient.MySqlDataAdapter da = new MySql.Data.MySqlClient.MySqlDataAdapter(cmd)) { da.UpdateBatchSize = 1000; using (MySql.Data.MySqlClient.MySqlCommandBuilder cb = new MySql.Data.MySqlClient.MySqlCommandBuilder(da)) { rowsCopied += da.Update(dtTarget); tran.Commit(); } } } } System.Console.WriteLine($"{rowsCopied} rows copied."); } catch (Exception ex) { errorMessage = ex.Message; } return errorMessage; }
public void sendData(ref DataSet data) { try { dbadapter = new MySql.Data.MySqlClient.MySqlDataAdapter("SELECT * FROM " + Table, connection); MySql.Data.MySqlClient.MySqlCommandBuilder builder = new MySql.Data.MySqlClient.MySqlCommandBuilder(dbadapter); dbadapter.Update(data, Table); } catch (MySql.Data.MySqlClient.MySqlException ex) { throw ex; } }
private void salvaprezziadhoc() { hocadapter.Update(prezzoadhoc); }
private void salvaarticoli() { articoliadapter.Update(articoli); }
private void button2_Click(object sender, EventArgs e) { try { string s_imsi = string.Empty; System.ComponentModel.BackgroundWorker work = new System.ComponentModel.BackgroundWorker(); work.ProgressChanged += delegate(object me, System.ComponentModel.ProgressChangedEventArgs ev) { this.Invoke(new MethodInvoker(delegate { this.toolStripProgressBar1.Value = ev.ProgressPercentage; })); }; work.WorkerReportsProgress = true; System.Collections.Generic.List <PCSC.GSMAlgorithm> gsmresult = new System.Collections.Generic.List <PCSC.GSMAlgorithm>(); this._simcard.Connect(this.comboBox1.SelectedItem); if (this._simcard.Connected) { ((Button)sender).Enabled = false; work.ReportProgress(10); Form2 pinCode = new Form2(); int pinrequired = -1; while (pinrequired < 0) { try { pinrequired = Convert.ToInt32(this._simcard.Authenticated); System.Threading.Thread.Sleep(100); } catch { } } if (pinrequired == 0) { work.ReportProgress(20); pinCode.FormClosed += delegate(object form_, FormClosedEventArgs ev_) { Form f = form_ as Form; if (f.DialogResult == DialogResult.OK) { byte[] pincode = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; byte[] received_pincode = Encoding.ASCII.GetBytes(f.Controls["textBox1"].Text); for (int i = 0; i < received_pincode.Length; i++) { pincode[i] = received_pincode[i]; } this._simcard.PIN1 = pincode; } }; while (!this._simcard.Authenticated && this._simcard.TryPIN1 > 0 && pinCode.DialogResult != DialogResult.Cancel) { pinCode.Text = string.Format("Code PIN - {0} essais", this._simcard.TryPIN1); pinCode.Controls["textBox1"].ResetText(); pinCode.ShowDialog(this); } if (this._simcard.Authenticated) { work.ReportProgress(30); /* * PCSC.Rand rand = new PCSC.Rand(); * PCSC.GSMAlgorithm response = this._simcard.RunGSMAlgorithm(rand.ToByteArray()); * * this.textBox1.Lines = new string[] * { * "IMSI = " + Core.Utility.ByteArray.ToString(this._simcard.IMSI), * "RAND = " + rand.ToString(), * "SRES = " + Core.Utility.ByteArray.ToString(response.SRes), * "KC = " + Core.Utility.ByteArray.ToString(response.Kc), * }; */ s_imsi = Core.Utility.ByteArray.ToString(this._simcard.IMSI); for (int i = 0; i < 3; i++) { gsmresult.Add(this._simcard.RunGSMAlgorithm(new PCSC.Rand().ToByteArray())); } work.ReportProgress(40); } } else { /* * PCSC.Rand rand = new PCSC.Rand(); * PCSC.GSMAlgorithm response = this._simcard.RunGSMAlgorithm(rand.ToByteArray()); * * this.textBox1.Lines = new string[] * { * "IMSI = " + Core.Utility.ByteArray.ToString(this._simcard.IMSI), * "RAND = " + rand.ToString(), * "SRES = " + Core.Utility.ByteArray.ToString(response.SRes), * "KC = " + Core.Utility.ByteArray.ToString(response.Kc), * }; */ s_imsi = Core.Utility.ByteArray.ToString(this._simcard.IMSI); for (int i = 0; i < 3; i++) { gsmresult.Add(this._simcard.RunGSMAlgorithm(new PCSC.Rand().ToByteArray())); } work.ReportProgress(40); } s_imsi = string.Format("{0}@wlan.mnc{2}.mcc{1}.3gppnetwork.org", s_imsi, s_imsi.Substring(1, 3).PadLeft(3, '0'), s_imsi.Substring(4, 2).PadLeft(3, '0')); object[] prm = new object[] { s_imsi, gsmresult }; work.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate(object me, System.ComponentModel.DoWorkEventArgs ev) { try { object[] args = ev.Argument as object[]; IniFile config = new IniFile("config.ini"); MySql.Data.MySqlClient.MySqlConnection sqlconn = new MySql.Data.MySqlClient.MySqlConnection() { ConnectionString = string.Format("server={0};uid={1};pwd={2};database={3}", config.Read("SQLHOST", "config"), config.Read("SQLUSER", "config"), Encoding.ASCII.GetString(Convert.FromBase64String(config.Read("SQLPWD", "config"))), config.Read("SQLDB", "config")) }; sqlconn.Open(); System.Data.DataSet ds = new System.Data.DataSet(); MySql.Data.MySqlClient.MySqlDataAdapter da = new MySql.Data.MySqlClient.MySqlDataAdapter(string.Format("SELECT username,attribute,op,value FROM radcheck WHERE username = '******'", args[0]), sqlconn); da.Fill(ds); ((System.ComponentModel.BackgroundWorker)me).ReportProgress(45); if (ds.Tables[0].Rows.Count == 0) { ds.Tables[0].Rows.Add(new object[] { args[0], "Auth-Type", ":=", "eap" }); ds.Tables[0].Rows.Add(new object[] { args[0], "EAP-Type", ":=", "sim" }); ((System.ComponentModel.BackgroundWorker)me).ReportProgress(50); for (int k = 0; k < 3; k++) { ds.Tables[0].Rows.Add(new object[] { args[0], string.Format("EAP-Sim-RAND{0}", k + 1), ":=", string.Format("0x{0}", Core.Utility.ByteArray.ToString(((System.Collections.Generic.IList <PCSC.GSMAlgorithm>)args[1])[k].Rand).ToLower()) }); ds.Tables[0].Rows.Add(new object[] { args[0], string.Format("EAP-Sim-SRES{0}", k + 1), ":=", string.Format("0x{0}", Core.Utility.ByteArray.ToString(((System.Collections.Generic.IList <PCSC.GSMAlgorithm>)args[1])[k].SRes).ToLower()) }); ds.Tables[0].Rows.Add(new object[] { args[0], string.Format("EAP-Sim-KC{0}", k + 1), ":=", string.Format("0x{0}", Core.Utility.ByteArray.ToString(((System.Collections.Generic.IList <PCSC.GSMAlgorithm>)args[1])[k].Kc).ToLower()) }); ((System.ComponentModel.BackgroundWorker)me).ReportProgress(50 + ((k + 1) * 10)); } new MySql.Data.MySqlClient.MySqlCommandBuilder(da); da.Update(ds); ((System.ComponentModel.BackgroundWorker)me).ReportProgress(90); ev.Result = "La carte SIM a correctement été ajoutée pour l'authentification EAP-SIM !"; } else { ev.Result = "La carte SIM a déjà été enregistrée pour l'authentification EAP-SIM !"; } /* * MySql.Data.MySqlClient.MySqlCommand ins = new MySql.Data.MySqlClient.MySqlCommand() * { * CommandText = string.Format("INSERT INTO radcheck(username,attribute,op,value) VALUES (@username, @attribute, @op, @value);"), * Connection = sqlconn * }; * ins.Prepare(); * * ins.Parameters.AddWithValue("@username", args[0]); * ins.Parameters.AddWithValue("@attribute", "Auth-Type"); * ins.Parameters.AddWithValue("@op", ":="); * ins.Parameters.AddWithValue("@value", "eap"); * * ins.ExecuteNonQuery(); * * ins = new MySql.Data.MySqlClient.MySqlCommand() * { * CommandText = string.Format("INSERT INTO radcheck(username,attribute,op,value) VALUES (@username, @attribute, @op, @value);"), * Connection = sqlconn * }; * ins.Prepare(); * * ins.Parameters.AddWithValue("@username", args[0]); * ins.Parameters.AddWithValue("@attribute", "EAP-Type"); * ins.Parameters.AddWithValue("@op", ":="); * ins.Parameters.AddWithValue("@value", "sim"); * * ins.ExecuteNonQuery(); * * for (int o = 0; o < 3; o++) * { * ins = new MySql.Data.MySqlClient.MySqlCommand() * { * CommandText = string.Format("INSERT INTO radcheck(username,attribute,op,value) VALUES (@username, @attribute, @op, @value);"), * Connection = sqlconn * }; * ins.Prepare(); * * ins.Parameters.AddWithValue("@username", args[0]); * ins.Parameters.AddWithValue("@attribute", string.Format("EAP-Sim-RAND{0}", o + 1)); * ins.Parameters.AddWithValue("@op", ":="); * ins.Parameters.AddWithValue("@value", string.Format("0x{0}", Core.Utility.ByteArray.ToString(((System.Collections.Generic.IList<PCSC.GSMAlgorithm>)args[1])[o].Rand).ToLower())); * * ins.ExecuteNonQuery(); * * ins = new MySql.Data.MySqlClient.MySqlCommand() * { * CommandText = string.Format("INSERT INTO radcheck(username,attribute,op,value) VALUES (@username, @attribute, @op, @value);"), * Connection = sqlconn * }; * ins.Prepare(); * * ins.Parameters.AddWithValue("@username", args[0]); * ins.Parameters.AddWithValue("@attribute", string.Format("EAP-Sim-SRES{0}", o + 1)); * ins.Parameters.AddWithValue("@op", ":="); * ins.Parameters.AddWithValue("@value", string.Format("0x{0}", Core.Utility.ByteArray.ToString(((System.Collections.Generic.IList<PCSC.GSMAlgorithm>)args[1])[o].SRes).ToLower())); * * ins.ExecuteNonQuery(); * * ins = new MySql.Data.MySqlClient.MySqlCommand() * { * CommandText = string.Format("INSERT INTO radcheck(username,attribute,op,value) VALUES (@username, @attribute, @op, @value);"), * Connection = sqlconn * }; * ins.Prepare(); * * ins.Parameters.AddWithValue("@username", args[0]); * ins.Parameters.AddWithValue("@attribute", string.Format("EAP-Sim-KC{0}", o + 1)); * ins.Parameters.AddWithValue("@op", ":="); * ins.Parameters.AddWithValue("@value", string.Format("0x{0}", Core.Utility.ByteArray.ToString(((System.Collections.Generic.IList<PCSC.GSMAlgorithm>)args[1])[o].Kc).ToLower())); * * ins.ExecuteNonQuery(); * } */ sqlconn.Close(); ((System.ComponentModel.BackgroundWorker)me).ReportProgress(100); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); ev.Result = "La carte SIM n'a pas pu être enregistrée pour l'authentification EAP-SIM !"; } }); work.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(delegate(object me, System.ComponentModel.RunWorkerCompletedEventArgs ev) { this.textBox1.Invoke(new MethodInvoker(delegate { this.textBox1.Lines = new string[] { ev.Result.ToString(), "Vous pouvez retirer la carte SIM du lecteur.", Environment.NewLine, "IMSI : " + s_imsi.Substring(1) }; this._simcard.Dispose(); pinCode = null; if (!this._simcard.Connected) { ((Button)sender).Enabled = true; } this.button1_Click(sender, e); })); }); work.RunWorkerAsync(prm); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void salvaarticolo(object sender, EventArgs e) { adapter.Update(articoli); MessageBox.Show("SALVATO"); }
private void salvaemail() { emailadapter.Update(clienteemail); }
private void salvapiva() { pivaadapter.Update(clientepiva); }
private void salvadestinazioni() { destinazioniadapter.Update(clientedestinazione); }
private void salvaclienti() { clientiadapter.Update(clienti); }
public static void salvabolle() { bolleadapter.Update(bolle); }
private void salvainformazioni(object sender, EventArgs e) { informazioniadapter.Update(informazioni); MessageBox.Show("SALVATO"); }
public void InsertBatch <T>(string connection, List <T> models, int batch = 0) where T : class, IModel { using (var c = new MySqlData.MySqlClient.MySqlConnection(connection)) { c.Open(); using (var transaction = c.BeginTransaction()) { try { var map = _sql?.Configuration?.GetMap <T>(); if (map == null) { throw new Exception($"Class Map for:{typeof(T).Name} could not be found."); } var name = map.TableName; var table = models.ToDataTable(); if (table.Rows.Count == 0) { return; } var builder = new StringBuilder(); builder.Append("SELECT TABLE_NAME"); builder.Append(", COLUMN_NAME"); builder.Append(", DATA_TYPE"); builder.Append(", CHARACTER_MAXIMUM_LENGTH"); builder.Append(", CHARACTER_OCTET_LENGTH"); builder.Append(", NUMERIC_PRECISION"); builder.Append(", NUMERIC_SCALE AS SCALE"); builder.Append(", COLUMN_DEFAULT"); builder.Append(", IS_NULLABLE"); builder.Append(" FROM INFORMATION_SCHEMA.COLUMNS"); builder.Append(" WHERE TABLE_NAME = @Table"); var schema = new List <Schema>(); //get table schema (e.g. names and datatypes for mapping) using (var command = new MySqlData.MySqlClient.MySqlCommand(builder.ToString(), c)) { var parameter = new MySqlData.MySqlClient.MySqlParameter(); parameter.Value = map.TableName; parameter.ParameterName = "@Table"; parameter.MySqlDbType = MySqlData.MySqlClient.MySqlDbType.String; command.Parameters.Add(parameter); using (var sql = new MySqlData.MySqlClient.MySqlDataAdapter(command)) { var result = new DataTable(); var parameters = map.Properties .Where(x => x.Ignored == false) .Where(x => x.IsReadOnly == false) .Where(x => x.KeyType == KeyType.NotAKey); sql.Fill(result); schema = (from p in parameters join s in result.AsEnumerable() on p.ColumnName equals s.Field <string>("COLUMN_NAME") select new Schema() { ColumnName = s.Field <string>("COLUMN_NAME"), DataType = s.Field <string>("DATA_TYPE"), Size = s.Field <object>("CHARACTER_OCTET_LENGTH") }).ToList(); } } using (var command = new MySqlData.MySqlClient.MySqlCommand($"INSERT INTO {map.TableName} ({string.Join(",", schema.Select(x => x.ColumnName))}) VALUES ({string.Join(",", schema.Select(x => $"@{x.ColumnName}"))});", c)) { command.UpdatedRowSource = UpdateRowSource.None; foreach (var type in schema) { var parameter = new MySqlData.MySqlClient.MySqlParameter(); parameter.ParameterName = $"@{type.ColumnName}"; parameter.SourceColumn = type.ColumnName; switch (type.DataType.ToLower()) { case "varchar": case "char": case "text": parameter.MySqlDbType = MySqlData.MySqlClient.MySqlDbType.String; parameter.Size = Int32.Parse(type.Size.ToString()); break; case "datetime": parameter.MySqlDbType = MySqlData.MySqlClient.MySqlDbType.DateTime; break; case "int": parameter.MySqlDbType = MySqlData.MySqlClient.MySqlDbType.Int32; break; default: throw new NotImplementedException(); } command.Parameters.Add(parameter); } using (var adapter = new MySqlData.MySqlClient.MySqlDataAdapter()) { adapter.InsertCommand = command; var timer = Stopwatch.StartNew(); _log.LogTrace <MySqlQuery>($"Bulk Insert on {name}. {models.Count} rows queued for insert."); timer.Start(); if (batch > 0) { adapter.UpdateBatchSize = 100; } adapter.Update(table); transaction.Commit(); _log.LogTrace <MySqlQuery>($"Bulk Insert on {name} complete in: {timer.Elapsed.ToString(@"hh\:mm\:ss\:fff")}"); } } } catch (Exception) { transaction.Rollback(); throw; } finally { c.Close(); } } } }