public static void CreateLocalBackup() { if (!Directory.Exists(backupDb)) { Directory.CreateDirectory(backupDb); } if (!Directory.Exists(backupDateMonth)) { Directory.CreateDirectory(backupDateMonth); } if (!Directory.Exists(backupDay)) { Directory.CreateDirectory(backupDay); } using (capdeEntities context = new capdeEntities()) { context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, @"EXEC [dbo].[Backup] @myBackupLocation = '" + fileBak + "', @myBaseName = '" + localDb + "'"); } if (File.Exists(Path.Combine(local, ConfigurationManager.AppSettings["ClientFileSecretName"]))) { UploadGoogleDrive(); } }
private int CadastroCJ(string cj, int raj) { using (capdeEntities context = new capdeEntities()) { CJ newCJ = new CJ { RajId = raj, CjNome = cj.ToUpper(), IsExcluido = false, }; Cidade cidade = new Cidade { CJ = newCJ, NomeCidade = StringBase.TODOS.ToString(), IsExcluido = false, }; context.CJs.Add(newCJ); context.Cidades.Add(cidade); context.SaveChanges(); return(newCJ.CjId); } }
private void CadastroSetor() { using (capdeEntities context = new capdeEntities()) { Setor verifSetor = context.Setors.Where(x => x.NomeSetor == textBox1.Text).FirstOrDefault(); if (isEditing) { Setor setor = context.Setors.Where(x => x.SetorId == idEditing).FirstOrDefault(); setor.NomeSetor = textBox1.Text; setor.IsExcluido = false; } else if (verifSetor == null) { Setor setor = new Setor { CidadeId = (int)comboBox1.SelectedValue, NomeSetor = textBox1.Text, IsExcluido = false, }; context.Setors.Add(setor); } if (isEditing || verifSetor == null) { common.SaveChanges_Database(context, true); OutEditing(); } else { MessageBox_AlreadyCadastrado(textBox1, TypeForm.Setor.ToString()); } }; }
private void CadastroCidade() { using (capdeEntities context = new capdeEntities()) { Cidade verifCidade = context.Cidades.Where(x => x.NomeCidade == textBox1.Text).FirstOrDefault(); if (isEditing) { Cidade cidade = context.Cidades.Where(x => x.CidadeId == idEditing).FirstOrDefault(); cidade.NomeCidade = textBox1.Text; cidade.IsExcluido = false; } else if (verifCidade == null) { Cidade cidade = new Cidade { CjId = (int)comboBox1.SelectedValue, NomeCidade = textBox1.Text, IsExcluido = false, }; context.Cidades.Add(cidade); } if (isEditing || verifCidade == null) { common.SaveChanges_Database(context, true); OutEditing(); } else { MessageBox_AlreadyCadastrado(textBox1, TypeForm.Cidade.ToString()); } }; }
private void CadastroCargo() { using (capdeEntities context = new capdeEntities()) { Cargo verifCargo = context.Cargoes.Where(x => x.NomeCargo == textBox1.Text).FirstOrDefault(); if (isEditing) { Cargo cargo = context.Cargoes.Where(x => x.CargoId == idEditing).FirstOrDefault(); cargo.NomeCargo = textBox1.Text; cargo.IsExcluido = false; } else if (verifCargo == null) { Cargo cargo = new Cargo { NomeCargo = textBox1.Text, IsExcluido = false, }; context.Cargoes.Add(cargo); } if (isEditing || verifCargo == null) { common.SaveChanges_Database(context, true); OutEditing(); } else { MessageBox_AlreadyCadastrado(textBox1, TypeForm.Cargo.ToString()); } }; }
private Object WichObjectEditing(capdeEntities context) { Object objToDel = new Object(); if (formAtual == (int)TypeForm.RAJ) { objToDel = context.RAJs.Where(x => x.RajId == idEditing).FirstOrDefault(); } else if (formAtual == (int)TypeForm.CJ) { objToDel = context.CJs.Where(x => x.CjId == idEditing).FirstOrDefault(); } else if (formAtual == (int)TypeForm.Cidade) { objToDel = context.Cidades.Where(x => x.CidadeId == idEditing).FirstOrDefault(); } else if (formAtual == (int)TypeForm.Setor) { objToDel = context.Setors.Where(x => x.SetorId == idEditing).FirstOrDefault(); } else if (formAtual == (int)TypeForm.Cargo) { objToDel = context.Cargoes.Where(x => x.CargoId == idEditing).FirstOrDefault(); } else if (formAtual == (int)TypeForm.Turma) { objToDel = context.Turmas.Where(x => x.TurmaId == idEditing).FirstOrDefault(); } return(objToDel); }
private void CadastroTurma() { using (capdeEntities context = new capdeEntities()) { Turma verifTurma = context.Turmas.Where(x => x.NomeTurma == textBox1.Text).FirstOrDefault(); if (isEditing) { Turma turma = context.Turmas.Where(x => x.TurmaId == idEditing).FirstOrDefault(); turma.NomeTurma = textBox1.Text; turma.IsExcluido = false; } else if (verifTurma == null) { Turma turma = new Turma { NomeTurma = textBox1.Text, IsExcluido = false, }; context.Turmas.Add(turma); } if (isEditing || verifTurma == null) { common.SaveChanges_Database(context, true); OutEditing(); } else { MessageBox_AlreadyCadastrado(textBox1, TypeForm.Turma.ToString()); } }; }
private void CadastroCJ_Form(int formtypeParameters) { this.Text = "Cadastro " + Enum.GetName(typeof(TypeForm), formtypeParameters); label1.Text = Enum.GetName(typeof(TypeForm), formtypeParameters); using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> raj = context.RAJs.Where(x => x.NomeRaj != StringBase.TODOS.ToString() && x.IsExcluido == false) .OrderBy(x => x.NomeRaj).Select(x => new { x.RajId, x.NomeRaj }).ToList(); comboBox1.SelectedIndexChanged -= comboBox1_SelectedIndexChanged; common.PreencheCombo(comboBox1, raj, "RajId", "NomeRaj"); comboBox1.SelectedIndex = -1; comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; if (comboBox1.Items.Count > 0) { comboBox1.SelectedIndex = 0; } label2 = (Label)common.MudarStatusVisible(label2, true, TypeForm.RAJ.ToString()); } label3 = (Label)common.MudarStatusVisible(label3, false, String.Empty); label4 = (Label)common.MudarStatusVisible(label4, false, String.Empty); comboBox1 = (ComboBox)common.MudarStatusVisible(comboBox1, true, String.Empty); comboBox2 = (ComboBox)common.MudarStatusVisible(comboBox2, false, String.Empty); comboBox3 = (ComboBox)common.MudarStatusVisible(comboBox3, false, String.Empty); }
private void CadastroCidade_Form() { this.Text = "Cadastro Cidade"; using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> raj = context.RAJs.Where(x => x.NomeRaj != StringBase.TODOS.ToString() && x.IsExcluido == false).OrderBy(x => x.NomeRaj) .Select(x => new { x.RajId, x.NomeRaj }).ToList(); common.PreencheCombo(comboBox2, raj, "RajId", "NomeRaj"); IEnumerable <dynamic> cj = context.CJs.Where(x => x.CjNome != StringBase.TODOS.ToString() && x.IsExcluido == false && x.RajId == (int)comboBox2.SelectedValue).OrderBy(x => x.CjNome).Select(x => new { x.CjId, x.CjNome }).ToList(); comboBox1.SelectedIndexChanged -= comboBox1_SelectedIndexChanged; common.PreencheCombo(comboBox1, cj, "CjId", "CjNome"); comboBox1.SelectedIndex = -1; comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; if (comboBox1.Items.Count > 0) { comboBox1.SelectedIndex = 0; } } label1 = (Label)common.MudarStatusVisible(label1, true, TypeForm.Cidade.ToString()); label2 = (Label)common.MudarStatusVisible(label2, true, TypeForm.CJ.ToString()); label3 = (Label)common.MudarStatusVisible(label3, true, TypeForm.RAJ.ToString()); label4 = (Label)common.MudarStatusVisible(label4, false, string.Empty); comboBox1 = (ComboBox)common.MudarStatusVisible(comboBox1, true, String.Empty); comboBox2 = (ComboBox)common.MudarStatusVisible(comboBox2, true, String.Empty); comboBox3 = (ComboBox)common.MudarStatusVisible(comboBox3, false, String.Empty); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (!String.IsNullOrEmpty(comboBox1.ValueMember) && formAtual != (int)TypeForm.Lote_Capacitar) { IEnumerable <dynamic> formEnum = null; string headerText = String.Empty; using (capdeEntities context = new capdeEntities()) { if (formAtual == (int)TypeForm.CJ) { headerText = TypeForm.CJ.ToString(); if (isAdmin) { formEnum = context.CJs.Where(x => x.CjNome != StringBase.TODOS.ToString() && x.RajId == (int)comboBox1.SelectedValue) .Select(x => new { x.CjId, x.CjNome, x.IsExcluido }).ToList(); } else { formEnum = context.CJs.Where(x => x.CjNome != StringBase.TODOS.ToString() && x.RajId == (int)comboBox1.SelectedValue && x.IsExcluido == false).Select(x => new { x.CjId, x.CjNome, x.IsExcluido }).ToList(); } } else if (formAtual == (int)TypeForm.Cidade) { headerText = TypeForm.Cidade.ToString(); if (isAdmin) { formEnum = context.Cidades.Where(x => x.NomeCidade != StringBase.TODOS.ToString() && x.CjId == (int)comboBox1.SelectedValue).Select(x => new { x.CidadeId, x.NomeCidade, x.IsExcluido }).ToList(); } else { formEnum = context.Cidades.Where(x => x.NomeCidade != StringBase.TODOS.ToString() && x.IsExcluido == false && x.CjId == (int)comboBox1.SelectedValue).Select(x => new { x.CidadeId, x.NomeCidade, x.IsExcluido }).ToList(); } } else if (formAtual == (int)TypeForm.Setor) { headerText = TypeForm.Setor.ToString(); if (isAdmin) { formEnum = context.Setors.Where(x => x.CidadeId == (int)comboBox1.SelectedValue) .Select(x => new { x.SetorId, x.NomeSetor, x.IsExcluido }).ToList(); } else { formEnum = context.Setors.Where(x => x.CidadeId == (int)comboBox1.SelectedValue && x.IsExcluido == false) .Select(x => new { x.SetorId, x.NomeSetor, x.IsExcluido }).ToList(); } } } dataGridView1.DataSource = formEnum; dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView1.Columns[1].HeaderText = headerText; dataGridView1.Columns[2].Visible = false; } }
private void SaveUserProfile() { using (capdeEntities context = new capdeEntities()) { string hash = crypt.newHash(txtUsuario.Text + txtSenha.Text); if (txtSenha.Text == txtSenhaConfirm.Text) { Usuario user = context.Usuarios.Where(x => x.Login == logedUser).FirstOrDefault(); user.Nome = textBox1.Text; user.Email = textBox2.Text; user.Login = txtUsuario.Text; user.Senha = hash; common.SaveChanges_Database(context, true); } else { MessageBox_SenhasDiferentes(); } } this.Close(); }
private int CadastroRaj(string raj) { using (capdeEntities context = new capdeEntities()) { RAJ newRaj = new RAJ { NomeRaj = raj.ToUpper(), IsExcluido = false, }; CJ cj = new CJ { RajId = newRaj.RajId, CjIdent = context.CJs.Count() + 1, CjNome = StringBase.TODOS.ToString() }; Cidade cidade = new Cidade { CjId = cj.CjId, NomeCidade = StringBase.TODOS.ToString(), }; context.RAJs.Add(newRaj); context.CJs.Add(cj); context.Cidades.Add(cidade); context.SaveChanges(); return(newRaj.RajId); } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { this.Hide(); using (capdeEntities context = new capdeEntities()) { bool hasChanged = context.DatabaseConfigs.Where(x => x.DatabaseConfigId == 1) .Select(x => x.HasChanged).First(); if (hasChanged) { try { CreateLocalBackup(); common.SaveChanges_Database(context, false); } catch (Exception ex) { comLog.SendLogError(thisAssemblyVersion.FileVersion, "Closing - Falha Backup", ex.Message + "\r\n" + ex.StackTrace, logedUser); MessageBox.Show("Houve um erro ao executar o backup", "Falha Backup", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } if (hasUpdate) { Process.Start(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\copy.bat"); } }
public void SaveChanges_Database(capdeEntities context, bool changed) { DatabaseConfig config = context.DatabaseConfigs.Where(x => x.DatabaseConfigId == 1).First(); config.HasChanged = changed; context.SaveChanges(); }
public static void CreateLocalBackup(string fileBackup) { using (capdeEntities context = new capdeEntities()) { context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, @"EXEC [dbo].[Backup] @myBackupLocation = '" + fileBackup + "', @myBaseName = '" + localDb + "'"); } }
private void btCadastrar_Click(object sender, EventArgs e) { using (capdeEntities context = new capdeEntities()) { Capacitacao capacitacao = new Capacitacao(); if (ckCapacitado.Checked) { capacitacao.DataInicio = Convert.ToDateTime(dateTInicio.Text); capacitacao.DataFim = Convert.ToDateTime(dateTFim.Text); capacitacao.IsCapacitado = true; if (radioEAD.Checked) { capacitacao.IsEAD = true; capacitacao.TurmaId = (int)cmbCapacitacao.SelectedValue; } else if (radioPresencial.Checked) { capacitacao.RajId = (int)cmbCapacitacao.SelectedValue; capacitacao.IsEAD = false; } } else { capacitacao.IsCapacitado = false; } Pessoa pessoa = new Pessoa { Nome = txtNome.Text, Registro = txtRegistro.Text, EMail = txtEmail.Text, CargoId = (int)cmbCargo.SelectedValue, Setor = context.Setors.Where(x => x.SetorId == (int)cmbSetor.SelectedValue).FirstOrDefault(), Capacitacao = capacitacao, Obs = txtOBS.Text, IsExcluido = false, IsAposentado = false, }; try { context.Capacitacaos.Add(capacitacao); context.Pessoas.Add(pessoa); common.SaveChanges_Database(context, true); } catch (Exception ex) { commonLog.SendLogError(thisAssemblyVersion.FileVersion, "Cadastro Pessoa", ex.Message + "\r\n" + ex.StackTrace, logedUser); } } LimpaCampos(); insertedData = true; common.PreencheCombos_Pessoa(cmbRAJ, cmbCJ, cmbCidade, cmbCargo, cmbSetor, cmbCapacitacao); }
private void radioPresencial_Click(object sender, EventArgs e) { cmbCapacitacao.Enabled = true; lblCapacitacao.Text = "RAJ"; using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> capacitado = context.RAJs.Select(x => new { x.RajId, x.NomeRaj }).ToList(); cmbCapacitacao = common.PreencheCombo(cmbCapacitacao, capacitado, "RajId", "NomeRaj"); } }
public ComboBox LoadTurmaCombo(ComboBox cmbTurma) { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> capacitado = context.Turmas.Where(x => x.IsExcluido == false).OrderBy(x => x.NomeTurma) .Select(x => new { x.TurmaId, x.NomeTurma }).ToList(); cmbTurma = PreencheCombo(cmbTurma, capacitado, "TurmaId", "NomeTurma"); } return(cmbTurma); }
private void AllUser() { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> user = context.Usuarios.Select(x => new { x.UsuarioId, x.Nome, x.IsAdmin }).ToList(); dgvUser.DataSource = user; dgvUser.Columns[0].Visible = false; dgvUser.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dgvUser.Columns[2].Visible = false; } }
private void tscCJ_SelectedIndexChanged(object sender, EventArgs e) { if (tscCJ.ComboBox.ValueMember != "" && tscCJ.ComboBox.SelectedValue != null) { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> cidade = context.Cidades.Where(x => x.CjId == (int)tscCJ.ComboBox.SelectedValue && x.IsExcluido == false) .Select(x => new { x.CidadeId, x.NomeCidade }).ToList(); tscCidade = common.PreencheCombo(tscCidade, cidade, "CidadeId", "NomeCidade"); } } }
private void radioPresencial_Click(object sender, EventArgs e) { cmbCapacitacao.Enabled = true; lblCapacitacao.Text = TypeForm.RAJ.ToString(); using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> capacitado = context.RAJs.Where(x => x.NomeRaj != StringBase.TODOS.ToString() && x.IsExcluido == false) .OrderBy(X => X.NomeRaj).Select(x => new { x.RajId, x.NomeRaj }).ToList(); cmbCapacitacao = common.PreencheCombo(cmbCapacitacao, capacitado, "RajId", "NomeRaj"); } }
private void cmbRAJ_SelectedValueChanged(object sender, EventArgs e) { if (cmbRAJ.ValueMember != String.Empty && cmbRAJ.SelectedValue != null) { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> CJ = context.CJs.Where(x => x.RajId == (int)cmbRAJ.SelectedValue && x.CjNome != StringBase.TODOS.ToString()) .OrderBy(x => x.CjNome).Select(x => new { x.CjId, x.CjNome }).ToList(); cmbCJ = common.PreencheCombo(cmbCJ, CJ, "CjId", "CjNome"); } } }
private void AtualizaPreencheInicial() { common.PreencheCombos_Pessoa(cmbRAJ, cmbCJ, cmbCidade, cmbCargo, cmbSetor, cmbCapacitacao); using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> RAJ = context.RAJs.Where(x => x.IsExcluido == false) .OrderByDescending(x => x.NomeRaj == StringBase.TODOS.ToString()).ThenBy(x => x.NomeRaj) .Select(x => new { x.RajId, x.NomeRaj }).ToList(); tscRAJ = common.PreencheCombo(tscRAJ, RAJ, "RajId", "NomeRaj"); } }
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { if (!String.IsNullOrEmpty(comboBox3.ValueMember)) { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> cj = context.CJs.Where(x => x.RajId == (int)comboBox3.SelectedValue && x.CjNome != StringBase.TODOS.ToString()) .OrderBy(x => x.CjNome).Select(x => new { x.CjId, x.CjNome }).ToList(); common.PreencheCombo(comboBox2, cj, "CjId", "CjNome"); } } }
private void radioPresencial_CheckedChanged(object sender, EventArgs e) { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> raj = context.RAJs.Where(x => x.NomeRaj != StringBase.TODOS.ToString() && x.IsExcluido == false) .OrderBy(x => x.NomeRaj).Select(x => new { x.RajId, x.NomeRaj }).ToList(); comboBox1.Enabled = true; comboBox1 = common.PreencheCombo(comboBox1, raj, "RajId", "NomeRaj"); label2 = (Label)common.MudarStatusVisible(label2, true, TypeForm.RAJ.ToString()); } }
private void radioEAD_CheckedChanged(object sender, EventArgs e) { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> turma = context.Turmas.Where(x => x.IsExcluido == false).OrderBy(x => x.NomeTurma) .Select(x => new { x.TurmaId, x.NomeTurma }).ToList(); comboBox1.Enabled = true; comboBox1 = common.PreencheCombo(comboBox1, turma, "TurmaId", "NomeTurma"); label2 = (Label)common.MudarStatusVisible(label2, true, TypeForm.Turma.ToString()); } }
private void cmbCJ_SelectedValueChanged(object sender, EventArgs e) { if (cmbCidade.ValueMember != String.Empty) { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> cidade = context.Cidades.Where(x => x.CjId == (int)cmbCJ.SelectedValue && x.NomeCidade != "TODOS") .OrderBy(x => x.NomeCidade).Select(x => new { x.CidadeId, x.NomeCidade }).ToList(); cmbCidade = common.PreencheCombo(cmbCidade, cidade, "CidadeId", "NomeCidade"); } } }
private void tscRAJ_SelectedIndexChanged(object sender, EventArgs e) { if (tscRAJ.ComboBox.ValueMember != "" && tscRAJ.ComboBox.SelectedValue != null) { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> CJ = context.CJs.Where(x => x.RajId == (int)tscRAJ.ComboBox.SelectedValue && x.IsExcluido == false) .OrderByDescending(x => x.CjNome == StringBase.TODOS.ToString()).ThenBy(x => x.CjNome) .Select(x => new { x.CjId, x.CjNome }).ToList(); tscCJ = common.PreencheCombo(tscCJ, CJ, "CjId", "CjNome"); } } }
private void cmbCidade_SelectedValueChanged(object sender, EventArgs e) { if (cmbSetor.ValueMember != String.Empty) { using (capdeEntities context = new capdeEntities()) { IEnumerable <dynamic> setor = context.Setors.Where(x => x.CidadeId == (int)cmbCidade.SelectedValue).OrderBy(x => x.NomeSetor) .Select(x => new { x.SetorId, x.NomeSetor }).ToList(); cmbSetor = common.PreencheCombo(cmbSetor, setor, "SetorId", "NomeSetor"); } } }
private void CadastroRAJ() { using (capdeEntities context = new capdeEntities()) { RAJ rajVerif = context.RAJs.Where(x => x.NomeRaj == textBox1.Text).FirstOrDefault(); if (isEditing) { RAJ raj = context.RAJs.Where(x => x.RajId == idEditing).FirstOrDefault(); raj.NomeRaj = textBox1.Text; raj.IsExcluido = false; } else if (rajVerif == null) { RAJ raj = new RAJ { NomeRaj = textBox1.Text, RajIdent = context.RAJs.Count() + 1, IsExcluido = false, }; CJ cj = new CJ { RajId = raj.RajId, CjIdent = context.CJs.Count() + 1, CjNome = StringBase.TODOS.ToString(), IsExcluido = false, }; Cidade cidade = new Cidade { CjId = cj.CjId, NomeCidade = StringBase.TODOS.ToString(), IsExcluido = false, }; context.RAJs.Add(raj); context.CJs.Add(cj); context.Cidades.Add(cidade); } if (isEditing || rajVerif == null) { common.SaveChanges_Database(context, true); OutEditing(); } else { MessageBox_AlreadyCadastrado(textBox1, TypeForm.RAJ.ToString()); } }; }