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.Text;
public partial class wantToDownloadComponent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string componentID = Request.QueryString["componentID"];
try
{
lblUserID.Text = Context.User.Identity.Name; //PUT User ID on pages
lblComponentName.Text = queryComponentNameByID(componentID);
}
catch (Exception ex)
{
showMsg(ex.Message.ToString());
}
}
protected void btnSure_Click(object sender, EventArgs e)
{
string componentID = Request.QueryString["componentID"];
// sCOMPONENT ƪDL_CNT
updateTableComponent(componentID);
//sU`ơAϥΩAP_ID AP_NAMEBUɶAUϥΪ
//nhsDL_LISTƪ
insertData2TableDownload_List(componentID);
showMsg("sUTAtΧYNziUʧ@......");
//ۭnɦVUa
//dCOMPONENTƪDL_LINKII
begin2Download(componentID);
}
#region }lU]OonURL^
private void begin2Download(string strComponentID)
{
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
SqlConnection Conn = new SqlConnection(CCSConnectionString);
SqlDataReader reader = null;
//ھComponentIDhdߤUs
SqlCommand strQueryCommand =new SqlCommand("SELECT DL_LINK FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID + "'", Conn);
try
{
Conn.Open();
reader = strQueryCommand.ExecuteReader();
while (reader.Read())
{
string strURL = reader["DL_LINK"].ToString().Trim();
if (String.IsNullOrEmpty(strURL) )
{
showMsg("URLšAгqz̡I");
Server.Transfer("~/Default.aspx");
}
else
{
Server.Transfer("~/Downloading.aspx?URL=" + strURL);
}
}
}
catch (Exception ex)
{
showMsg(ex.Message);
}
finally
{
reader.Close();
Conn.Close();
}
// string strURL = @"http://localhost/"; //nɦVs
// strURL = @"~/Default.aspx"; //for debug
// Response.Redirect(strURL);
}
#endregion
#region JAP_ID M AP_NAME DOWNLOAD_LIST
private void insertData2TableDownload_List(string component_ID)
{
string strComponentID = component_ID;
string strComponentVersion = queryComponentVersionByID(strComponentID);
string strUserID = lblUserID.Text;
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
SqlConnection Conn = new SqlConnection(CCSConnectionString);
//ססססססססססססססססססססססססססססססססססס
//AhsDOWNLOAD_LIST
if (String.IsNullOrEmpty(tbxAP_ID.Text))
{
tbxAP_ID.Text = "";
}
//if (String.IsNullOrEmpty(tbxAP_NAME.Text))
//{
// tbxAP_NAME.Text = "";
//}
StringBuilder strBd = new StringBuilder("");
strBd.AppendFormat("{0:yyyy/MM/dd-hh:mm:ss}", System.DateTime.Now);
string InsertCommand =
"INSERT INTO DOWNLOAD_LIST (USER_ID, COMPONENT_ID, VERSION, MYDATETIME, AP_ID, AP_NAME) VALUES( '"
+ lblUserID.Text + "', '" + strComponentID + "', '" + strComponentVersion + "', '" + strBd + "', '" + tbxAP_ID.Text + "', '" + tbxAP_NAME.Text + "')";
// showMsg(InsertCommand);
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
}
}
#endregion
#region sCOMPONENT ƪDL_CNT
private void updateTableComponent(string component_ID)
{
string componentID = component_ID;
string strComponentVersion = queryComponentVersionByID(componentID);
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
//oثeUƭȡ]w]NO1^
string QueryDL_CNT = "SELECT DL_CNT FROM COMPONENT WHERE COMPONENT_ID = '" + componentID + "'";
SqlConnection Conn = new SqlConnection(CCSConnectionString);
int rtnNumOfDL_CNT = 0; //initialize the variable
try
{
Conn.Open();
}
catch (SqlException ex)
{
// Connection failed
showMsg(ex.Message);
}
try
{
SqlCommand command = new SqlCommand(QueryDL_CNT, Conn);
command.CommandType = System.Data.CommandType.Text;
rtnNumOfDL_CNT = Convert.ToInt32(command.ExecuteScalar());
}
catch (SqlException ex)
{
showMsg(ex.Message);
}
finally
{
Conn.Close(); //remember to close the db connection
}
//sCOMPONENT ƪDLCNTAMnAhs DOWNLOAD_LIST
string UpdateCommand =
"UPDATE COMPONENT SET DL_CNT = " + "'" + (rtnNumOfDL_CNT + 1) + "'"
+" WHERE COMPONENT_ID = '" + componentID + "'";
showMsg(UpdateCommand);
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
}
}
#endregion
#region COMPONENT_IDhdߤX
private string queryComponentVersionByID(string strComponentID)
{
string strComponentVersion = String.Empty;
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
SqlConnection conn = new SqlConnection(CCSConnectionString);
SqlCommand cmd = new SqlCommand("SELECT VERSION FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID + "' ORDER BY VERSION DESC",
conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
strComponentVersion = reader["VERSION"].ToString().Trim();
}
reader.Close();
conn.Close();
return strComponentVersion;
}
#endregion
#region Hcomponent_IDdߤW
private string queryComponentNameByID(string strComponentID)
{
string strComponentName = String.Empty;
ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
string CCSConnectionString = connSettings.ConnectionString;
SqlConnection conn = new SqlConnection(CCSConnectionString);
SqlCommand cmd = new SqlCommand("SELECT NAME FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID + "' ORDER BY NAME DESC",
conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
strComponentName = reader["NAME"].ToString().Trim();
}
reader.Close();
conn.Close();
return strComponentName;
}
#endregion
protected void showMsg(string AlertMessage)
{
Literal txtMsg = new Literal();
txtMsg.Text = "<script>alert('" + AlertMessage + "')</script>" + "<br/>";
Page.Controls.Add(txtMsg);
}
}