Esempio n. 1
0
        private void button1_Salvar_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox2Senha.Text != textBox1Senha2.Text)
                {
                    MessageBox.Show("Senhas não conferem", ".:: Atenção ::.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                string tempL      = textBox1Login.Text.Replace(" ", "");
                string cryptLogin = textBox1Login.Text.Replace(" ", "");
                textBox1Login.Text = EncryptLogin(cryptLogin);

                string tempP         = textBox2Senha.Text.Replace(" ", "");
                string cryptPassword = textBox2Senha.Text.Replace(" ", "");
                textBox2Senha.Text = EncryptLogin(cryptPassword);

                DataSet ds;
                string  sXMLFile = (CaminhoDadosXML(caminho) + @"System.net.b.xml");
                string  strID    = idt;
                //Criando o DataSet
                ds = new DataSet();
                //Preenche o DataSet com o XML
                ds.ReadXml(sXMLFile);

                //Fazer uma busca no DataSet para encontrar o cliente com o ID da QueryString
                DataRow dRow = ds.Tables["B_dado"].Select(" id = '" + strID + "'")[0];
                //Definindo os valores do DataRow com os valores do formulário.
                dRow["Cliente"]  = textBox1Client.Text.Replace(" ", "");
                dRow["url"]      = textBox1Link.Text.Replace(" ", "");
                dRow["Username"] = textBox1Login.Text;
                dRow["Password"] = textBox2Senha.Text.Replace(" ", "");

                //Atualizar o XML com os novos valores.
                ds.WriteXml(sXMLFile);

                Form8 obj = (Form8)Application.OpenForms["Form8"];
                obj.GetDados();

                textBox1Login.Text = tempL;
                textBox2Senha.Text = tempP;
                MessageBox.Show("Salvo com Sucesso!", ".:: Sucesso ::.", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                File.AppendAllText(logpath + @"\" + "log_erro.txt", "\r\n" + DateTime.Now + @" | " + ex.Message);
                MessageBox.Show("Erro " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        private void button1_Salvar_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox2Senha.Text != textBox1Senha2.Text)
                {
                    MessageBox.Show("Senhas não conferem", ".:: Atenção ::.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                id = Convert.ToString(GetRandomNumber(1, 9999));

                string tempL      = textBox1Login.Text.Replace(" ", "");
                string cryptLogin = textBox1Login.Text.Replace(" ", "");
                textBox1Login.Text = EncryptLogin(cryptLogin);

                string tempP         = textBox2Senha.Text.Replace(" ", "");
                string cryptPassword = textBox2Senha.Text.Replace(" ", "");
                textBox2Senha.Text = EncryptLogin(cryptPassword);


                using (DataSet dsResultado = new DataSet())
                {
                    dsResultado.ReadXml(CaminhoDadosXML(caminho) + @"System.net.b.xml");
                    if (dsResultado.Tables.Count != 0)
                    {
                        dsResultado.Tables[0].Rows.Add(dsResultado.Tables[0].NewRow());
                        dsResultado.Tables[0].Rows[dsResultado.Tables[0].Rows.Count - 1]["id"]       = id;
                        dsResultado.Tables[0].Rows[dsResultado.Tables[0].Rows.Count - 1]["Cliente"]  = textBox1Client.Text;
                        dsResultado.Tables[0].Rows[dsResultado.Tables[0].Rows.Count - 1]["url"]      = textBox1Link.Text;
                        dsResultado.Tables[0].Rows[dsResultado.Tables[0].Rows.Count - 1]["Username"] = textBox1Login.Text;
                        dsResultado.Tables[0].Rows[dsResultado.Tables[0].Rows.Count - 1]["Password"] = textBox2Senha.Text;

                        dsResultado.AcceptChanges();
                        //--  Escreve para o arquivo XML final usando o método Write
                        dsResultado.WriteXml(CaminhoDadosXML(caminho) + @"System.net.b.xml", XmlWriteMode.IgnoreSchema);
                    }
                }

                //using (DataSet dsRess = new DataSet())
                //{

                //    sessao sessao = new sessao();
                //    sessao.idSessao = Convert.ToInt32(id);
                //    sessao.ClienteSessao = textBox1Client.Text;

                //    XmlTextWriter writer = new XmlTextWriter(CaminhoDadosXML(caminho) + @"System.net.b.xml", System.Text.Encoding.UTF8);
                //    writer.WriteStartDocument(true);

                //    writer.Formatting = Formatting.Indented;
                //    writer.Indentation = 2;
                //    writer.WriteStartElement("B_dados");

                //    writer.WriteStartElement("sessao");
                //    writer.WriteStartElement("idsessao");
                //    writer.WriteString(Convert.ToString(sessao.idSessao));
                //    writer.WriteEndElement();

                //    writer.WriteStartElement("Cliente");
                //    writer.WriteString(sessao.ClienteSessao);
                //    writer.WriteEndElement();

                //    writer.WriteEndElement();
                //    writer.WriteEndDocument();
                //    writer.Close();
                //    dsRess.ReadXml(CaminhoDadosXML(caminho) + @"System.net.b.xml");

                //}
                // Salva na sessao
                //XElement x = new XElement("sessao");
                //x.Add(new XAttribute("id", id));
                //x.Add(new XAttribute("Cliente", textBox1Client.Text));
                //XElement xml = XElement.Load(CaminhoDadosXML(caminho) + @"System.net.b.xml");
                //xml.Add(x);
                //xml.Save(CaminhoDadosXML(caminho) + @"System.net.b.xml");



                textBox1Login.Text = tempL;
                textBox2Senha.Text = tempP;

                Form8 obj = (Form8)Application.OpenForms["Form8"];
                obj.GetDados();


                MessageBox.Show("Salvo com Sucesso!", ".:: Sucesso ::.", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                File.AppendAllText(logpath + @"\" + "log_erro.txt", "\r\n" + DateTime.Now + @" | " + ex.Message);
                MessageBox.Show("Erro " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }