protected void SaveFile(object sender, ImageClickEventArgs e) { ImageButton imbtn = (ImageButton)sender; FileInfo file = new FileInfo(imbtn.CommandArgument); if (file.Exists) { try { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.Flush(); String qry = "UPDATE db_trainingdownloads SET DownloadCount=DownloadCount+1 WHERE FileName=@filename"; SQL.Update(qry, new String[] { "@filename" }, new Object[] { file.FullName }); Util.WriteLogWithDetails("File " + file.Name + " successfully downloaded from Presentations page.", "training_log"); Response.End(); ApplicationInstance.CompleteRequest(); } catch { Util.PageMessage(this, "There was an error downloading the file. Please try again."); } } else { Util.PageMessage(this, "There was an error downloading the file. Please try again."); } }
protected void dlScenario_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "cmdView") { Session["ScenarioID"] = Convert.ToInt32(e.CommandArgument); Response.Redirect("ScenarioDetail.aspx", false); ApplicationInstance.CompleteRequest(); //Response.Redirect("welcome.aspx"); } else if (e.CommandName == "cmdEdit") { Session["ScenarioID"] = Convert.ToInt32(e.CommandArgument); Response.Redirect("Scenario.aspx", false); ApplicationInstance.CompleteRequest(); } else if (e.CommandName == "cmdDelete") { Session["ScenarioID"] = Convert.ToInt32(e.CommandArgument); using (SqlConnection con = new SqlConnection()) { con.ConnectionString = ConfigurationManager.ConnectionStrings["CPDBCS"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "DeleteScenario"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@ScenarioID", SqlDbType.Int).Value = Convert.ToInt32(Session["ScenarioID"]); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Scenario Deleted Sucessfully..')", true); con.Close(); getScenario(); } } }
protected void Page_Load(object sender, EventArgs e) { #region Validating session if (Session["UserID"] == null || Session["IsStudent"] == null) { Response.Redirect("index.html", false); ApplicationInstance.CompleteRequest(); } #endregion Session["ScenarioID"] = null; Session["HideComment"] = null; string decsription = @"A student or pupil is a learner or someone who attends an educational institution. In Britain those attending university are termed A student or pupil is a learner or someone who attends an educational institution. In Britain those attending university are termed A student or pupil is a learner or someone who attends an educational institution. In Britain those attending university are termed A student or pupil is a learner or someone who attends an educational institution. In Britain those attending university are termed "; if (!IsPostBack) { if (Convert.ToInt32(Session["IsStudent"]) == 1) { lblwelcome.Text = "Welcome Student :" + Session["UserName"]; lblweldescp.Text = decsription; } else { lblwelcome.Text = "Welcome Admin :" + Session["UserName"]; lblweldescp.Text = ""; pnlAdmin.Visible = true; SetDashboardForAdmin(); } } }
protected void dlContents_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e) { if (e.CommandName == "cmdEdit") { Session["ContentID"] = Convert.ToInt32(e.CommandArgument); Response.Redirect("Content.aspx"); } else if (e.CommandName == "cmdDelete") { Session["ContentID"] = Convert.ToInt32(e.CommandArgument); using (SqlConnection con = new SqlConnection()) { con.ConnectionString = ConfigurationManager.ConnectionStrings["CPDBCS"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "DeleteContent"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@ContentId", SqlDbType.Int).Value = Convert.ToInt32(Session["ContentID"]); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Content Deleted Sucessfully..')", true); getContents(); } } else if (e.CommandName == "cmdView") { Session["ContentID"] = Convert.ToInt32(e.CommandArgument); Session["HideComment"] = true; Response.Redirect("SubContent.aspx", false); ApplicationInstance.CompleteRequest(); } }
protected void SaveFile(object sender, ImageClickEventArgs e) { ImageButton imbtn = (ImageButton)sender; FileInfo file = new FileInfo(imbtn.CommandArgument); if (file.Exists) { try { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.Flush(); UpdateAttributeCount(file.FullName, "DownloadCount"); Util.WriteLogWithDetails("File " + file.Name + " successfully downloaded from ToolBox", "training_log"); Response.End(); ApplicationInstance.CompleteRequest(); } catch { Util.PageMessage(this, "There was an error downloading the file. Please try again."); } } else { Util.PageMessage(this, "There was an error downloading the file. Please try again."); } }
protected void btnRandomStart_Click(object sender, EventArgs e) { var randomScenarioId = getRandomScenarioId(); Session["ScenarioID"] = randomScenarioId; Response.Redirect("ScenarioDetail.aspx", false); ApplicationInstance.CompleteRequest(); }
protected void Page_Init(object sender, EventArgs e) { if (Session["UserID"] == null || Session["IsStudent"] == null) { Response.Redirect("index.html", false); ApplicationInstance.CompleteRequest(); } }
/// <summary> /// 输出 /// </summary> /// <param name="obj"></param> public void ResponseWrite(object obj) { if (obj == null) { obj = ""; } Response.Write(obj.ToString()); ApplicationInstance.CompleteRequest(); }
/// <summary> /// Denies the authorization. /// </summary> private void DenyAuthorization() { // Notify the client that the authorization grant has been denied by the resource owner. var owinContext = Context.GetOwinContext(); var redirectUri = owinContext.Request.Query["redirect_uri"]; Response.Redirect(redirectUri + "?error=access_denied&error_description=The+user+declined+claim+permissions", true); ApplicationInstance.CompleteRequest(); }
protected void dlContentButtons_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "cmdView") { Session["ContentID"] = Convert.ToInt32(e.CommandArgument); Response.Redirect("SubContent.aspx", false); ApplicationInstance.CompleteRequest(); } }
/// <summary> /// Denies the authorization. /// </summary> private void DenyAuthorization(string errorDescription) { // Notify the client that the authorization grant has been denied by the resource owner. var owinContext = Context.GetOwinContext(); var redirectUri = owinContext.Request.Query["redirect_uri"]; Response.Redirect(redirectUri + $"?error=access_denied&error_description={errorDescription.Replace( ' ', '+' )}", true); ApplicationInstance.CompleteRequest(); }
protected void Export(object sender, EventArgs e) { DataTable dt_feedback = GetFeedback(true); if (dt_feedback.Rows.Count > 0) { String template_filename = "Survey Feedback-Template.xlsx"; String new_filename = template_filename.Replace("-Template.xlsx", "") + " - " + DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + ".xlsx"; String folder_dir = AppDomain.CurrentDomain.BaseDirectory + @"Dashboard\SurveyFeedback\XL\"; File.Copy(folder_dir + template_filename, folder_dir + Util.SanitiseStringForFilename(new_filename), true); // copy template file // Add sheet with data for each territory SpreadsheetDocument ss = ExcelAdapter.OpenSpreadSheet(folder_dir + new_filename, 99); if (ss != null) { ExcelAdapter.AddDataToWorkSheet(ss, "Survey Feedback", dt_feedback, true, true, true); ExcelAdapter.CloseSpreadSheet(ss); FileInfo file = new FileInfo(folder_dir + new_filename); if (file.Exists) { try { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.Flush(); ApplicationInstance.CompleteRequest(); Util.WriteLogWithDetails("Survey Feedback exported.", "surveyfeedback_log"); } catch { Util.PageMessage(this, "There was an error downloading the Excel file. Please try again."); } finally { file.Delete(); } } else { Util.PageMessage(this, "There was an error downloading the Excel file. Please try again."); } } } else { Util.PageMessage(this, "Nothing to export!"); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Session.Abandon(); Session.Clear(); Session["studentloginDetails"] = null; Session["adminloginDetails"] = null; Response.Redirect("Login.aspx", false); ApplicationInstance.CompleteRequest(); } }
protected void lnkscenario_Click(object sender, EventArgs e) { if (Session["UserID"] != null && Convert.ToInt32(Session["IsStudent"]) != 1) { Response.Redirect("ShowScenarios.aspx", false); ApplicationInstance.CompleteRequest(); } else if (Convert.ToBoolean(Session["IsAllowEdit"]) == true) { Response.Redirect("ShowScenarios.aspx", false); ApplicationInstance.CompleteRequest(); } }
protected void btnLogin_Click(object sender, EventArgs e) { try { if (con.State == ConnectionState.Closed) { con.Open(); } cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "STUDENT_LOGIN"; cmd.Parameters.Clear(); cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = txtUser.Text; cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = txtPass.Text; cmd.Parameters.Add("@StudentId", SqlDbType.VarChar, 50); cmd.Parameters.Add("@IsAllowEdit", SqlDbType.Bit); cmd.Parameters["@StudentId"].Direction = ParameterDirection.Output; cmd.Parameters["@IsAllowEdit"].Direction = ParameterDirection.Output; cmd.Connection = con; cmd.ExecuteNonQuery(); string studentID = cmd.Parameters["@StudentId"].Value.ToString(); Boolean isAllowEdit = Convert.ToBoolean(cmd.Parameters["@IsAllowEdit"].Value); if (!string.IsNullOrEmpty(studentID)) { Session["UserID"] = studentID; Session["IsStudent"] = 1; Session["IsAllowEdit"] = isAllowEdit; Session["UserName"] = txtUser.Text; Response.Redirect("Home.aspx", false); ApplicationInstance.CompleteRequest(); } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alert", "alert('The Username or Password is incorrect.')", true); } } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alert", "alert('" + ex.Message + "')", true); } finally { if (con.State == ConnectionState.Open) { con.Close(); } } }
protected void Page_Load(object sender, EventArgs e) { #region Validating session if (Session["UserID"] == null || Session["IsStudent"] == null) { Response.Redirect("index.html", false); ApplicationInstance.CompleteRequest(); } #endregion if (!IsPostBack) { BindListbox(GetContentDetails()); } }
protected void Button3_Click(object sender, EventArgs e) { string path1 = CommonFun.PhysicalFilePath + "imgMsg/2014-12-22/20141222111426.bmp"; FileInfo fi = new FileInfo(path1); if (fi.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment;filename=" + fi.Name); Response.AddHeader("Content-Length", fi.Length.ToString()); Response.ContentType = "application/octet-stream;charset=gb2321"; Response.WriteFile(fi.FullName); Response.Flush(); Response.Close(); ApplicationInstance.CompleteRequest(); } }
protected void Page_Load(object sender, EventArgs e) { #region Validating session if (Session["UserID"] == null || Session["IsStudent"] == null) { Response.Redirect("index.html", false); ApplicationInstance.CompleteRequest(); } if (Convert.ToInt32(Session["IsStudent"]) != 0 && Convert.ToBoolean(Session["IsAllowEdit"]) == false) { btnAddScenario.Visible = false; } #endregion Session["ScenarioID"] = null; Session["HideComment"] = null; if (!IsPostBack) { getScenario(); } }
protected void DownloadTemplates(object sender, EventArgs e) { FileInfo file = new FileInfo(Util.path + @"\Dashboard\Finance\Docs\Finance Mail Examples (Finance Mailing Options).docx"); if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.Flush(); Util.WriteLogWithDetails("Downloading Finance Mailing Options templates document", "finance_log"); Response.End(); ApplicationInstance.CompleteRequest(); } else { Util.PageMessage(this, "There was an error receiving the document!"); } }
protected void btnDownloadLog_Click(object sender, EventArgs e) { try { if (txtOutput.Text != "There is nothing to show.") { DataTable objDataTable = new DataTable(); objDataTable = clsServersDataManager.SelectServer(dgridShowData.SelectedRow.Cells[1].Text); stringArr = objDataTable.Rows[0].ItemArray.Select(arrServer => arrServer.ToString()).ToArray(); Guid objGUID = Guid.NewGuid(); String strDestinationPath = strTempPath + stringArr[1] + objGUID.ToString() + ".log"; File.WriteAllText(strDestinationPath, txtOutput.Text); Response.ContentType = "text/plain"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + stringArr[1] + ".log"); Response.TransmitFile(Server.MapPath("~/temp/" + stringArr[1] + objGUID.ToString() + ".log")); Response.Flush(); Response.SuppressContent = true; ApplicationInstance.CompleteRequest(); btnDownloadLog.Enabled = false; } } catch (Exception ex) { Guid objGUID = Guid.NewGuid(); String strException = ex.ToString(); File.WriteAllText(strLogPath + DateTime.Today.ToString("yyyyMMdd") + "-" + objGUID.ToString() + ".log", strException); lblMessageData01.Text = "خطایی در سیستم رخ داده است. لطفا کد خطای زیر را به همراه آی دی سرور به واحد نصب و راه اندازی ارسال نمایید.\r\n"; lblMessageData02.Text = DateTime.Today.ToString("yyyyMMdd") + "-" + objGUID.ToString(); } }
protected void ExportToExcel(DataTable dt_data) { Util.WriteLogWithDetails("Exporting company search results from " + dd_facet.SelectedItem.Text + ".", "search_log"); String dir = AppDomain.CurrentDomain.BaseDirectory + @"dashboard\search\xl\xltemplate.xlsx"; SpreadsheetDocument ss = ExcelAdapter.OpenSpreadSheet(dir, 99); if (ss != null) { ExcelAdapter.AddDataToWorkSheet(ss, "Exported", dt_data, true, true, false); ExcelAdapter.CloseSpreadSheet(ss); FileInfo file = new FileInfo(dir); if (file.Exists) { try { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + dd_facet.SelectedItem.Text + " Export " + "(" + DateTime.Now.ToString().Replace(" ", "-").Replace("/", "_").Replace(":", "_") .Substring(0, (DateTime.Now.ToString().Length - 3)) + DateTime.Now.ToString("tt") + ").xls\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.Flush(); ApplicationInstance.CompleteRequest(); } catch { Util.PageMessage(this, "There was an error downloading the Excel file. Please try again."); } } else { Util.PageMessage(this, "There was an error downloading the Excel file. Please try again."); } } }
protected void Page_Load(object sender, EventArgs e) { #region Validating session if (Session["UserID"] == null || Session["IsStudent"] == null) { Response.Redirect("Login.aspx", false); ApplicationInstance.CompleteRequest(); } #endregion if (!IsPostBack) { pnllearnabt.Visible = false; pnlwelcome.Visible = true; pnldetails.Visible = false; pnldesc.Visible = false; if (Convert.ToInt32(Session["IsStudent"]) != 0 && Convert.ToBoolean(Session["IsAllowEdit"]) == false) { txtdesc.ReadOnly = true; txtlearnabt.ReadOnly = true; txtwelcome.ReadOnly = true; txtScenarioDetails.ReadOnly = true; } if (Session["ScenarioID"] != null) { #region Bind scenario to data list using (SqlConnection con = new SqlConnection()) { con.ConnectionString = ConfigurationManager.ConnectionStrings["CPDBCS"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "ShowScenario"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = Session["UserID"].ToString(); cmd.Parameters.Add("@ScenarioID", SqlDbType.Int).Value = Convert.ToInt32(Session["ScenarioID"]); cmd.Connection = con; con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "Scenario"); if (ds.Tables["Scenario"].Rows.Count > 0) { lblScenarioName.Text = ds.Tables["Scenario"].Rows[0]["Name"].ToString(); txtwelcome.Text = ds.Tables["Scenario"].Rows[0]["Welcome"].ToString(); txtlearnabt.Text = ds.Tables["Scenario"].Rows[0]["LearnAbout"].ToString(); txtdesc.Text = ds.Tables["Scenario"].Rows[0]["Desciption"].ToString(); txtScenarioDetails.Text = ds.Tables["Scenario"].Rows[0]["Details"].ToString(); txtlearnabt.Text = ds.Tables["Scenario"].Rows[0]["LearnAbout"].ToString(); txtScenarioDetails.Text = ds.Tables["Scenario"].Rows[0]["Details"].ToString(); } }; #region Bind buttons to grid view using (SqlConnection con = new SqlConnection()) { con.ConnectionString = ConfigurationManager.ConnectionStrings["CPDBCS"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "ShowContentByScenarioID"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = Session["UserID"].ToString(); cmd.Parameters.Add("@ScenarioID", SqlDbType.Int).Value = Convert.ToInt32(Session["ScenarioID"]); cmd.Connection = con; con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "ContentButtons"); if (ds.Tables["ContentButtons"].Rows.Count > 0) { dlContentButtons.DataSource = ds.Tables["ContentButtons"]; dlContentButtons.DataBind(); } }; #endregion } #endregion else { Response.Redirect("Home.aspx"); } } }
protected void GenerateWidget(object sender, EventArgs e) { div_generated.Visible = false; if (tb_digital_reader_href.Text.Trim() != "" && tb_pdf_href.Text.Trim() != "" && tb_thumbnail_href.Text.Trim() != "" && tb_website_href.Text.Trim() != "" && tb_thumbnail_src.Text.Trim() != "") { String g_widget_code = Util.ReadTextFile("widget", @"MailTemplates\Widgets\"); g_widget_code = g_widget_code.Replace("%brochure_href%", tb_thumbnail_href.Text.Trim()); g_widget_code = g_widget_code.Replace("%brochure_src%", tb_thumbnail_src.Text.Trim()); g_widget_code = g_widget_code.Replace("%digital_reader_href%", tb_digital_reader_href.Text.Trim()); g_widget_code = g_widget_code.Replace("%website_href%", tb_website_href.Text.Trim()); g_widget_code = g_widget_code.Replace("%pdf_href%", tb_pdf_href.Text.Trim()); g_widget_code = g_widget_code.Replace("%widget_title%", dd_feature.Text.Trim()); lit_generated_widget.Text = g_widget_code; tb_source.Text = g_widget_code; div_generated.Visible = true; // Save widget .html file String short_month_name = dd_issues.SelectedItem.Text.Substring(0, 3) + dd_issues.SelectedItem.Text.Substring(dd_issues.SelectedItem.Text.IndexOf(" ") + 3); String feature_name = Util.SanitiseStringForFilename(dd_feature.SelectedItem.Text.Replace(@"/", "-")).Replace(" ", String.Empty); String file_name = "w3-" + dd_feature_region.Text.Substring(0, 2).ToUpper() + "-" + short_month_name + "-" + feature_name; //+"-" //+ DateTime.Now.ToString().Replace(":", "-").Replace(@"/", "-") + "-" //+ User.Identity.Name; using (TextWriter tsw = new StreamWriter(Util.path + @"\MailTemplates\Widgets\" + file_name + ".html", false)) //StreamWriter sw = File.AppendText() { tsw.WriteLine(g_widget_code); } hf_file_name.Value = file_name; // Download .html file if (cb_download.Checked) { FileInfo file = new FileInfo(Util.path + @"\MailTemplates\Widgets\" + file_name + ".html"); if (file.Exists) { try { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.Flush(); ApplicationInstance.CompleteRequest(); Util.WriteLogWithDetails("Widget File '" + file_name + ".html' generated and downloaded.", "widgetgenerator_log"); } catch { Util.PageMessage(this, "There was an error downloading the widget file. Please try again."); } } else { Util.PageMessage(this, "There was an error downloading the widget file. Please try again."); } } else { Util.WriteLogWithDetails("Widget File '" + file_name + ".html' generated.", "widgetgenerator_log"); } } else { Util.PageMessage(this, "Specify all required fields!"); } }
protected void ExportPull(object sender, EventArgs e) { DataTable dt_pull = GetPull(); bool IsData = dt_pull != null && dt_pull.Rows.Count > 0; if (IsData) { String template_filename = "Data Pull Template.xlsx"; String new_filename = Util.SanitiseStringForFilename( template_filename.Replace(" Template.xlsx", String.Empty) + " - " + Util.GetUserName() + " - " + DateTime.Now.ToString("d-M-yyyy HH-mm-ss") + ".xlsx"); String folder_dir = AppDomain.CurrentDomain.BaseDirectory + @"dashboard\leads\files\templates\"; File.Copy(folder_dir + template_filename, folder_dir + new_filename, true); // copy template file // Add sheet with data for each territory SpreadsheetDocument ss = ExcelAdapter.OpenSpreadSheet(folder_dir + new_filename, 99); if (ss != null) { String SeparatorField = dd_separate.SelectedItem.Value; if (SeparatorField != String.Empty) { // Sort by region dt_pull.DefaultView.Sort = SeparatorField + ", Company"; dt_pull = dt_pull.DefaultView.ToTable(); DataTable dt_region_data = dt_pull.Copy(); dt_region_data.Clear(); for (int i = 0; i < dt_pull.Rows.Count; i++) { DataRow dr = dt_pull.Rows[i]; dt_region_data.ImportRow(dr); String ThisSeparator = dt_pull.Rows[i][SeparatorField].ToString(); String NextSeparator = String.Empty; if (i < (dt_pull.Rows.Count - 1)) { NextSeparator = dt_pull.Rows[i + 1][SeparatorField].ToString(); } if (NextSeparator == String.Empty || ThisSeparator.ToLower().Trim() != NextSeparator.ToLower().Trim()) { ExcelAdapter.InsertWorkSheetWithData(ss, ThisSeparator, dt_region_data, true, false); dt_region_data.Clear(); } } } else { ExcelAdapter.AddDataToWorkSheet(ss, "Pull Data", dt_pull, true, true, false); } ExcelAdapter.CloseSpreadSheet(ss); FileInfo file = new FileInfo(folder_dir + new_filename); if (file.Exists) { try { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.Flush(); ApplicationInstance.CompleteRequest(); } catch { Util.PageMessageAlertify(this, "There was an error downloading the Excel file. Please try again."); } finally { file.Delete(); } } else { Util.PageMessageAlertify(this, "There was an error downloading the Excel file. Please try again."); } } } else { Util.PageMessageAlertify(this, "Nothing to export!"); } }
protected void btnPlay_Click(object sender, EventArgs e) { Response.Redirect("Home.aspx", false); ApplicationInstance.CompleteRequest(); }
protected void btnSave_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection()) { try { #region Declaration int isStudent = Convert.ToInt32(Session["IsStudent"]); string userID = Session["UserID"].ToString(); string image = null; if (fileImage.HasFile) { image = DateTime.Now.ToString("yyyyMMddHHmmssfff").ToString() + ".jpg"; string filePath = "ScenarioImages/" + image; fileImage.SaveAs(Server.MapPath(filePath)); } int scenarioID = -1; if (Session["ScenarioID"] != null) { scenarioID = Convert.ToInt32(Session["ScenarioID"]); } #endregion #region Saving parent content con.ConnectionString = ConfigurationManager.ConnectionStrings["CPDBCS"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SaveScenario"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@ScenarioID", SqlDbType.Int).Value = scenarioID; cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txtName.Text; cmd.Parameters.Add("@Welcome", SqlDbType.VarChar).Value = txtwelcome.Text; cmd.Parameters.Add("@LearnAbt", SqlDbType.VarChar).Value = txtlearnabt.Text; cmd.Parameters.Add("@Desc", SqlDbType.VarChar).Value = txtDesc.Text; cmd.Parameters.Add("@Details", SqlDbType.VarChar).Value = txtDetails.Text; cmd.Parameters.Add("@Rank", SqlDbType.VarChar).Value = "Rank Obsolete"; if (!string.IsNullOrEmpty(image)) { cmd.Parameters.Add("@Image", SqlDbType.VarChar).Value = image; } cmd.Parameters.Add("@IsCreatedByStudent", SqlDbType.Int).Value = isStudent; cmd.Parameters.Add("@CreatedBy", SqlDbType.Int).Value = userID; cmd.Parameters.Add("@NewScenarioID", SqlDbType.VarChar, 50); cmd.Parameters["@NewScenarioID"].Direction = ParameterDirection.Output; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); string newScenarioID = cmd.Parameters["@NewScenarioID"].Value.ToString(); #endregion #region Saving child content foreach (ListItem childContentID in chkContents.Items) { int contentID = Convert.ToInt32(childContentID.Value); int isDel = 0; if (!childContentID.Selected) { isDel = 1; } cmd.CommandText = "SaveScenarioContent"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@ScenarioID", SqlDbType.Int).Value = newScenarioID; cmd.Parameters.Add("@ContentID", SqlDbType.Int).Value = contentID; cmd.Parameters.Add("@IsDeleted", SqlDbType.Int).Value = isDel; cmd.Connection = con; cmd.ExecuteNonQuery(); } #endregion ScriptManager.RegisterClientScriptBlock(this, GetType(), "alert", "alert('Scenario saved successfully')", true); Response.Redirect("ShowScenarios.aspx", false); ApplicationInstance.CompleteRequest(); } catch (Exception ex) { throw new Exception(ex.Message); } }; }
protected void Page_Load(object sender, EventArgs e) { #region Validating session if (Session["UserID"] == null || Session["IsStudent"] == null) { Response.Redirect("index.html", false); ApplicationInstance.CompleteRequest(); } #endregion if (!IsPostBack) { if (Session["ScenarioID"] != null) { chkContents.Visible = false; fileImage.Enabled = false; using (SqlConnection con = new SqlConnection()) { con.ConnectionString = ConfigurationManager.ConnectionStrings["CPDBCS"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "ShowScenario"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@ScenarioID", SqlDbType.Int).Value = Convert.ToInt32(Session["ScenarioID"]); cmd.Connection = con; con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "getScenario"); if (ds.Tables["getScenario"].Rows.Count > 0) { txtName.Text = ds.Tables["getScenario"].Rows[0]["Name"].ToString(); txtDetails.Text = ds.Tables["getScenario"].Rows[0]["Details"].ToString(); txtwelcome.Text = ds.Tables["getScenario"].Rows[0]["Welcome"].ToString(); txtlearnabt.Text = ds.Tables["getScenario"].Rows[0]["LearnAbout"].ToString(); txtDesc.Text = ds.Tables["getScenario"].Rows[0]["Desciption"].ToString(); } } } #region Bind contents to checkbox list using (SqlConnection con = new SqlConnection()) { con.ConnectionString = ConfigurationManager.ConnectionStrings["CPDBCS"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "ShowContent"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = Session["UserID"].ToString(); cmd.Connection = con; con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "CreateScenario"); if (ds.Tables["CreateScenario"].Rows.Count > 0) { chkContents.DataSource = ds.Tables["CreateScenario"]; chkContents.DataTextField = "HeadingText"; chkContents.DataValueField = "ContentID"; chkContents.DataBind(); } }; #endregion } }
protected void btnAddScenario_Click(object sender, EventArgs e) { Response.Redirect("Scenario.aspx", false); ApplicationInstance.CompleteRequest(); }
protected void btnSave_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection()) { con.ConnectionString = ConfigurationManager.ConnectionStrings["CPDBCS"].ConnectionString; try { #region Declaration int hasCommentBox = 0; if (chkCommentBox.Checked) { hasCommentBox = 1; } int hasButtons = 1; int isStudent = Convert.ToInt32(Session["IsStudent"]); string userID = Session["UserID"].ToString(); string image = null; if (fileImage.HasFile) { image = DateTime.Now.ToString("yyyyMMddHHmmssfff").ToString() + ".jpg"; string filePath = "ContentImages/" + image; fileImage.SaveAs(Server.MapPath(filePath)); } int contentID = -1; if (Session["ContentID"] != null) { contentID = Convert.ToInt32(Session["ContentID"]); SqlCommand cmdd = new SqlCommand(); cmdd.CommandText = "DeleteSubContent"; cmdd.CommandType = CommandType.StoredProcedure; cmdd.Parameters.Clear(); cmdd.Parameters.Add("@ParentId", SqlDbType.Int).Value = contentID; cmdd.Connection = con; if (con.State == ConnectionState.Closed) { con.Open(); } cmdd.ExecuteNonQuery(); } #endregion #region Saving parent content SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SaveContent"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@ContentID", SqlDbType.Int).Value = contentID; cmd.Parameters.Add("@HeadingID", SqlDbType.VarChar).Value = txtHeadingID.Text; cmd.Parameters.Add("@HeadingText", SqlDbType.VarChar).Value = txtHeadingText.Text; cmd.Parameters.Add("@Contents", SqlDbType.VarChar).Value = txtContent.Text; if (!string.IsNullOrEmpty(image)) { cmd.Parameters.Add("@Image", SqlDbType.VarChar).Value = image; } cmd.Parameters.Add("@Link1Caption", SqlDbType.VarChar).Value = Link1Caption.Text; cmd.Parameters.Add("@Link1Description", SqlDbType.VarChar).Value = Link1Description.Text; cmd.Parameters.Add("@Link2Caption", SqlDbType.VarChar).Value = Link2Caption.Text; cmd.Parameters.Add("@Link2Description", SqlDbType.VarChar).Value = Link2Description.Text; cmd.Parameters.Add("@Link3Caption", SqlDbType.VarChar).Value = Link3Caption.Text; cmd.Parameters.Add("@Link3Description", SqlDbType.VarChar).Value = Link3Description.Text; cmd.Parameters.Add("@Link4Caption", SqlDbType.VarChar).Value = Link4Caption.Text; cmd.Parameters.Add("@Link4Description", SqlDbType.VarChar).Value = Link4Description.Text; cmd.Parameters.Add("@Link5Caption", SqlDbType.VarChar).Value = Link5Caption.Text; cmd.Parameters.Add("@Link5Description", SqlDbType.VarChar).Value = Link5Description.Text; cmd.Parameters.Add("@Link6Caption", SqlDbType.VarChar).Value = Link6Caption.Text; cmd.Parameters.Add("@Link6Description", SqlDbType.VarChar).Value = Link6Description.Text; cmd.Parameters.Add("@HasCommentBox", SqlDbType.Bit).Value = hasCommentBox; cmd.Parameters.Add("@HasButtons", SqlDbType.Bit).Value = hasButtons; cmd.Parameters.Add("@IsCreatedByStudent", SqlDbType.Int).Value = isStudent; cmd.Parameters.Add("@CreatedBy", SqlDbType.Int).Value = userID; cmd.Parameters.Add("@NewContentID", SqlDbType.VarChar, 50); cmd.Parameters["@NewContentID"].Direction = ParameterDirection.Output; cmd.Connection = con; if (con.State == ConnectionState.Closed) { con.Open(); } cmd.ExecuteNonQuery(); string newContentID = cmd.Parameters["@NewContentID"].Value.ToString(); #endregion Session["ContentID"] = newContentID; #region Saving child content CellEntities context = new CellEntities(); foreach (ListItem childSubContentID in chkChoices.Items) { int isDel = 0; if (!childSubContentID.Selected) { isDel = 1; } if (childSubContentID.Selected) { int childID = Convert.ToInt32(childSubContentID.Value); cmd.CommandText = "SaveSubContent"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.Add("@ParentID", SqlDbType.Int).Value = newContentID; cmd.Parameters.Add("@ChildID", SqlDbType.Int).Value = childID; cmd.Parameters.Add("@IsDeleted", SqlDbType.Int).Value = isDel; cmd.Connection = con; if (con.State == ConnectionState.Closed) { con.Open(); } cmd.ExecuteNonQuery(); } } #endregion ScriptManager.RegisterClientScriptBlock(this, GetType(), "alert", "alert('Content saved successfully')", true); } catch (Exception ex) { throw new Exception(ex.Message); } }; Response.Redirect("ShowContents.aspx", false); ApplicationInstance.CompleteRequest(); }
protected void gridStudent_RowCommand(object sender, GridViewCommandEventArgs e) { int rowIndex = Convert.ToInt32(e.CommandArgument); if (e.CommandName == "cmdDelete") { try { if (con.State == ConnectionState.Closed) { con.Open(); } cmd.Parameters.Clear(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "DELETE_STUDENT"; cmd.Parameters.Add("@studentId", SqlDbType.Int).Value = Convert.ToInt32(e.CommandArgument); cmd.Connection = con; cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (con.State == ConnectionState.Open) { con.Close(); } } Response.Redirect("manageStudent.aspx", false); ApplicationInstance.CompleteRequest(); } if (e.CommandName == "cmdSave") { try { if (con.State == ConnectionState.Closed) { con.Open(); } GridViewRow row = gridStudent.Rows[rowIndex]; string studentId = (row.FindControl("StuId") as HiddenField).Value; Boolean IsAllowedit = (row.FindControl("chkSelect") as CheckBox).Checked; cmd.Parameters.Clear(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "UpdateStudentPermission"; cmd.Parameters.Add("@StudenttId", SqlDbType.Int).Value = Convert.ToInt32(studentId); cmd.Parameters.Add("@IsAllowEdit", SqlDbType.Bit).Value = IsAllowedit; cmd.Connection = con; cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (con.State == ConnectionState.Open) { con.Close(); } } Response.Redirect("manageStudent.aspx", false); ApplicationInstance.CompleteRequest(); } }