static void Main(string[] args) { /*foreach (var VARIABLE in args) * { * Console.WriteLine(VARIABLE); * }*/ /*args = new string[3] { "fajlli.xlsx", * "CRMSWEB", "SELECT * FROM HelpDesk.Tickets" };*/ if (!args.Any()) { var l = new Login(); l.ShowDialog(); } else if (args.Count() == 3) { try { string connectionString = "", sqlQuery = ""; var location = ConfigurationManager.AppSettings["location"].ToString(); if (args[1] == null || args[2] == null || args[0] == null && string.IsNullOrEmpty(location)) { return; } string filePath = location + args[0]; connectionString = ConfigurationManager.ConnectionStrings[args[1]].ConnectionString; sqlQuery = args[2]; BL.DefaultConnectionString = connectionString; if (BL.CanConnect()) { var ee = new BusinessEntity.ExcelExporter(ExcelTypeExporter.AutomationUseArray, filePath); ee.Automation_QueryTable(filePath, connectionString, sqlQuery); //Process.Start(/*location + */ // ReSharper disable once AssignNullToNotNullAttribute //fileName: args[0]); } else { throw new Exception("asdf"); } } catch (Exception ex) { Console.WriteLine(ex.Message); return; } } else { Console.WriteLine(@"Ju lutem qe ti ipni 3 parametra si vijon:" + @"1. FilePath\FileName" + @"2. Connection String" + @"3. sqlQuery ose proceduren me parametra"); } }
void Connect() { if (cbAuthentication.Text != @"Windows Authentication") { BL.DefaultConnectionString = $"Server={txtServerName.Text};Database={cbDatabase.Text};User Id={txtUserName.Text};Password={txtPassword.Text};Trusted_Connection=False;"; } else { BL.DefaultConnectionString = $"Server={txtServerName.Text};Database={cbDatabase.Text};Trusted_Connection=True;"; } if (chbSaveConfiguration.Checked) { Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath); config.AppSettings.Settings["server"].Value = txtServerName.Text; //config.AppSettings.Settings["database"].Value = txtDatabase.Text; config.AppSettings.Settings["save"].Value = "1"; config.Save(ConfigurationSaveMode.Modified); } else { Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath); config.AppSettings.Settings["server"].Value = ""; //config.AppSettings.Settings["database"].Value = ""; config.AppSettings.Settings["save"].Value = "0"; config.Save(ConfigurationSaveMode.Modified); } if (BL.CanConnect()) { CurrentSettings.Database = cbDatabase.Text; CurrentSettings.ServerName = txtServerName.Text; var f = new ExporterForm(); Hide(); f.ShowDialog(); Close(); } else { MessageBox.Show(@"(N)"); } }
void GetDatabases() { cbDatabase.DataSource = null; cbDatabase.Refresh(); if (cbAuthentication.SelectedIndex == 1) { DataConnection.ConnectionString = $@"Server={txtServerName.Text};Database=master;User Id={txtUserName.Text};Password={ txtPassword.Text };Trusted_Connection=False;"; } else if (cbAuthentication.SelectedIndex == 0) { DataConnection.ConnectionString = $@"Server={txtServerName.Text};Database=master;Trusted_Connection=True;"; } if (BL.CanConnect()) { cbDatabase.DataSource = BLL.GetDatabases(); cbDatabase.Refresh(); } }