using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Xml;
using log4net;
using System.Text;
using System.IO;
using System.Net.Mail;
public partial class AddNewComponent : System.Web.UI.Page
{
private static readonly ILog log = LogManager.GetLogger("CommonComponentMngSys");
private string strFileSavePath =
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// NFormView ܴInsertҦ
fvAddNewComponent.ChangeMode(FormViewMode.Insert);
btnAdd.Visible = true;
try
{
Label lblTemp = (Label)fvAddNewComponent.FindControl("lblContributor");
lblTemp.Text = Context.User.Identity.Name; //PUT user name on pages
}
catch (Exception ex) {
showMsg(ex.Message.ToString()) ;
}
}
}
#region ņˬdYNgJƮwU, ˬdnO_
protected void InsertButton_Click(object sender, EventArgs e)
{
//A@ǭnJ쵹X
FormView myFormView = (FormView)Page.FindControl("fvAddNewComponent");
TextBox myTbxName = (TextBox)myFormView.FindControl("tbxName");
DropDownList myDdlVersion1 = (DropDownList) myFormView.FindControl("ddlVersion1");
DropDownList myDdlVersion2 = (DropDownList) myFormView.FindControl("ddlVersion2");
DropDownList myDdlVersion3 = (DropDownList) myFormView.FindControl("ddlVersion3");
TextBox myTbxPath = (TextBox)myFormView.FindControl("tbxPath");
DropDownList myDdlFramework = (DropDownList)myFormView.FindControl("ddlFramework");
Label myLblContributor = (Label) myFormView.FindControl("lblContributor");
DropDownList myDdlType = (DropDownList) myFormView.FindControl("ddlType");
TextBox myTbxNote = (TextBox) myFormView.FindControl("tbxNote");
TextBox myTbxToDo = (TextBox) myFormView.FindControl("tbxToDo");
DropDownList myDdlIDE = (DropDownList) myFormView.FindControl("ddlIDE");
TextBox myTbxDescription = (TextBox) myFormView.FindControl("tbxDescription");
TextBox myTbxSynposis = (TextBox)myFormView.FindControl("tbxSynposis");
DropDownList myDdlTestEnv = (DropDownList)myFormView.FindControl("ddlTestEnv");
DropDownList myDdlCopyright = (DropDownList)myFormView.FindControl("ddlCopyright");
TextBox myTbxAcknowledge = (TextBox)myFormView.FindControl("tbxAcknowledge");
TextBox myTbxSeeAlso = (TextBox)myFormView.FindControl("tbxSeeAlso");
TextBox myTbxAP_ID = (TextBox)myFormView.FindControl("tbxAP_ID");
TextBox myTbxAP_Name = (TextBox)myFormView.FindControl("tbxAP_Name");
TextBox myTbxEmail = (TextBox)myFormView.FindControl("tbxEmail");
TextBox myTbxPhone = (TextBox)myFormView.FindControl("tbxPhone");
//next ,we all insert the all available data into database
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
StringBuilder strBd = new StringBuilder("");
strBd.AppendFormat("{0:yyyy-MM-dd HH:mm:ss}", System.DateTime.Now);
string strComponentIDNow = Convert.ToString(findOutTheMaxComponentID() + 1);
//string UpdateCommand = "UPDATE Employees SET LastName=@LastName, FirstName=@FirstName, HomePhone=@HomePhone, HireDate=@HireDate WHERE EmployeeID=@EmployeeID";
string InsertCommand = "INSERT INTO COMPONENT ( COMPONENT_ID, NAME, TYPE, CONTRIBUTOR, FRAMEWORK, PATH, VERSION, SYNPOSIS, DESCRIPTION,"+
" TEST_ENVIRONMENT, IDE, NOTE, TODO, SEE_ALSO, ACKNOWLEDGEMENT, COPYRIGHT, AP_ID, AP_NAME, EMAIL, PHONE, MYDATETIME, STATUS)"
+ " VALUES ( " + strComponentIDNow + ","
+ "'"+ myTbxName.Text.Trim() + "'" + ","
+ "'" + myDdlType.Text.Trim() + "'" + ","
+ "'" + myLblContributor.Text.Trim() + "'" + ","
+ "'" + myDdlFramework.Text.Trim() + "'" + ","
+ "'" + myTbxPath.Text.Trim() + "'" + ","
+ "'" + myDdlVersion1.Text.Trim() + "." + myDdlVersion2.Text.Trim() + "." + myDdlVersion3.Text.Trim() + "'" + ","
+ "'" + myTbxSynposis.Text.Trim() + "'" + ","
+ "'" + myTbxDescription.Text.Trim() + "'" + ","
+ "'" + myDdlTestEnv.Text.Trim() + "'" + ","
+ "'" + myDdlIDE.Text.Trim() + "'" + ","
+ "'" + myTbxNote.Text.Trim() + "'" + ","
+ "'" + myTbxToDo.Text.Trim() + "'" + ","
+ "'" + myTbxSeeAlso.Text.Trim() + "'" + ","
+ "'" + myTbxAcknowledge.Text.Trim() + "'" + ","
+ "'" + myDdlCopyright.Text.Trim() + "'" + ","
+ "'" + myTbxAP_ID.Text.Trim() + "'" + ","
+ "'" + myTbxAP_Name.Text.Trim() + "'" + ","
+ "'" + myTbxEmail.Text.Trim() + "'" + ","
+ "'" + myTbxPhone.Text.Trim() + "'" + ","
+ "'" + strBd + "'" + ","
+ "'N')";
// showMsg(InsertCommand);
log.Info(InsertCommand);
SqlConnection Conn = new SqlConnection(CCSConnectionString);
try
{
Conn.Open();
}
catch (SqlException ex)
{
// Connection failed
showMsg(ex.Message);
}
try
{
SqlCommand command = new SqlCommand(InsertCommand, Conn);
command.CommandType = System.Data.CommandType.Text;
command.ExecuteNonQuery();
}
catch (SqlException ex)
{
showMsg(ex.Message);
}
finally
{
Conn.Close(); //remember to close the db connection
}
// generateRSSFeed("sW", myTbxName.Text.Trim()); //sWRSS Feed
string strMyVersionNow = myDdlVersion1.Text.Trim() + "." + myDdlVersion2.Text.Trim() + "." + myDdlVersion3.Text.Trim();
ImageFileUpload(strComponentIDNow, strMyVersionNow); //Wdemo
SrcCodeFileUpload(strComponentIDNow, strMyVersionNow); //WǭlX{
AddNewUser2UserTable(myLblContributor.Text.Trim()); //sWϥΪ̨ USER TableAΧsثeϥΪ̪^mƥ
// GenerateComponentsPage(""); //ͭneު
// Publish2WorkSiteMP();//oGުխ
SendMail2ContributorAboutWaitForAudit(strComponentIDNow);
myFormView.ChangeMode(FormViewMode.ReadOnly);
btnAdd.Visible = false;
}
#endregion
#region oGިt
private void Publish2WorkSiteMP()
{
// Get the full file path
string strFilePath = strFileSavePath + "compNews\\start.bat";
// Create the ProcessInfo object
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.WorkingDirectory = strFileSavePath + "compNews\\";
try
{
if (File.Exists(strFilePath))
{
// Start the process
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
// Open the batch file for reading
System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath);
// Attach the output for reading
System.IO.StreamReader sOut = proc.StandardOutput;
// Attach the in for writing
System.IO.StreamWriter sIn = proc.StandardInput;
// Write each line of the batch file to standard input
while(strm.Peek() != -1)
{
sIn.WriteLine(strm.ReadLine());
}
strm.Close();
// Exit CMD.EXE
string stEchoFmt = "# {0} run successfully. Exiting";
sIn.WriteLine(String.Format(stEchoFmt, strFilePath));
sIn.WriteLine("EXIT");
// Close the process
proc.Close();
// Read the sOut to a string.
string results = sOut.ReadToEnd().Trim();
// Close the io Streams;
sIn.Close();
sOut.Close();
// Write out the results.
// string fmtStdOut = "<font face=courier size=0>{0}</font>";
// this.Response.Write(String.Format(fmtStdOut,results.Replace(System.Environment.NewLine, "<br>")));
}
else
{
showMsg("j䤣");
}
}
catch (Exception ex)
{
showMsg(ex.Message);
}
}
#endregion
#region sWϥΪ̨USER TABLE
private void AddNewUser2UserTable(string strUserID)
{
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
SqlDataReader reader = null;
SqlConnection conn = null;
int iExistCounter = 0;
int iContributeCounter = 0;
try
{
conn = new SqlConnection(CCSConnectionString);
SqlCommand cmd = new SqlCommand("SELECT * FROM [USER] WHERE USER_ID ='" + strUserID + "' ", conn);
conn.Open();
reader = cmd.ExecuteReader();
//Ӭd߬ݬݥثeƪSoӤH
while (reader.Read())
{
iExistCounter++;
iContributeCounter = (int)reader["CONTRIBUTE_CNT"];
}
}
catch (Exception ex)
{
showMsg(ex.Message);
}
finally
{
reader.Close();
conn.Close();
}
//===============================
if (iExistCounter > 0)
{
try
{
SqlCommand updateCommand = new SqlCommand("UPDATE [USER] SET CONTRIBUTE_CNT = '"
+ Convert.ToString(iContributeCounter + 1) + "' WHERE USER_ID ='" + strUserID + "'", conn);
conn.Open();
updateCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
showMsg(ex.Message);
}
finally
{
conn.Close();
}
}
else
{
try
{
SqlCommand insertCommand = new SqlCommand("INSERT INTO [USER] (USER_ID, IS_ADM, USER_NAME, USER_SCORE, CONTRIBUTE_CNT) VALUES('"+strUserID +"',' 0','','0','0')", conn);
conn.Open();
insertCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
showMsg(ex.Message);
}
finally
{
conn.Close();
}
}
}
#endregion
#region {lXWǨ UploadSrcCode
protected void SrcCodeFileUpload(string strComponentID, string strMyVersionNow)
{
FormView myFormView = (FormView)Page.FindControl("fvAddNewComponent");
FileUpload myFileuploadSrcCode = (FileUpload)myFormView.FindControl("fileUploadSrcCode");
Label myLblUploadSrcCode= (Label)myFormView.FindControl("lblUploadSrcCode");
string fullname = strComponentID+"_"+strMyVersionNow+"_"+ myFileuploadSrcCode.FileName.ToString(); //oW
//configSection.MaxRequestLength = 1024*10; //̤jW10MBAw]ȬO4MB
string url = myFileuploadSrcCode.PostedFile.FileName.ToString(); //oӬOHe2003ΪAoWǤ|ӦWrAMAQSubStringkӱoΤWA{bݨӬOSnF
string mimeType = myFileuploadSrcCode.PostedFile.ContentType.ToString(); //MIMEe
string typ2 = fullname.Substring(fullname.LastIndexOf(".") + 1); //Wr . ᭱rŧ@
string size = myFileuploadSrcCode.PostedFile.ContentLength.ToString();
bool fileIsOK = false;
// string path = Server.MapPath("~/");
if (myFileuploadSrcCode.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(myFileuploadSrcCode.FileName).ToLower();
string[] allowedExtensions ={ ".zip", ".rar", ".c", ".cpp", ".txt",".pl",".plx", ".cs",".aspx",".m", ".asp",".vb" }; //VCiWǪɮ榡
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileIsOK = true;
}
}
}
if (fileIsOK)
{
try
{
myFileuploadSrcCode.SaveAs(Server.MapPath("~/UploadSrcCode/") + "\\" + fullname);//NOsbؿUPU
myLblUploadSrcCode.Text = ("AWǤF@ӦW" + fullname + "AMIMEe[" + mimeType + "]AW[" + typ2 + "]A@[" + size + "] bytejp<br>wgOsbFAWǥؿFI");
}
catch(Exception ex)
{
myLblUploadSrcCode.Text = ex.Message;
}
}
else
{
myLblUploadSrcCode.Text = "WǮ榡~HάOSWǵ{lX";
}
}
#endregion
#region vɮפWǨ /UploadImages/
protected void ImageFileUpload(string strComponentID, string strMyVersionNow)
{
FormView myFormView = (FormView)Page.FindControl("fvAddNewComponent");
FileUpload myFileuploadImage = (FileUpload)myFormView.FindControl("fileUploadImage");
Label myLblUploadImage = (Label)myFormView.FindControl("lblUploadImage");
string fullname = strComponentID + "_" + strMyVersionNow; //`Nsɪ覡
string url = myFileuploadImage.PostedFile.FileName.ToString(); //oӬOHe2003ΪAoWǤ|ӦWrAMAQSubStringkӱoΤWA{bݨӬOSnF
string typ = myFileuploadImage.PostedFile.ContentType.ToString(); //MIMEe
string typ2 = fullname.Substring(fullname.LastIndexOf(".") + 1); //Wr . ᭱rŧ@
string size = myFileuploadImage.PostedFile.ContentLength.ToString();
bool fileIsOK = false;
// string path = Server.MapPath("~/");
if (myFileuploadImage.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(myFileuploadImage.FileName).ToLower();
string[] allowedExtensions ={ ".gif", ".png", ".jpeg", ".jpg" }; //ΪN\F
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileIsOK = true;
}
}
if (fileIsOK)
{
try
{
myFileuploadImage.SaveAs(Server.MapPath("~/UploadImages/") + "\\" + fullname);//NOsbؿUPU
myLblUploadImage.Text = ("AWǤF@ӦW" + fullname + "AMIMEe[" + typ + "]AW[" + typ2 + "]A@[" + size + "] bytejp<br>wgOsbFAWǥؿFI");
}
catch (Exception ex)
{
myLblUploadImage.Text = ex.Message;
}
}
else
{
myLblUploadImage.Text = "WǮ榡~H";
}
}
}
#endregion
#region Xثe̤jComponent IDAoniH]SQL DB۰ʻW
protected int findOutTheMaxComponentID() {
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
#if TEST
#elif QA
#elif PRODUCTION
#endif
string SelectCommand = "SELECT MAX(COMPONENT_ID) FROM COMPONENT";
SqlConnection Conn = new SqlConnection(CCSConnectionString);
int rtnMaxComponentID =1;
try
{
Conn.Open();
}
catch (SqlException ex)
{
// Connection failed
showMsg(ex.Message);
}
try
{
SqlCommand command = new SqlCommand(SelectCommand, Conn);
command.CommandType = System.Data.CommandType.Text;
rtnMaxComponentID = Convert.ToInt32(command.ExecuteScalar());
}
catch (SqlException ex)
{
showMsg(ex.Message);
}
finally
{
Conn.Close(); //remember to close the db connection
}
return rtnMaxComponentID;
}
#endregion
#region ˬd EMAIL 榡 checkEmailFormat
protected bool checkEmailFormat(string strEmailAddress)
{
bool boolTrueOrFalse = false;
if (strEmailAddress != null)
{
bool isEmailValid = TestEmailRegex(strEmailAddress);
if (isEmailValid)
{
showMsg("EmailXG榡I");
boolTrueOrFalse = true;
}
else
{
showMsg("Email榡~I");
}
}
return boolTrueOrFalse;
}
#endregion
#region Test Email Regex
// http://www.cambiaresearch.com/c4/bf974b23-484b-41c3-b331-0bd8121d5177/Parsing-Email-Addresses-with-Regular-Expressions.aspx
protected bool TestEmailRegex(string emailAddress)
{
// string patternLenient = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
// Regex reLenient = new Regex(patternLenient);
string patternStrict = @"^(([^<>()[\]\\.,;:\s@\""]+"
+ @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
+ @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
+ @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
+ @"[a-zA-Z]{2,}))$";
Regex reStrict = new Regex(patternStrict);
// bool isLenientMatch = reLenient.IsMatch(emailAddress);
// return isLenientMatch;
bool isStrictMatch = reStrict.IsMatch(emailAddress);
return isStrictMatch;
}
#endregion
protected void fvAddNewComponent_ItemInserting(object sender, FormViewInsertEventArgs e)
{
// 22. DateTimeAѨtΦbTw\sW]Inserted^A۰ʵ@Өtήɶ
// nugƮw
}
protected void showMsg(string AlertMessage)
{
Literal txtMsg = new Literal();
txtMsg.Text = "<script>alert('" + AlertMessage + "')</script>" + "<br/>";
Page.Controls.Add(txtMsg);
}
protected void ddlVersion3_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void fvAddNewComponent_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
fvAddNewComponent.ChangeMode(FormViewMode.ReadOnly);
}
#region ͦRSS Feed z
private void generateRSSFeed(string strMsgLevel, string strComponentName)
{
SqlConnection conn = null;
SqlCommand cmd = null;
SqlDataReader reader = null;
RSSChannel channel = null;
StreamWriter sw = null;
StreamReader sr = null;
int a = 0;
try
{
channel = new RSSChannel();
channel.title = "@ظTBG@Τzt Feed";
channel.webMaster = "jiing.deng@cathaybk.com.tw";
channel.managingEditor = "jiing.deng@cathaybk.com.tw";
// channel.link = "http://www.cathaybk.com.tw";
channel.description = "@ظTBUx@Τi";
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
conn = new SqlConnection(CCSConnectionString);
cmd = new SqlCommand("SELECT NAME, FRAMEWORK, VERSION, DESCRIPTION " +
"FROM COMPONENT WHERE NAME ='" + strComponentName +"' ORDER BY NAME,VERSION DESC",
conn);
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
channel.AppendRSSItem("[" + strMsgLevel + "]" + reader["NAME"].ToString().Trim() + " for "
+ reader["FRAMEWORK"].ToString().Trim() + " Ver." +
reader["VERSION"].ToString().Trim(),
reader["DESCRIPTION"].ToString().Trim(), string.Empty);
}
reader.Close();
conn.Close();
bool isAppend = File.Exists(strFileSavePath + "CathayBkRSS.xml");
if (!isAppend)
{
sw = new StreamWriter(strFileSavePath + "CathayBkRSS.xml", false,
System.Text.Encoding.GetEncoding("utf-8"));
sw.WriteLine(channel.GenerateChannel());
}
else
{
sr = new StreamReader(strFileSavePath + "CathayBkRSS.xml", System.Text.Encoding.GetEncoding("utf-8"));
string original = sr.ReadToEnd();
sr.DiscardBufferedData();
sr.Dispose();
string newTxt = string.Empty;
for (a = 0; a < channel.itemLst.Count; a++)
{
newTxt += ((RSSItem)channel.itemLst[a]).GenerateItem();
}
//夤Ĥ@Item
int thePos = original.IndexOf("<item>");
if (thePos > 0)
{
//NHUeUguidXﻼW
int target1 = original.IndexOf("<guid>", thePos);
int target2 = 0;
while (target1 > thePos)
{
target2 = original.IndexOf("</guid>", target1 + "<guid>".Length);
string match = original.Substring(target1 + "<guid>".Length, target2 - (target1 + "<guid>".Length));
int lastSharp = match.LastIndexOf('#');
int newNum = int.Parse(match.Substring(lastSharp + "#".Length)) + a;
string newMatch = match.Substring(0, lastSharp) + "#" + newNum.ToString().Trim();
original = original.Replace("<guid>" + match + "</guid>", "<guid>" + newMatch + "</guid>");
target1 = original.IndexOf("<guid>", target2 + "</guid>".Length);
}
original = original.Insert(thePos, newTxt);
}
sw = new StreamWriter(strFileSavePath + "CathayBkRSS.xml", false, System.Text.Encoding.GetEncoding("utf-8"));
sw.WriteLine(original);
}
sw.Flush();
sw.Close();
sw.Dispose();
reader.Dispose();
cmd.Dispose();
conn.Dispose();
}
catch (Exception exp)
{
showMsg(exp.Message);
}
finally
{
reader = null;
cmd = null;
conn = null;
channel = null;
sw = null;
sr = null;
}
}
#endregion
protected void btnBackToMain_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default.aspx");
}
protected void CustomValidatorTbxNote_ServerValidate(object source, ServerValidateEventArgs args)
{
FormView myFormView = (FormView)Page.FindControl("fvAddNewComponent");
TextBox myTbxNote = (TextBox)myFormView.FindControl("tbxNote");
if (myTbxNote.Text.Length > 80)
{
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
protected void CustomValidatorToDo_ServerValidate(object source, ServerValidateEventArgs args)
{
FormView myFormView = (FormView)Page.FindControl("fvAddNewComponent");
TextBox myTbxToDo = (TextBox)myFormView.FindControl("tbxToDo");
if (myTbxToDo.Text.Length > 60)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
protected void CustomValidatorTbxDescription_ServerValidate(object source, ServerValidateEventArgs args)
{
FormView myFormView = (FormView)Page.FindControl("fvAddNewComponent");
TextBox myTbxDescription = (TextBox)myFormView.FindControl("tbxDescription");
if (myTbxDescription.Text.Length > 60)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
FormView myFormView = (FormView)Page.FindControl("fvAddNewComponent");
TextBox myTbxSynposis = (TextBox)myFormView.FindControl("tbxSynposis");
if (myTbxSynposis.Text.Length > 800)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
protected void CustomValidatorAck_ServerValidate(object source, ServerValidateEventArgs args)
{
FormView myFormView = (FormView)Page.FindControl("fvAddNewComponent");
TextBox myTbxAcknowledge = (TextBox)myFormView.FindControl("tbxAcknowledge");
if (myTbxAcknowledge.Text.Length > 60)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
protected void CustomValidatorSeeAlso_ServerValidate(object source, ServerValidateEventArgs args)
{
FormView myFormView = (FormView)Page.FindControl("fvAddNewComponent");
TextBox myTbxSeeAlso = (TextBox)myFormView.FindControl("tbxSeeAlso");
if (myTbxSeeAlso.Text.Length > 60)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
#region NӸ`ରHtmlAݰeܤިt
public void GenerateComponentsPage(string outputPath)
{
SqlDataAdapter ada = null;
DataTable tbl = null;
StreamWriter sw = null;
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
SqlConnection DBConnection = new SqlConnection(CCSConnectionString);
try
{
string tblHTML = string.Empty;
//ȿeTQ
string sqlTxt = "SELECT TOP 30 NAME,VERSION,TYPE,PATH,CONTRIBUTOR,PHONE,DL_LINK," +
"MYDATETIME,DESCRIPTION FROM COMPONENT WITH (NOLOCK)" +
" WHERE IS_VALID1 !='' AND IS_VALID2 !='' ";
ada = new SqlDataAdapter(sqlTxt, DBConnection);
tbl = new DataTable();
ada.Fill(tbl);
foreach (DataRow dr in tbl.Rows)
{
tblHTML += "<DIV ALIGN='CENTER'><TABLE BORDER='1'>\n" +
"<CAPTION><H1>" + dr["NAME"].ToString().Trim() + "</H1></CAPTION>\n" +
"<TR><TD COLSPAN='4'>" + dr["DESCRIPTION"].ToString().Trim() + "</TD></TR>\n" +
"<TR><TD></TD><TD>" + dr["VERSION"].ToString().Trim() + "</TD>" +
"<TD></TD><TD>" + dr["TYPE"].ToString().Trim() + "</TD></TR>\n" +
"<TR><TD>𪬹ϸ|</TD><TD COLSPAN='3'>" + dr["PATH"].ToString().Trim() +
"</TD></TR>\n" +
"<TR><TD>^m</TD><TD>" + dr["CONTRIBUTOR"].ToString().Trim() + "</TD>" +
"<TD>q/</TD><TD>" + dr["PHONE"].ToString().Trim() + "</TD></TR>\n" +
"<TR><TD>U}</TD></TR>\n"+
"<TR><TD>sW</TD><TD>" + dr["MYDATETIME"].ToString().Trim() + "</TD>" +
"</TR>\n" +
"</TABLE></DIV>\n" +
"<BR /><BR />\n";
}
if (tblHTML.Length > 0)
{
sw = new StreamWriter(strFileSavePath + "\\ComponentsList.html", false,
System.Text.Encoding.GetEncoding("utf-8"));
sw.WriteLine("<HTML>\n" +
"<HEAD>\n" +
"<TITLE>s@ΤoG</TITLE>\n" +
"</HEAD>\n" +
"<BODY>\n");
sw.WriteLine(tblHTML);
sw.WriteLine("</BODY>\n" +
"</HTML>\n");
sw.Flush();
sw.Close();
}
tbl.Clear();
tbl.Dispose();
ada.Dispose();
sw.Dispose();
}
catch (Exception exp)
{
throw new Exception(exp.Message);
}
finally
{
tbl = null;
ada = null;
sw = null;
}
}
#endregion
#region Heemail}o̡Aiݺz̼f
private void SendMail2ContributorAboutWaitForAudit(string strComponentID)
{
//Step 1. dEmail
string strEmailAddress = "";
SqlConnection conn = null;
SqlCommand cmd = null;
SqlDataReader reader = null;
try
{
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
conn = new SqlConnection(CCSConnectionString);
cmd = new SqlCommand("SELECT EMAIL FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID + "'", conn);
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
strEmailAddress = reader["EMAIL"].ToString().Trim();
}
}
catch (Exception ex)
{
showMsg(ex.Message);
}
finally
{
reader.Close();
conn.Close();
}
//Step 2.HoEmail }o
sendEMail("",strEmailAddress);
}
#endregion
#region HeEmailiT
private void sendEMail(string strMailBody, string strMailToAddress)
{
//PɱHez̻PϥΪ
String strTo = "<jiing.deng@cathaybk.com.tw>;" + strMailToAddress;
//ӷO@ΤztΩMz
String strFrom = "<CCOM@cathaybk.com.tw>";
String strMailSubject = "[@Τ]@ΤztΪAqHI";
if (String.IsNullOrEmpty(strMailBody))
{
strMailBody = "oOѦ@ΤztγqT</b>A<b>zҷsW/^mAثeݺz̼f<br>";
}
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "PIEX2K05.cathaybk.intra.uwccb";
client.Port = 25;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid", "pwd"); //uid, pwd please replace as yours
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new MailMessage(strFrom, strTo, strMailSubject, strMailBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
try
{
client.Send(message);
Response.Write("<font color=\"blue\">Email successfully sent.</font>");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
}
#endregion
}