diff --git a/Report Runner/Advantage Final/FilePaths.cs b/Report Runner/Advantage Final/FilePaths.cs index 46b854e..0b1f96e 100644 --- a/Report Runner/Advantage Final/FilePaths.cs +++ b/Report Runner/Advantage Final/FilePaths.cs @@ -28,11 +28,6 @@ namespace Advantage_Final } - - - - - private void button1_Click(object sender, EventArgs e) { @@ -51,7 +46,7 @@ namespace Advantage_Final private void btnExit_Click(object sender, EventArgs e) { - this.Hide(); + this.Close(); } private void textBox1_Leave(object sender, EventArgs e) @@ -100,7 +95,5 @@ namespace Advantage_Final } - - } } \ No newline at end of file diff --git a/Report Runner/Advantage Final/Form1.cs b/Report Runner/Advantage Final/Form1.cs index b5e4348..7f8e90d 100644 --- a/Report Runner/Advantage Final/Form1.cs +++ b/Report Runner/Advantage Final/Form1.cs @@ -153,10 +153,9 @@ namespace Advantage_Final { } + } - - } } @@ -177,11 +176,13 @@ namespace Advantage_Final string value = item; int i = item.IndexOf('{') + 1; string d = Path.Combine(value.Substring(i) + "\\mwddf.add"); - list.Add(d); - + list.Add(d); } { + + bool bSeparate = Options.GetBoolValue((string)Dicks.GetValue("Separate")); + bool bFileMDY = Options.GetBoolValue((string)Dicks.GetValue("FileMDY")); if ((string)Dicks.GetValue("ReportFolder") == null) { @@ -193,15 +194,12 @@ namespace Advantage_Final } DialogResult result = reportFileDialog1.ShowDialog(); - if (result == DialogResult.OK) { using (StreamReader sr = new StreamReader(reportFileDialog1.FileName)) { - - line = sr.ReadToEnd(); - + line = sr.ReadToEnd(); } foreach (string item in list) @@ -219,30 +217,30 @@ namespace Advantage_Final conn.ConnectionString = "Data Source=" + item + ";User ID=user;Password=password;" + "ServerType=REMOTE|LOCAL;TrimTrailingSpaces=True"; + AdsDataAdapter da = new AdsDataAdapter(line, conn); DataSet ds = new DataSet(); da.SelectCommand.CommandTimeout = 0; da.Fill(ds, "Dick"); DataTable dt = ds.Tables[0]; - string filepath = (string)Dicks.GetValue("ReportOutput", ""); - da.Dispose(); + string filename = Path.GetFileNameWithoutExtension(reportFileDialog1.FileName); + string filepath = (string)Dicks.GetValue("ReportOutput", ""); + if (String.IsNullOrEmpty(filepath)) + filepath = @"C:\"; + + da.Dispose(); conn.Open(); AdsDataReader reader; AdsCommand PracticeName = conn.CreateCommand(); PracticeName.CommandText = "SELECT [Practice Name] FROM [MWPRA]"; - reader = PracticeName.ExecuteReader(); while (reader.Read()) { - PracticeFolder = reader.GetString(0); - - - } dt.Columns.Add("Practice", typeof(string)); foreach (DataRow dr in dt.Rows) @@ -250,29 +248,32 @@ namespace Advantage_Final dr["Practice"] = PracticeFolder; } conn.Close(); + AdsConnection.FlushConnectionPool(); - string ReportExportPath1 = (Path.Combine((string)Dicks.GetValue("ReportOutput", ""))); - //string ReportExportPath1 = (Path.Combine((string)Dicks.GetValue("ReportOutput", "") + newPracticeName)); - string ReportExportPath = ReportExportPath1.TrimEnd('\\'); - bool exists = System.IO.Directory.Exists(ReportExportPath); + string ReportExportPath = filepath; + if(bSeparate) + ReportExportPath += "\\" + newPracticeName.Replace("\\",""); + bool exists = System.IO.Directory.Exists(ReportExportPath); if (!exists) - System.IO.Directory.CreateDirectory(ReportExportPath); - - // String rFilePath = (ReportExportPath + "\\" + Path.GetFileNameWithoutExtension(reportFileDialog1.FileName) + ".xlsx"); - String rFilePath = (ReportExportPath + "\\" + "Test" + ".xlsx"); - + System.IO.Directory.CreateDirectory(ReportExportPath); + + string ReportFile = filename; + if(bFileMDY) + ReportFile += "_" + DateTime.Now.ToShortDateString().Replace('/','_'); + + // Ready to export + String rFilePath = (ReportExportPath + "\\" + ReportFile + ".xlsx"); dt.ExportToExcel(rFilePath); + dt.Dispose(); ds.Dispose(); conn.Close(); } catch (Exception ex) - { - - + { string LogPath = ((Path.Combine((string)Dicks.GetValue("ReportOutput", "") + "\\" + "log.txt"))); bool fileExists = File.Exists(LogPath); using (StreamWriter sw = File.AppendText(LogPath)) @@ -280,16 +281,10 @@ namespace Advantage_Final sw.WriteLine(""); sw.WriteLine(ex); sw.WriteLine(""); - sw.WriteLine(oldPath); - + sw.WriteLine(oldPath); } - } continue; - - - - } @@ -299,7 +294,7 @@ namespace Advantage_Final } } - MessageBox.Show("All Done"); + MessageBox.Show("All Done"); } /// diff --git a/Report Runner/Advantage Final/Options.Designer.cs b/Report Runner/Advantage Final/Options.Designer.cs index 2ff6b43..fe7cf19 100644 --- a/Report Runner/Advantage Final/Options.Designer.cs +++ b/Report Runner/Advantage Final/Options.Designer.cs @@ -28,27 +28,14 @@ /// private void InitializeComponent() { - this.lblReportPath = new System.Windows.Forms.Label(); this.btnExit = new System.Windows.Forms.Button(); - this.lblReportOutput = new System.Windows.Forms.Label(); - this.reportFolder = new System.Windows.Forms.FolderBrowserDialog(); - this.reportOutput = new System.Windows.Forms.FolderBrowserDialog(); - this.checkBox1 = new System.Windows.Forms.CheckBox(); - this.checkBox2 = new System.Windows.Forms.CheckBox(); + this.chkSeparate = new System.Windows.Forms.CheckBox(); + this.chkFileMDY = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // - // lblReportPath - // - this.lblReportPath.AutoSize = true; - this.lblReportPath.Location = new System.Drawing.Point(12, 38); - this.lblReportPath.Name = "lblReportPath"; - this.lblReportPath.Size = new System.Drawing.Size(64, 13); - this.lblReportPath.TabIndex = 0; - this.lblReportPath.Text = "Report Path"; - // // btnExit // - this.btnExit.Location = new System.Drawing.Point(683, 383); + this.btnExit.Location = new System.Drawing.Point(71, 124); this.btnExit.Name = "btnExit"; this.btnExit.Size = new System.Drawing.Size(114, 30); this.btnExit.TabIndex = 1; @@ -56,47 +43,38 @@ this.btnExit.UseVisualStyleBackColor = true; this.btnExit.Click += new System.EventHandler(this.btnExit_Click); // - // lblReportOutput + // chkSeparate // - this.lblReportOutput.AutoSize = true; - this.lblReportOutput.Location = new System.Drawing.Point(12, 80); - this.lblReportOutput.Name = "lblReportOutput"; - this.lblReportOutput.Size = new System.Drawing.Size(74, 13); - this.lblReportOutput.TabIndex = 2; - this.lblReportOutput.Text = "Report Output"; + this.chkSeparate.AutoSize = true; + this.chkSeparate.Location = new System.Drawing.Point(26, 26); + this.chkSeparate.Name = "chkSeparate"; + this.chkSeparate.Size = new System.Drawing.Size(109, 17); + this.chkSeparate.TabIndex = 3; + this.chkSeparate.Text = "Separate Reports"; + this.chkSeparate.UseVisualStyleBackColor = true; + this.chkSeparate.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); // - // checkBox1 + // chkFileMDY // - this.checkBox1.AutoSize = true; - this.checkBox1.Location = new System.Drawing.Point(384, 66); - this.checkBox1.Name = "checkBox1"; - this.checkBox1.Size = new System.Drawing.Size(109, 17); - this.checkBox1.TabIndex = 3; - this.checkBox1.Text = "Separate Reports"; - this.checkBox1.UseVisualStyleBackColor = true; - // - // checkBox2 - // - this.checkBox2.AutoSize = true; - this.checkBox2.Location = new System.Drawing.Point(368, 146); - this.checkBox2.Name = "checkBox2"; - this.checkBox2.Size = new System.Drawing.Size(158, 17); - this.checkBox2.TabIndex = 4; - this.checkBox2.Text = "Add Mm-DD-YY to file name"; - this.checkBox2.UseVisualStyleBackColor = true; + this.chkFileMDY.AutoSize = true; + this.chkFileMDY.Location = new System.Drawing.Point(26, 67); + this.chkFileMDY.Name = "chkFileMDY"; + this.chkFileMDY.Size = new System.Drawing.Size(159, 17); + this.chkFileMDY.TabIndex = 4; + this.chkFileMDY.Text = "Add MM-DD-YY to file name"; + this.chkFileMDY.UseVisualStyleBackColor = true; + this.chkFileMDY.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); // // Options // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(846, 434); - this.Controls.Add(this.checkBox2); - this.Controls.Add(this.checkBox1); - this.Controls.Add(this.lblReportOutput); + this.ClientSize = new System.Drawing.Size(228, 184); + this.Controls.Add(this.chkFileMDY); + this.Controls.Add(this.chkSeparate); this.Controls.Add(this.btnExit); - this.Controls.Add(this.lblReportPath); this.Name = "Options"; - this.Text = "Form2"; + this.Text = "Options"; this.ResumeLayout(false); this.PerformLayout(); @@ -104,12 +82,8 @@ #endregion - private System.Windows.Forms.Label lblReportPath; private System.Windows.Forms.Button btnExit; - private System.Windows.Forms.Label lblReportOutput; - private System.Windows.Forms.FolderBrowserDialog reportFolder; - private System.Windows.Forms.FolderBrowserDialog reportOutput; - private System.Windows.Forms.CheckBox checkBox1; - private System.Windows.Forms.CheckBox checkBox2; + private System.Windows.Forms.CheckBox chkSeparate; + private System.Windows.Forms.CheckBox chkFileMDY; } } \ No newline at end of file diff --git a/Report Runner/Advantage Final/Options.cs b/Report Runner/Advantage Final/Options.cs index a43839f..f8eb126 100644 --- a/Report Runner/Advantage Final/Options.cs +++ b/Report Runner/Advantage Final/Options.cs @@ -13,12 +13,26 @@ namespace Advantage_Final { public partial class Options : Form { + public static bool GetBoolValue(string str) + { + bool b = false; + if (!String.IsNullOrEmpty(str)) + b = (str == "True") ? true : false; + return b; + } + public Options() { InitializeComponent(); - //textReportOutput.Text = (string)Dicks.GetValue("ReportOutput", ""); - //textBox1.Text = (string)Dicks.GetValue("ReportFolder", ""); - + + string SEP = (string)Dicks.GetValue("Separate"); + if(!String.IsNullOrEmpty(SEP)) + chkSeparate.Checked = (SEP == "True")? true : false; + + string FMDY = (string)Dicks.GetValue("FileMDY"); + if (!String.IsNullOrEmpty(FMDY)) + chkFileMDY.Checked = (FMDY == "True") ? true : false; + } public RegistryKey Dicks = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\PanaceanTech\\ReportRunner", true); @@ -27,24 +41,110 @@ namespace Advantage_Final private void Form1_Load(object sender, EventArgs e) { + } + + private void btnExit_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void checkBox1_CheckedChanged(object sender, EventArgs e) + { + CheckBox cb = (CheckBox)sender; + string value = cb.Checked.ToString(); + Dicks.SetValue("Separate", value); + } + + private void checkBox2_CheckedChanged(object sender, EventArgs e) + { + CheckBox cb = (CheckBox)sender; + string value = cb.Checked.ToString(); + Dicks.SetValue("FileMDY", value); + } + + /* + + public ReportName() + { + * + InitializeComponent(); + * + string FPN = (string)Form1.Dicks.GetValue("FolderPracticeName"); + string FRFN = (string)Form1.Dicks.GetValue("FolderReportFolderName"); + string FRN = (string)Form1.Dicks.GetValue("FolderReportName"); + string FMDY = (string)Form1.Dicks.GetValue("FileMDY"); + string FFPN = (string)Form1.Dicks.GetValue("FilePracticeName"); + string FFRN = (string)Form1.Dicks.GetValue("FileReportName"); + string SEP = (string)Form1.Dicks.GetValue("Separate"); + + if (FPN == "False") + { + checkFolderPracticeName.Checked = false; + } + else + checkFolderPracticeName.Checked = true; + + if (FRFN == "False") + { + checkFolderReportFolder.Checked = false; + } + else + checkFolderReportFolder.Checked = true; + + if (FRN == "False") + { + checkFolderReportName.Checked = false; + } + else checkFolderReportName.Checked = true; + + if (FMDY == "False") + { + checkFileMDY.Checked = false; + } + else + checkFileMDY.Checked = true; + + if (FFPN == "False") + { + checkFilePracticeName.Checked = false; + } + else checkFilePracticeName.Checked = true; + + if (FFRN == "False") + { + checkFileReportName.Checked = false; + } + else checkFileReportName.Checked = true; + + if (SEP == "False") + { + checkSeparate.Checked = false; + } + else + checkSeparate.Checked = true; + + // checkFolderReportFolder.Checked = (Boolean)Form1.Dicks.GetValue("FolderReportFolderName"); + // checkFolderReportName.Checked = (Boolean)Form1.Dicks.GetValue("FolderReportName"); + // checkFileMDY.Checked = (Boolean)Form1.Dicks.GetValue("FileMDY"); + // checkFilePracticeName.Checked = (Boolean)Form1.Dicks.GetValue("FilePracticeName"); + // checkFileReportName.Checked = (Boolean)Form1.Dicks.GetValue("FileReportName"); + // checkSeparate.Checked = (Boolean)Form1.Dicks.GetValue("Separate"); + + } + + private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) + { } + private void checkBox6_CheckedChanged(object sender, EventArgs e) + { - private void button1_Click(object sender, EventArgs e) + } + + private void checkFilePracticeName_CheckedChanged(object sender, EventArgs e) { - // - // This event handler was created by double-clicking the window in the designer. - // It runs on the program's startup routine. - // - //DialogResult result = reportFolder.ShowDialog(); - //if (result == DialogResult.OK) - //{ - // Dicks.SetValue("ReportFolder", reportFolder.SelectedPath); - // textBox1.Text = (string)Dicks.GetValue("ReportFolder"); - - //} } private void btnExit_Click(object sender, EventArgs e) @@ -52,51 +152,19 @@ namespace Advantage_Final this.Hide(); } - private void textBox1_Leave(object sender, EventArgs e) + private void button1_Click(object sender, EventArgs e) { - //if (System.IO.Directory.Exists(textBox1.Text)) - //{ - // Dicks.SetValue("ReportFolder", textBox1.Text.TrimEnd('\\')); - // textBox1.Text = (string)Dicks.GetValue("ReportFolder"); - //} - //else - //{ - // MessageBox.Show("Enter a valid path. Quit trying to break shit"); - // textBox1.Text = ""; - - //} - } - - private void btnOutPath_Click(object sender, EventArgs e) - { - //DialogResult result = reportOutput.ShowDialog(); - //if (result == DialogResult.OK) - //{ - // Dicks.SetValue("ReportOutput", reportOutput.SelectedPath); - // textReportOutput.Text = (string)Dicks.GetValue("ReportOutput"); - - //} - } - - private void textReportOutput_Leave(object sender, EventArgs e) - { - //if (System.IO.Directory.Exists(textReportOutput.Text)) - //{ - // Dicks.SetValue("ReportOutput", textReportOutput.Text.TrimEnd('\\')); - // textReportOutput.Text = (string)Dicks.GetValue("ReportOutput"); - //} - //else - //{ - // MessageBox.Show("Enter a valid path. Quit trying to break shit"); - // textBox1.Text = ""; - - //} - } - - private void textReportOutput_TextChanged(object sender, EventArgs e) - { - - } + Form1.Dicks.SetValue("FolderPracticeName", checkFolderPracticeName.Checked.ToString()); + Form1.Dicks.SetValue("FolderReportName", checkFolderReportName.Checked.ToString()); + Form1.Dicks.SetValue("FolderReportFolderName", checkFolderReportName.Checked.ToString()); + Form1.Dicks.SetValue("FileMDY", checkFileMDY.Checked.ToString()); + Form1.Dicks.SetValue("FilePracticeName", checkFilePracticeName.Checked.ToString()); + Form1.Dicks.SetValue("FileReportName", checkFileReportName.Checked.ToString()); + Form1.Dicks.SetValue("Separate", checkSeparate.Checked.ToString()); + this.Hide(); + } + + */ } } diff --git a/Report Runner/Advantage Final/Options.resx b/Report Runner/Advantage Final/Options.resx index 71968ae..1af7de1 100644 --- a/Report Runner/Advantage Final/Options.resx +++ b/Report Runner/Advantage Final/Options.resx @@ -117,10 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - - - 137, 17 - \ No newline at end of file