/*
Copyright (C) 2007 Ajay Handa - jmdcms.com
This program is free software;
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
License for more details.
Some rights reserved. Please read License.txt for details.
Removing above copyright message is a violation of license terms.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace JMDCMS.Win{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region Database Build Script
private void btnBuild_Click(object sender, EventArgs e)
{
txtLog.Text = "";
txtScript.Text = "";
AppendLog("Checking Directory Structure....");
if (CheckStructure())
{
txtScript.Text += Environment.NewLine + "/*## TABLES SCRIPT ##*/" +Environment.NewLine;
txtScript.Text += GetScript(txtPath.Text + "\\SQL2005\\DDL\\Table",".TBL");
txtScript.Text += Environment.NewLine + "/*## VIEWS SCRIPT ##*/" + Environment.NewLine;
txtScript.Text += GetScript(txtPath.Text + "\\SQL2005\\DDL\\View", ".VW");
txtScript.Text += Environment.NewLine + "/*## FUNCTIONS SCRIPT ##*/" + Environment.NewLine;
txtScript.Text += GetScript(txtPath.Text + "\\SQL2005\\DDL\\Function", ".FN");
txtScript.Text += Environment.NewLine + "/*## STORED PROCEDURES SCRIPT ##*/" + Environment.NewLine;
txtScript.Text += GetScript(txtPath.Text + "\\SQL2005\\DDL\\SP", ".SP");
}
else
{
MessageBox.Show("Directory structure is not correct. Please check LOG for details.");
}
}
private bool CheckStructure()
{
bool ReturnValue = false;
ReturnValue = CheckDirectory(txtPath.Text);
if ( ReturnValue == true )
{
ReturnValue = CheckDirectory(txtPath.Text+"\\SQL2005");
}
if (ReturnValue == true)
{
ReturnValue = CheckDirectory(txtPath.Text + "\\SQL2005\\DDL");
}
if (ReturnValue == true)
{
ReturnValue = CheckDirectory(txtPath.Text + "\\SQL2005\\DDL\\Function");
}
if (ReturnValue == true)
{
ReturnValue = CheckDirectory(txtPath.Text + "\\SQL2005\\DDL\\SP");
}
if (ReturnValue == true)
{
ReturnValue = CheckDirectory(txtPath.Text + "\\SQL2005\\DDL\\Table");
}
if (ReturnValue == true)
{
ReturnValue = CheckDirectory(txtPath.Text + "\\SQL2005\\DDL\\View");
}
return ReturnValue;
}
private bool CheckDirectory(string DirPath)
{
if (Directory.Exists(DirPath))
{
return true;
}
else
{
AppendLog(string.Format("Failed: Directory {0} does not exists.", DirPath));
return false;
}
}
private void AppendLog(string LogText)
{
txtLog.Text += LogText + Environment.NewLine;
}
public static void GetAllDirFilesRecurse(string dir)
{
DirectoryInfo mainDir = new DirectoryInfo(dir);
FileSystemInfo[] items = mainDir.GetFileSystemInfos();
foreach (FileSystemInfo item in items)
{
if (item is DirectoryInfo)
{
Console.WriteLine("DIRECTORY: " + ((DirectoryInfo)item).FullName);
GetAllDirFilesRecurse(((DirectoryInfo)item).FullName);
}
if (item is FileInfo)
{
Console.WriteLine("FILE: " + ((FileInfo)item).FullName);
}
else
{
Console.WriteLine("Unknown");
}
}
}
public static string GetScript(string dir, string Ext)
{
StringBuilder sb = new StringBuilder();
DirectoryInfo mainDir = new DirectoryInfo(dir);
FileSystemInfo[] items = mainDir.GetFileSystemInfos();
foreach (FileSystemInfo item in items)
{
if (item is FileInfo)
{
FileInfo fileInfo = item as FileInfo;
if (fileInfo.Extension.ToUpper().CompareTo(Ext.ToUpper()) == 0)
sb.Append(ReadText(((FileInfo)item).FullName));
}
}
return sb.ToString();
}
public static string ReadText(string ScriptFileName)
{
if (!File.Exists(ScriptFileName))
{
throw (new FileNotFoundException(
"logfile cannot be read since it does not exist.", ScriptFileName));
}
string contents = "" + Environment.NewLine + Environment.NewLine;
using (FileStream fileStream = new FileStream(ScriptFileName,
FileMode.Open,
FileAccess.Read,
FileShare.None))
{
using (StreamReader streamReader = new StreamReader(fileStream))
{
contents += streamReader.ReadToEnd();
}
}
return contents;
}
private void button1_Click(object sender, EventArgs e)
{
/*
dgResults.Columns.Clear();
dgResults.Columns.Add("clickCommissionField", "ClickCommission");
dgResults.Columns.Add("clickCommissionField", "ClickCommission");
dgResults.Columns.Add("creativeHeightField", "creativeHeightField");
dgResults.Columns.Add("creativeWidthField", "creativeWidthField");
dgResults.Columns.Add("leadCommissionField", "leadCommissionField");
dgResults.Columns.Add("linkCodeHTMLField", "linkCodeHTMLField");
dgResults.Rows.Clear();
List<LinkData> Items = cjws.GetLinks(tvCategories.SelectedNode.Text,
txtFrom.Text, txtTo.Text);
foreach (LinkData linkData in Items)
{
dgResults.Rows.Add(new string[]
{
linkData.clickCommission,
linkData.creativeHeight,
linkData.creativeWidth,
linkData.leadCommission,
linkData.linkCodeHTML
});
}
private string cidField;
private string clickCommissionField;
private string creativeHeightField;
private string creativeWidthField;
private string leadCommissionField;
private string linkCodeHTMLField;
private string linkCodeJavascriptField;
private string linkDescriptionField;
private string linkDestinationField;
private string linkIdField;
private string linkNameField;
private string linkTypeField;
private string nameField;
private string networkRankField;
private string performanceIncentivesField;
private string relationshipStatusField;
private string saleCommissionField;
private string sevenDayEPCField;
private string threeMonthEPCField;
*/
//ListViewItem lvi = new ListViewItem(Items.ToArray(),-1);
}
#endregion
private void tvCategories_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
//cjws.GetLinks(e.Node.Text, 0, 500);
}
private void tsbProducts_Click(object sender, EventArgs e)
{
/*
private int advertiserIdField;
private string advertiserNameField;
private string clickUrlField;
private string currencyField;
private string descriptionField;
private string imageUrlField;
private string nameField;
private double priceField;
private string skuField;
private string upcField;
dgResults.Columns.Clear();
dgResults.Columns.Add("advertiserIdField", "advertiserIdField");
dgResults.Columns.Add("advertiserNameField", "advertiserNameField");
dgResults.Columns.Add("clickUrlField", "clickUrlField");
dgResults.Columns.Add("descriptionField", "descriptionField");
dgResults.Columns.Add("skuField", "skuField");
dgResults.Rows.Clear();
List<ProductData> Items = cjws.SearchProduct();
foreach (ProductData linkData in Items)
{
dgResults.Rows.Add(new string[]
{
linkData.advertiserId.ToString(),
linkData.advertiserName,
linkData.clickUrl,
linkData.description,
linkData.sku
});
}
*/
}
}
}
|