private int GetSQLServerVersion() { String query = "SELECT CONVERT(INTEGER, CONVERT(FLOAT, CONVERT(VARCHAR(3), SERVERPROPERTY('ProductVersion')))) majorVersion"; DBQuery dbQuery = new DBQuery(query, sqlConnection); dbQuery.Execute(true); List <Object> resultSet = dbQuery.ExtractFromResultset(typeof(SQLServerVersion)); SQLServerVersion productVersion = (SQLServerVersion)resultSet[0]; return(productVersion.majorVersion); }
private void DisplayAvailableTenants() { DBQuery dbQuery = new DBQuery(sqlConnection); // dbQuery.Query = "USE AppCommon"; // dbQuery.Execute(false); // Busca todos os tenants cadastrados no banco dbQuery.Query = "SELECT * FROM tb_tenant"; dbQuery.Execute(true); DataTable tenantTable = dbQuery.ExtractFromResultset(typeof(TenantInfo), "tenantTable"); tenantGridView.DataSource = tenantTable; tenantGridView.Columns[2].MinimumWidth = tenantGridView.Width; }
private void btnImport_Click(object sender, EventArgs e) { if (!OpenConnection()) { return; } DateTime?fileDate = PrintLogFile.GetDate(txtFileToImport.Text); if (fileDate == null) { MessageBox.Show("Arquivo inválido"); return; } DateTime startDate = fileDate.Value; DateTime endDate = startDate.Add(new TimeSpan(23, 59, 59)); DateRange dateRange = new DateRange(true); dateRange.SetRange(startDate, endDate); DBQuery query = new DBQuery(sqlConnection); query.Query = "use Accounting"; query.Execute(false); query.Query = "SELECT" + Environment.NewLine + " PRN_LOG.id jobId," + Environment.NewLine + " PRN_LOG.tenantId," + Environment.NewLine + " PRN_LOG.jobTime," + Environment.NewLine + " USR.alias userName," + Environment.NewLine + " PRN.alias printerName," + Environment.NewLine + " PRN_LOG.documentName name," + Environment.NewLine + " PRN_LOG.pageCount," + Environment.NewLine + " PRN_LOG.copyCount," + Environment.NewLine + " PRN_LOG.duplex," + Environment.NewLine + " PRN_LOG.color" + Environment.NewLine + "FROM" + Environment.NewLine + " tb_printLog PRN_LOG" + Environment.NewLine + " INNER JOIN tb_printer PRN WITH (NOLOCK)" + Environment.NewLine + " ON PRN_LOG.printerId = PRN.id" + Environment.NewLine + " INNER JOIN tb_user USR WITH (NOLOCK)" + Environment.NewLine + " ON PRN_LOG.userId = USR.id"; query.Execute(true); DataTable printLog = query.ExtractFromResultset(typeof(PrintedDocument), "tb_ptintLog"); //dataGridView1.DataSource = printLog.DefaultView; if (printLog.Rows.Count > 0) { //MessageBox.Show("Erro. Já existem registros correspondentes a data do arquivo!"); //return; } Boolean imported = ImportFile(txtFileToImport.Text); CloseConnection(); if (imported) { MessageBox.Show("Arquivo importado com sucesso."); } }
private Boolean CreateTenant() { txtProcessInfo.Text += Environment.NewLine + "Criando empresa no sistema..."; const String creationFail = "Falha ao criar a empresa no sistema. "; if (String.IsNullOrEmpty(txtTenantName.Text)) { txtProcessInfo.Text += Environment.NewLine + creationFail + "Favor informar um identificador para a empresa. "; return(false); } if (String.IsNullOrEmpty(txtTenantAlias.Text)) { txtProcessInfo.Text += Environment.NewLine + creationFail + "Favor informar um nome amigável para a empresa. "; return(false); } TenantInfo tenantInfo = null; try { DBQuery dbQuery = new DBQuery(sqlConnection); // dbQuery.Query = "USE AppCommon"; // dbQuery.Execute(false); // Insere a empresa no banco de dados (guarda o id da empresa inserida no banco) txtProcessInfo.Text += Environment.NewLine + "Inserindo a empresa no BD..."; dbQuery.Query = "INSERT INTO tb_tenant VALUES ('" + txtTenantName.Text + "', '" + txtTenantAlias.Text + "')" + Environment.NewLine + "SELECT SCOPE_IDENTITY() tenantId"; dbQuery.Execute(true); int?tenantId = dbQuery.ExtractFromResultset(); // Cria o tenantInfo, o tenantId foi o id atribuido pelo BD na operação INSERT // e obtido através do SCOPE_IDENTITY() tenantInfo = new TenantInfo(tenantId.Value, txtTenantName.Text, txtTenantAlias.Text); // Insere as preferências para empresa no banco de dados txtProcessInfo.Text += Environment.NewLine + "Inserindo preferências para a empresa no BD..."; dbQuery.Query = "INSERT INTO tb_tenantPreference VALUES (" + tenantInfo.id + ", 'sysSender', '*****@*****.**', 'System.String')"; dbQuery.Execute(false); // Insere os logins de acesso para a empresa no banco de dados txtProcessInfo.Text += Environment.NewLine + "Inserindo logins de acesso para a empresa no BD..."; dbQuery.Query = "INSERT INTO tb_login VALUES (" + tenantInfo.id + ", 'admin', '1E588BE3A984524C7F2C278686F44E72', 0, 0)" + Environment.NewLine + "INSERT INTO tb_login VALUES (" + tenantInfo.id + ", 'guest', '1E588BE3A984524C7F2C278686F44E72', 1, 0)"; dbQuery.Execute(false); // Insere o servidor de smtp default para a empresa no banco de dados txtProcessInfo.Text += Environment.NewLine + "Inserindo servidor de smtp(default) para a empresa no BD..."; dbQuery.Query = "INSERT INTO tb_smtpServer VALUES (" + tenantInfo.id + ", 'Servidor Default', 'smtp.gmail.com', 587, '*****@*****.**', 'datacopy123', 0)"; dbQuery.Execute(false); // Altera o database para "Accounting" dbQuery.Query = "USE Accounting"; dbQuery.Execute(false); // Insere o centro de custo raiz para a empresa no banco de dados txtProcessInfo.Text += Environment.NewLine + "Inserindo centro de custo (raiz) para a empresa no BD..."; dbQuery.Query = "INSERT INTO tb_costCenter VALUES (" + tenantInfo.id + ", '" + tenantInfo.alias + "', NULL)"; dbQuery.Execute(false); } catch (Exception exc) { txtProcessInfo.Text += Environment.NewLine + creationFail + Environment.NewLine + exc.Message; return(false); } // Se não houve nenhuma falha insere a empresa na lista retorna status de sucesso if (tenantList == null) { tenantList = new List <TenantInfo>(); } tenantList.Add(tenantInfo); return(true); }