public void Initialize(MySql.Data.MySqlClient.MySqlDataReader pReader) { UserID = pReader.GetInt32("userid"); ID = pReader.GetInt32("id"); InternalID = pReader.GetInt32("internal_id"); Name = pReader.GetString("name"); WorldID = pReader.GetByte("world_id"); AccountID = AccountDataCache.Instance.KnownUserlist[UserID]; SlotHashes = new Dictionary <int, Dictionary <short, int> >(); }
private void importar() { label1.Text = "Iniciando Importação. Aguarde"; label1.Visible = true; StopTrimble(); Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); limpaTabelas(); label1.Text = "Dados locais apagados"; Application.DoEvents(); //abre conexao try { myconn.Open(); } catch (Exception ex) { MessageBox.Show("Não foi possível conectar ao servidor, verifique a sua conexão com a internet."); } if (myconn.State == ConnectionState.Open) { try { //inicia a transacao MySql.Data.MySqlClient.MySqlCommand mycommand = myconn.CreateCommand(); //mycommand.Connection = myconn; //inserir usuarios mycommand.CommandText = "SELECT `usuario`.`id`, " + "`usuario`.`nome`, " + "`usuario`.`senha`, " + "`usuario`.`nmax_barramento`, " + "`usuario`.`nmin_barramento`, " + "`usuario`.`repetir_coord`, " + "`usuario`.`email` " + "FROM `eletrocad`.`usuario`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); MySql.Data.MySqlClient.MySqlDataReader reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.usuarioRow uRow; uRow = eletrocadDataSet.usuario.NewusuarioRow(); uRow.id = reader.GetInt32("id"); uRow.nome = reader.GetString("nome"); uRow.email = reader.GetString("email"); uRow.senha = reader.GetString("senha"); uRow.nmax_barramento = reader.GetInt32("nmax_barramento"); uRow.nmin_barramento = reader.GetInt32("nmin_barramento"); uRow.repetir_coord = reader.GetByte("repetir_coord"); eletrocadDataSet.usuario.Rows.Add(uRow); } usuarioTableAdapter.Update(eletrocadDataSet.usuario); eletrocadDataSet.usuario.AcceptChanges(); usuarioTableAdapter.Fill(eletrocadDataSet.usuario); reader.Close(); label1.Text = "Usuário importado com sucesso!"; Application.DoEvents(); //inserir usuarios //mycommand = myconn.CreateCommand(); mycommand.CommandText = "SELECT `braco`.`id`, " + "`braco`.`descricao` " + "FROM `eletrocad`.`braco`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.bracoRow uRow; uRow = eletrocadDataSet.braco.NewbracoRow(); uRow.id = reader.GetInt32("id"); uRow.descricao = reader.GetString("descricao"); eletrocadDataSet.braco.Rows.Add(uRow); } bracoTableAdapter.Update(eletrocadDataSet.braco); eletrocadDataSet.braco.AcceptChanges(); bracoTableAdapter.Fill(eletrocadDataSet.braco); reader.Close(); label1.Text = "Braço importado com sucesso!"; Application.DoEvents(); //inserir fase //mycommand = myconn.CreateCommand(); mycommand.CommandText = "SELECT `fase`.`id`, " + "`fase`.`descricao` " + "FROM `eletrocad`.`fase`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.faseRow uRow; uRow = eletrocadDataSet.fase.NewfaseRow(); uRow.id = reader.GetInt32("id"); uRow.descricao = reader.GetString("descricao"); eletrocadDataSet.fase.Rows.Add(uRow); } faseTableAdapter.Update(eletrocadDataSet.fase); eletrocadDataSet.fase.AcceptChanges(); faseTableAdapter.Fill(eletrocadDataSet.fase); reader.Close(); label1.Text = "Fase importada com sucesso!"; Application.DoEvents(); //mycommand = myconn.CreateCommand(); mycommand.CommandText = "SELECT `chave_comando`.`id`, " + "`chave_comando`.`descricao` " + "FROM `eletrocad`.`chave_comando`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.chave_comandoRow uRow; uRow = eletrocadDataSet.chave_comando.Newchave_comandoRow(); uRow.id = reader.GetInt32("id"); uRow.descricao = reader.GetString("descricao"); eletrocadDataSet.chave_comando.Rows.Add(uRow); } chave_comandoTableAdapter.Update(eletrocadDataSet.chave_comando); eletrocadDataSet.chave_comando.AcceptChanges(); chave_comandoTableAdapter.Fill(eletrocadDataSet.chave_comando); reader.Close(); label1.Text = "Chave de comando importada com sucesso!"; Application.DoEvents(); //inserir ativacao //mycommand = myconn.CreateCommand(); mycommand.CommandText = "SELECT `ativacao`.`id`, " + "`ativacao`.`descricao` " + "FROM `eletrocad`.`ativacao`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.ativacaoRow uRow; uRow = eletrocadDataSet.ativacao.NewativacaoRow(); uRow.id = reader.GetInt32("id"); uRow.descricao = reader.GetString("descricao"); eletrocadDataSet.ativacao.Rows.Add(uRow); } ativacaoTableAdapter.Update(eletrocadDataSet.ativacao); eletrocadDataSet.ativacao.AcceptChanges(); ativacaoTableAdapter.Fill(eletrocadDataSet.ativacao); reader.Close(); label1.Text = "Ativação importada com sucesso!"; Application.DoEvents(); //inserir ativacao //mycommand = myconn.CreateCommand(); mycommand.CommandText = "SELECT `condicao_risco`.`id`, " + "`condicao_risco`.`descricao` " + "FROM `eletrocad`.`condicao_risco`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.condicao_riscoRow uRow; uRow = eletrocadDataSet.condicao_risco.Newcondicao_riscoRow(); uRow.id = reader.GetInt32("id"); uRow.descricao = reader.GetString("descricao"); eletrocadDataSet.condicao_risco.Rows.Add(uRow); } condicao_riscoTableAdapter.Update(eletrocadDataSet.condicao_risco); eletrocadDataSet.condicao_risco.AcceptChanges(); condicao_riscoTableAdapter.Fill(eletrocadDataSet.condicao_risco); reader.Close(); label1.Text = "Condição de Risco importada com sucesso!"; Application.DoEvents(); //tipo de lampada primeiro mycommand.CommandText = "SELECT `tipo_lampada`.`id`," + "`tipo_lampada`.`descricao` " + "FROM `eletrocad`.`tipo_lampada`"; reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.tipo_lampadaRow pipRow; pipRow = eletrocadDataSet.tipo_lampada.Newtipo_lampadaRow(); pipRow.id = reader.GetInt32("id"); pipRow.descricao = reader.GetString("descricao"); eletrocadDataSet.tipo_lampada.Rows.Add(pipRow); } tipo_lampadaTableAdapter.Update(eletrocadDataSet.tipo_lampada); eletrocadDataSet.tipo_lampada.AcceptChanges(); tipo_lampadaTableAdapter.Fill(eletrocadDataSet.tipo_lampada); reader.Close(); label1.Text = "Tipo de lâmpadas importado com sucesso!"; Application.DoEvents(); mycommand.CommandText = "SELECT `lampada`.`id`," + "`lampada`.`descricao`," + "`lampada`.`potencia`," + "`lampada`.`perda`," + "`lampada`.`tipo_lampada_id` " + "FROM `eletrocad`.`lampada`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.lampadaRow pipRow; pipRow = eletrocadDataSet.lampada.NewlampadaRow(); pipRow.id = reader.GetInt32("id"); pipRow.descricao = reader.GetString("descricao"); pipRow.perda = reader.GetDouble("perda"); pipRow.potencia = reader.GetDouble("potencia"); pipRow.tipo_lampada_id = reader.GetInt32("tipo_lampada_id"); eletrocadDataSet.lampada.Rows.Add(pipRow); } lampadaTableAdapter.Update(eletrocadDataSet.lampada); eletrocadDataSet.lampada.AcceptChanges(); lampadaTableAdapter.Fill(eletrocadDataSet.lampada); reader.Close(); label1.Text = "Lâmpadas importadas com sucesso!"; Application.DoEvents(); mycommand.CommandText = "SELECT `reator`.`id`," + "`reator`.`descricao`," + "`reator`.`potencia`," + "`reator`.`perda`," + "`reator`.`tipo_lampada_id` " + "FROM `eletrocad`.`reator`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.reatorRow pipRow; pipRow = eletrocadDataSet.reator.NewreatorRow(); pipRow.id = reader.GetInt32("id"); pipRow.descricao = reader.GetString("descricao"); pipRow.perda = reader.GetDouble("perda"); pipRow.potencia = reader.GetDouble("potencia"); pipRow.tipo_lampada_id = reader.GetInt32("tipo_lampada_id"); eletrocadDataSet.reator.Rows.Add(pipRow); } reatorTableAdapter.Update(eletrocadDataSet.reator); eletrocadDataSet.reator.AcceptChanges(); reatorTableAdapter.Fill(eletrocadDataSet.reator); reader.Close(); label1.Text = "Reator importado com sucesso!"; Application.DoEvents(); mycommand.CommandText = "SELECT `uso_mutuo`.`id`," + "`uso_mutuo`.`descricao` " + "FROM `eletrocad`.`uso_mutuo`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.uso_mutuoRow pipRow; pipRow = eletrocadDataSet.uso_mutuo.Newuso_mutuoRow(); pipRow.id = reader.GetInt32("id"); pipRow.descricao = reader.GetString("descricao"); eletrocadDataSet.uso_mutuo.Rows.Add(pipRow); } uso_mutuoTableAdapter.Update(eletrocadDataSet.uso_mutuo); eletrocadDataSet.uso_mutuo.AcceptChanges(); uso_mutuoTableAdapter.Fill(eletrocadDataSet.uso_mutuo); reader.Close(); label1.Text = "Uso Mútuo importado com sucesso!"; Application.DoEvents(); mycommand.CommandText = "SELECT `tipo_luminaria`.`id`," + "`tipo_luminaria`.`descricao` " + "FROM `eletrocad`.`tipo_luminaria`"; //mycommand.Parameters.Clear(); //mycommand.Parameters.AddWithValue("estado", cbEstado.Text); //mycommand.Parameters.AddWithValue("ano", txtAno.Value); reader = mycommand.ExecuteReader(); while (reader.Read()) { // //insere nova programação db.eletrocadDataSet.tipo_luminariaRow pipRow; pipRow = eletrocadDataSet.tipo_luminaria.Newtipo_luminariaRow(); pipRow.id = reader.GetInt32("id"); pipRow.descricao = reader.GetString("descricao"); eletrocadDataSet.tipo_luminaria.Rows.Add(pipRow); } tipo_luminariaTableAdapter.Update(eletrocadDataSet.tipo_luminaria); eletrocadDataSet.tipo_luminaria.AcceptChanges(); tipo_luminariaTableAdapter.Fill(eletrocadDataSet.tipo_luminaria); reader.Close(); label1.Text = "Luminária importada com sucesso!"; //StartTraking(); Application.DoEvents(); //MSG FINAL label1.Text = "Dados importados com sucesso!"; Application.DoEvents(); } catch (Exception ex) { MessageBox.Show("Não foi possível importar todos os dados: " + ex.Message); } finally { myconn.Close(); } } //MessageBox.Show("Informações recuperadas com sucesso"); label1.Visible = false; Cursor.Current = Cursors.Default; Application.DoEvents(); }