public int salvar() { if (!string.IsNullOrEmpty(txtEmailtrans.Text)) { Boolean emailOk = valida.ValidaEmail(txtEmailtrans.Text); if (emailOk == false) { //MessageBox.Show("Email Inválido.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); //return 1; throw new Exception("email invalido"); } String CnpjTrans = (String)txtCnpjTrans.Text.Replace(".", "").Replace("/", "").Replace("-", ""); if (chkAereo.Checked) { COMERCIALDataSetTableAdapters.TRANSPORTADORAVIATableAdapter VTrans = new Comercial.COMERCIALDataSetTableAdapters.TRANSPORTADORAVIATableAdapter(); VTrans.Insert("aer", CnpjTrans); } if (chkFerroviario.Checked) { COMERCIALDataSetTableAdapters.TRANSPORTADORAVIATableAdapter VTrans = new Comercial.COMERCIALDataSetTableAdapters.TRANSPORTADORAVIATableAdapter(); VTrans.Insert("fer", CnpjTrans); } if (chkMaritimo.Checked) { COMERCIALDataSetTableAdapters.TRANSPORTADORAVIATableAdapter VTrans = new Comercial.COMERCIALDataSetTableAdapters.TRANSPORTADORAVIATableAdapter(); VTrans.Insert("mar", CnpjTrans); } if (chkTerrestre.Checked) { COMERCIALDataSetTableAdapters.TRANSPORTADORAVIATableAdapter VTrans = new Comercial.COMERCIALDataSetTableAdapters.TRANSPORTADORAVIATableAdapter(); VTrans.Insert("ter", CnpjTrans); } this.limparcampos(); } return(0); }
public int salvar(bool edit) { DataRowView x; x = (DataRowView)cLIENTEBindingSource.Current; Validacoes valida = new Validacoes(); string c = ConfigurationManager.ConnectionStrings["Comercial.Properties.Settings.COMERCIALConnectionString"].ConnectionString; //Valida CNPJ if (!String.IsNullOrEmpty(txtCnpjCli.Text) && txtCnpjCli.Text.Trim().Length == 14) { int cnpj = valida.ValidaCNPJ(txtCnpjCli.Text); if (cnpj == 1) { //MessageBox.Show("CNPJ Inválido.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); //return 1; throw new Exception("cnpj invalido"); } } else { throw new Exception("cnpj invalido"); } // Valida IE if (!String.IsNullOrEmpty(txtIeCli.Text)) { string ie = txtIeCli.Text; string uf = cmbUfCli.SelectedItem.ToString(); int returnIe = ConsisteInscricaoEstadual(ie, uf); if (returnIe == 1) { //MessageBox.Show("I.E. Inválida.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); //return 1; throw new Exception("ie invalida"); } //if (string.IsNullOrEmpty(txtRazaoSocialCli.Text)) //{ // MessageBox.Show("Campo(s) obrigatório(s) não preenchido(s).", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); // return 1; //} } // Valida limite de crédito // string va = txtLimCredCli.Te if(!String.IsNullOrEmpty(txtLimCredCli.Text)) { double valor = double.Parse(txtLimCredCli.Text,System.Globalization.NumberStyles.Currency); if (valor<=0) { throw new Exception("valor invalido"); } } // Valida email if (!string.IsNullOrEmpty(txtEmailCli.Text)) { Boolean emailOk = valida.ValidaEmail(txtEmailCli.Text); if (emailOk == false) { //MessageBox.Show("Email Inválido.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); //return 1; throw new Exception("email invalido"); } #region Salva Usuario if (edit == false) { if (!string.IsNullOrEmpty(txtUsuarioCli.Text) && !string.IsNullOrEmpty(txtSenhaCli.Text)) { SqlConnection conn = new SqlConnection(c); conn.Open(); SqlCommand cmd = new SqlCommand("select * from usuario where usuario = @usu", conn); SqlParameter param = new SqlParameter(); param.ParameterName = "@usu"; param.Value = txtUsuarioCli.Text; cmd.Parameters.Add(param); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); if (reader.HasRows) { MessageBox.Show("Usuário ja cadastrado.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return 1; } else { COMERCIALDataSetTableAdapters.USUARIOTableAdapter usu = new Comercial.COMERCIALDataSetTableAdapters.USUARIOTableAdapter(); usu.Insert(txtUsuarioCli.Text, txtSenhaCli.Text, "N", "S"); } reader.Dispose(); reader.Close(); conn.Close(); conn.Dispose(); } SqlConnection conn1 = new SqlConnection(c); conn1.Open(); SqlCommand cmd1 = new SqlCommand("select * from usuario where usuario = @usu", conn1); SqlParameter param1 = new SqlParameter(); param1.ParameterName = "@usu"; param1.Value = txtUsuarioCli.Text; cmd1.Parameters.Add(param1); SqlDataReader reader1 = cmd1.ExecuteReader(); reader1.Read(); x["CodUSUARIO"] = reader1["codusuario"]; reader1.Dispose(); reader1.Close(); conn1.Close(); conn1.Dispose(); } #endregion if (chckBxCred.Checked) { x["APROVADOCRED"] = "S"; } else { x["APROVADOCRED"] = "N"; } x["CEP"] = txtCepCli.getText; txtSenhaCli.Text = ""; txtUsuarioCli.Text = ""; } return 0; }
public int salvar(bool edit) { DataRowView x; x = (DataRowView)cLIENTEBindingSource.Current; Validacoes valida = new Validacoes(); string c = ConfigurationManager.ConnectionStrings["Comercial.Properties.Settings.COMERCIALConnectionString"].ConnectionString; //Valida CNPJ if (!String.IsNullOrEmpty(txtCnpjCli.Text) && txtCnpjCli.Text.Trim().Length == 14) { int cnpj = valida.ValidaCNPJ(txtCnpjCli.Text); if (cnpj == 1) { //MessageBox.Show("CNPJ Inválido.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); //return 1; throw new Exception("cnpj invalido"); } } else { throw new Exception("cnpj invalido"); } // Valida IE if (!String.IsNullOrEmpty(txtIeCli.Text)) { string ie = txtIeCli.Text; string uf = cmbUfCli.SelectedItem.ToString(); int returnIe = ConsisteInscricaoEstadual(ie, uf); if (returnIe == 1) { //MessageBox.Show("I.E. Inválida.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); //return 1; throw new Exception("ie invalida"); } //if (string.IsNullOrEmpty(txtRazaoSocialCli.Text)) //{ // MessageBox.Show("Campo(s) obrigatório(s) não preenchido(s).", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); // return 1; //} } // Valida limite de crédito // string va = txtLimCredCli.Te if (!String.IsNullOrEmpty(txtLimCredCli.Text)) { double valor = double.Parse(txtLimCredCli.Text, System.Globalization.NumberStyles.Currency); if (valor <= 0) { throw new Exception("valor invalido"); } } // Valida email if (!string.IsNullOrEmpty(txtEmailCli.Text)) { Boolean emailOk = valida.ValidaEmail(txtEmailCli.Text); if (emailOk == false) { //MessageBox.Show("Email Inválido.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); //return 1; throw new Exception("email invalido"); } #region Salva Usuario if (edit == false) { if (!string.IsNullOrEmpty(txtUsuarioCli.Text) && !string.IsNullOrEmpty(txtSenhaCli.Text)) { SqlConnection conn = new SqlConnection(c); conn.Open(); SqlCommand cmd = new SqlCommand("select * from usuario where usuario = @usu", conn); SqlParameter param = new SqlParameter(); param.ParameterName = "@usu"; param.Value = txtUsuarioCli.Text; cmd.Parameters.Add(param); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); if (reader.HasRows) { MessageBox.Show("Usuário ja cadastrado.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } else { COMERCIALDataSetTableAdapters.USUARIOTableAdapter usu = new Comercial.COMERCIALDataSetTableAdapters.USUARIOTableAdapter(); usu.Insert(txtUsuarioCli.Text, txtSenhaCli.Text, "N", "S"); } reader.Dispose(); reader.Close(); conn.Close(); conn.Dispose(); } SqlConnection conn1 = new SqlConnection(c); conn1.Open(); SqlCommand cmd1 = new SqlCommand("select * from usuario where usuario = @usu", conn1); SqlParameter param1 = new SqlParameter(); param1.ParameterName = "@usu"; param1.Value = txtUsuarioCli.Text; cmd1.Parameters.Add(param1); SqlDataReader reader1 = cmd1.ExecuteReader(); reader1.Read(); x["CodUSUARIO"] = reader1["codusuario"]; reader1.Dispose(); reader1.Close(); conn1.Close(); conn1.Dispose(); } #endregion if (chckBxCred.Checked) { x["APROVADOCRED"] = "S"; } else { x["APROVADOCRED"] = "N"; } x["CEP"] = txtCepCli.getText; txtSenhaCli.Text = ""; txtUsuarioCli.Text = ""; } return(0); }
/* * SALVAR RETORNA: * 0 - OK * 1 - ERRO */ public int salvar(bool edit) { #region Validaçoes //Valida CPFe email string c = ConfigurationManager.ConnectionStrings["Comercial.Properties.Settings.COMERCIALConnectionString"].ConnectionString; Validacoes valida = new Validacoes(); if (!string.IsNullOrEmpty(txtCPF.Text) && !string.IsNullOrEmpty(txtComissao.Text)) { int cpf = valida.ValidaCPF(txtCPF.Text); bool email = true; if (!string.IsNullOrEmpty(txtEmail.Text)) { email = valida.ValidaEmail(txtEmail.Text); } if (cpf == 1) { MessageBox.Show("CPF Inválido.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } if (email == false) { MessageBox.Show("E-mail Inválido.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } if (Convert.ToDouble(txtComissao.Text) < 0) { MessageBox.Show("Comissão Inválida.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } } else { throw new Exception("campo vazio"); } #endregion DataRowView x; x = (DataRowView)vENDEDORBindingSource.Current; #region Salva Usuario if (edit == false) { if (!string.IsNullOrEmpty(txtUsu.Text) && !string.IsNullOrEmpty(txtSenha.Text)) { SqlConnection conn = new SqlConnection(c); conn.Open(); SqlCommand cmd = new SqlCommand("select * from usuario where usuario = @usu", conn); SqlParameter param = new SqlParameter(); param.ParameterName = "@usu"; param.Value = txtUsu.Text; cmd.Parameters.Add(param); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); if (reader.HasRows) { MessageBox.Show("Usuário ja cadastrado.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } else { COMERCIALDataSetTableAdapters.USUARIOTableAdapter usu = new Comercial.COMERCIALDataSetTableAdapters.USUARIOTableAdapter(); usu.Insert(txtUsu.Text, txtSenha.Text, "N", "S"); } reader.Dispose(); reader.Close(); conn.Close(); conn.Dispose(); } SqlConnection conn1 = new SqlConnection(c); conn1.Open(); SqlCommand cmd1 = new SqlCommand("select * from usuario where usuario = @usu", conn1); SqlParameter param1 = new SqlParameter(); param1.ParameterName = "@usu"; param1.Value = txtUsu.Text; cmd1.Parameters.Add(param1); SqlDataReader reader1 = cmd1.ExecuteReader(); reader1.Read(); x["CodUSUARIO"] = reader1["codusuario"]; reader1.Dispose(); reader1.Close(); conn1.Close(); conn1.Dispose(); } #endregion x["CEP"] = txtcep.getText; x["ATIVO"] = "S"; if (radioButton1.Checked) { x["SEXO"] = "M"; } else { x["SEXO"] = "F"; } txtSenha.Text = ""; txtUsu.Text = ""; return(0); }