using System;
using System.Data;
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.Data.SqlClient;
using System.IO;
using System.Net.Mail;
public partial class ManagerMain : System.Web.UI.Page
{
private string strFileSavePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// NFormView ܴInsertҦ
fvComponentDetails.ChangeMode(FormViewMode.Edit);
//FormViewRow fvRow = (FormViewRow)fvAddNewComponent.Row;
//btnAudit.Enabled = false;
lblBanner.Visible = false;
}
}
#region Uf䪺ʧ@
protected void btnAudit_Click(object sender, EventArgs e)
{
//ofvComponentDetails WUȡAçsComponent TableP@CompoenntID
//A@ǭnJ쵹X
FormView myFormView = (FormView)Page.FindControl("fvComponentDetails");
Label myLblComponentID = (Label)myFormView.FindControl("lblComponentID");
TextBox myTbxName = (TextBox)myFormView.FindControl("tbxName");
TextBox myTbxVersion = (TextBox)myFormView.FindControl("tbxVersion");
TextBox myTbxPath = (TextBox)myFormView.FindControl("tbxPath");
DropDownList myDdlFramework = (DropDownList)myFormView.FindControl("ddlFramework");
Label myLblContributor = (Label)myFormView.FindControl("lblContributor");
TextBox myTbxContributor = (TextBox)myFormView.FindControl("tbxContributor");
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 myTbxAcknowledgement = (TextBox)myFormView.FindControl("tbxAcknowledgement");
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");
TextBox myIsValid1 = (TextBox)myFormView.FindControl("tbxIsValid1");
TextBox myIsValid2 = (TextBox)myFormView.FindControl("tbxIsValid2");
CheckBox myCbxIsBuggy = (CheckBox)myFormView.FindControl("cbxIsBuggy");
if (String.IsNullOrEmpty(myIsValid1.Text) && String.IsNullOrEmpty(myIsValid2.Text))
{
myIsValid1.Text = Context.User.Identity.Name;
myIsValid1 = (TextBox)myFormView.FindControl("tbxIsValid1");
myIsValid2 = (TextBox)myFormView.FindControl("tbxIsValid2");
}
else if (myIsValid1.Text != myIsValid2.Text && string.IsNullOrEmpty(myIsValid1.Text) && myIsValid2.Text != Context.User.Identity.Name)
{
myIsValid1.Text = Context.User.Identity.Name;
myIsValid1 = (TextBox)myFormView.FindControl("tbxIsValid1");
}
else if (myIsValid1.Text != myIsValid2.Text && string.IsNullOrEmpty(myIsValid2.Text) && myIsValid1.Text != Context.User.Identity.Name)
{
myIsValid2.Text = Context.User.Identity.Name;
myIsValid2 = (TextBox)myFormView.FindControl("tbxIsValid2");
}
else if (myIsValid1.Text == myIsValid2.Text)
{
showMsg("fֻAiP@z̼fw");
return;
}
//next ,we all insert the all available data into database
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
// string componentID = Request.QueryString["componentID"]; //γoӴե\i
string UpdateCommand = "UPDATE COMPONENT SET NAME = " + "'" + myTbxName.Text.Trim() + "'" + ", "
+ "TYPE = " + "'" + myDdlFramework.Text.Trim() + "'" + ", "
+ "CONTRIBUTOR = " + "'" + myLblContributor.Text.Trim() + "'" + ", "
+ "FRAMEWORK = " + "'" + myDdlFramework.Text.Trim() + "'" + ", "
+ "PATH = " + "'" + myTbxPath.Text.Trim() + "'" + ", "
+ "VERSION = " + "'" + myTbxVersion.Text.Trim() + "'" + ", "
+ "SYNPOSIS = " + "'" + myTbxSynposis.Text.Trim().Replace('\'',' ' )+ "'" + ", "
+ "DESCRIPTION = " + "'" + myTbxDescription.Text.Trim() + "'" + ", "
+ "TEST_ENVIRONMENT = " + "'" + myDdlTestEnv.Text.Trim() + "'" + ", "
+ "IDE = " + "'" + myDdlIDE.Text.Trim() + "'" + ", "
+ "NOTE = " + "'" + myTbxNote.Text.Trim() + "'" + ", "
+ "TODO = " + "'" + myTbxToDo.Text.Trim() + "'" + ", "
+ "SEE_ALSO = " + "'" + myTbxSeeAlso.Text.Trim() + "'" + ", "
+ "ACKNOWLEDGEMENT = " + "'" + myTbxAcknowledgement.Text.Trim() + "'" + ", "
+ "COPYRIGHT = " + "'" + myDdlCopyright.Text.Trim() + "'" + ", "
+ "AP_ID = " + "'" + myTbxAP_ID.Text.Trim() + "'" + ", "
+ "AP_NAME = " + "'" + myTbxAP_Name.Text.Trim() + "'" + ", "
+ "EMAIL = " + "'" + myTbxEmail.Text.Trim() + "'" + ", "
+ "PHONE = " + "'" + myTbxPhone.Text.Trim() + "'" + ", "
+ "IS_VALID1 =" + "'" + myIsValid1.Text.Trim() + "'" + ", "
+ "IS_VALID2 =" + "'" + myIsValid2.Text.Trim() + "'" + ", "
+ "IS_BUGGY =" + "'" + myCbxIsBuggy.Text.Trim() + "'" + ", "
+ "STATUS =" + "'P'"
+ "WHERE COMPONENT_ID = '" + myLblComponentID.Text.Trim() + "' ";
SqlConnection Conn = new SqlConnection(CCSConnectionString);
try
{
Conn.Open();
}
catch (SqlException ex)
{
// Connection failed
showMsg(ex.Message);
}
try
{
SqlCommand command = new SqlCommand(UpdateCommand, Conn);
command.CommandType = System.Data.CommandType.Text;
command.ExecuteNonQuery();
}
catch (Exception ex)
{
showMsg(ex.Message);
}
finally
{
Conn.Close(); //remember to close the db connection
generateRSSFeed("i", myLblComponentID.Text);
}
showMsg("f֧");
fvComponentDetails.ChangeMode(FormViewMode.ReadOnly);
if (!String.IsNullOrEmpty(myIsValid1.Text) && !String.IsNullOrEmpty(myIsValid2.Text))
{
GenerateComponentsPage(""); //ͭneު
Publish2WorkSiteMP();//oGުխ
//HoEmail줸}o
SendMail2ContributorAboutPublish(myLblComponentID.Text);
}
}
#endregion
protected void showMsg(string AlertMessage)
{
Literal txtMsg = new Literal();
txtMsg.Text = "<script>alert('" + AlertMessage + "')</script>" + "<br/>";
Page.Controls.Add(txtMsg);
}
#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,DL_LINK,DESCRIPTION " +
"FROM COMPONENT WHERE NAME ='" + strComponentName + "' AND STATUS ='P' " + "WITH (NOLOCK) 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["DL_LINK"].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 gvComToDoList_SelectedIndexChanged1(object sender, EventArgs e)
{
//btnAudit.Enabled = true;
fvComponentDetails.ChangeMode(FormViewMode.Edit);
lblBanner.Visible = true;
Panel1.Visible = false;
// gvComToDoList.Visible = false;
}
protected void btnReject_Click(object sender, EventArgs e)
{
// oOaNjob quere rejectAiHisbuggyӼХܡH
// ҥHreject AR
//na@QueryStringih
FormView myFormView = (FormView)Page.FindControl("fvComponentDetails");
Label myLblComponentID = (Label)myFormView.FindControl("lblComponentID");
Label myLblContributor = (Label)myFormView.FindControl("lblContributor");
TextBox myTbxVersion = (TextBox)myFormView.FindControl("tbxVersion");
string strFramework = queryFrameworkByComponentID(myLblComponentID.Text);
//ڵA]D (Delete^nF
UpdateComponentStatusToDelete(myLblComponentID.Text);
Server.Transfer("~/WriteRejectReasonAndMail.aspx?ComponentID=" + myLblComponentID.Text + "&Contributor=" + myLblContributor.Text + "&Framework=" + strFramework + "&Version=" + myTbxVersion.Text);
}
private void UpdateComponentStatusToDelete(string strComponentID) {
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
// string componentID = Request.QueryString["componentID"]; //γoӴե\i
string UpdateCommand = "UPDATE COMPONENT SET STATUS = 'D'"
+ "WHERE COMPONENT_ID = '" + strComponentID + "' ";
SqlConnection Conn = new SqlConnection(CCSConnectionString);
try
{
Conn.Open();
}
catch (SqlException ex)
{
// Connection failed
showMsg(ex.Message);
}
try
{
SqlCommand command = new SqlCommand(UpdateCommand, Conn);
command.CommandType = System.Data.CommandType.Text;
command.ExecuteNonQuery();
}
catch (SqlException ex)
{
showMsg(ex.Message);
}
finally
{
Conn.Close(); //remember to close the db connection
}
}
private string queryFrameworkByComponentID(string strComponentID)
{
string strFramework = "";
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 FRAMEWORK FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID + "'", conn);
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
strFramework = reader["FRAMEWORK"].ToString().Trim();
}
}
catch (Exception ex)
{
showMsg(ex.Message);
}
finally
{
reader.Close();
conn.Close();
}
return strFramework;
}
protected void btnGo2Main_Click(object sender, EventArgs e)
{
Server.Transfer("~/Default.aspx");
}
#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 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 STATUS ='P' ORDER BY MYDATETIME DESC";
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><TD>" + dr["DL_CNT"].ToString().Trim() + "</TD></TR>\n" +
"<TR><TD>ثe`</TD><TD>" + dr["TOTAL_SCORE"].ToString().Trim() + "</TD>" +
"<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̡AiwG
private void SendMail2ContributorAboutPublish(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><font color=\"blue\">zҭק諸AثewQG@Τ</font><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
protected void cbxIsBuggy_CheckedChanged(object sender, EventArgs e)
{
//oQĿɡANbug
FormView myFormView = (FormView)Page.FindControl("fvComponentDetails");
Label myLblComponentID = (Label)myFormView.FindControl("lblComponentID");
string strComponentID = myLblComponentID.Text;
//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();
}
}
}