protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "btdownload") { int i = Convert.ToInt32(e.CommandArgument); int key = Convert.ToInt32(GridView1.DataKeys[i].Values[0]); //DataRowView rowview =(DataRowView)GridView1.Rows[i].DataItem; string fileurl = GridView1.DataKeys[i].Values[1].ToString(); string filename = GridView1.DataKeys[i].Values[2].ToString(); bool temp = false; try { temp = DealFile.DownLoad(fileurl, filename, GridView1.DataKeys[i].Values[4].ToString()); } catch (Exception err) { eMessage.Message(err); //ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('" + err.Message + "')", true); } finally {} if (temp) { SqlDataSource1.UpdateCommand = "usp_UpdateSourceCount"; SqlDataSource1.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure; SqlDataSource1.UpdateParameters.Add("type", DbType.Int32, drType.SelectedValue); SqlDataSource1.UpdateParameters.Add("sourceid", DbType.Int32, key.ToString()); SqlDataSource1.UpdateParameters.Add("oldcount", DbType.Int32, GridView1.DataKeys[i].Values[3].ToString()); SqlDataSource1.Update(); DataBind(); //GridView1.DataBind(); } } }
protected void GVSourceOnline_RowCommand(object sender, GridViewCommandEventArgs e) { string filename = null; string fileurl = null; bool state = false; if (e.CommandName == "view") { SqlConnection con = new SqlConnection(DealData.constring); SqlCommand cmd = new SqlCommand("usp_OpenSourceOnline", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@sourceid", SqlDbType.Int)).Value = Convert.ToInt32(e.CommandArgument); SqlDataReader reader; try { con.Open(); reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); filename = reader["SourceName"].ToString(); fileurl = reader["FileUrl"].ToString(); } reader.Close(); state = true; } catch (SqlException err) { eMessage.Message(err); eMessage.rMessage("与数据库连接发生错误,请与管理员联系或稍候再试!"); } finally { if (con != null) { con.Close(); } } if (state) { string requesturl = "~/fileonline/" + filename.Substring(0, filename.LastIndexOf(".")) + ".html"; string htmlfileurl = fileurl.Substring(0, fileurl.LastIndexOf(".")) + ".html"; if (System.IO.File.Exists(htmlfileurl)) { Response.Redirect(requesturl); } else { DealFile.PptToHtmlFile(fileurl); Response.Redirect(requesturl); } } } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "btdelete") { int i = Convert.ToInt32(e.CommandArgument); int key = Convert.ToInt32(GridView1.DataKeys[i].Values[0].ToString()); //DataRowView rowview =(DataRowView)GridView1.Rows[i].DataItem; string fileurl = GridView1.DataKeys[i].Values[1].ToString(); if (drType.SelectedValue == "1") { if (DealFile.FilePicDelete(fileurl)) { SqlDataSource1.DeleteCommand = "usp_DeleteSource"; SqlDataSource1.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure; SqlDataSource1.DeleteParameters.Add("SourceId", DbType.Int32, key.ToString()); SqlDataSource1.DeleteParameters.Add("type", DbType.Int32, drType.SelectedValue); SqlDataSource1.Delete(); GridView1.DataBind(); } } else if (drType.SelectedValue == "2") { string pptfile = fileurl.Substring(0, fileurl.LastIndexOf(".")) + ".html"; string pptfilefolder = fileurl.Substring(0, fileurl.LastIndexOf(".")) + ".files"; if (DealFile.FilePicDelete(fileurl) && DealFile.FilePicDelete(pptfile) && DealFile.DeleteFolder(pptfilefolder)) { SqlDataSource1.DeleteCommand = "usp_DeleteSource"; SqlDataSource1.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure; SqlDataSource1.DeleteParameters.Add("SourceId", DbType.Int32, key.ToString()); SqlDataSource1.DeleteParameters.Add("type", DbType.Int32, drType.SelectedValue); SqlDataSource1.Delete(); GridView1.DataBind(); } } } }
public JsonResult AddDoc(int id, IList <IFormFile> file) { List <Object> Adicionado = new List <Object>(); var deal = _dealServices.Find(id); long size = file.Sum(f => f.Length); List <DealFile> dealfiles = new List <DealFile>(); foreach (var formFile in file) { if (formFile.Length > 0) { using (var memoryStream = new MemoryStream()) { formFile.CopyTo(memoryStream); var arq = new Smart.Core.Domain.Files.File() { BusinessEntityId = _currentUser.GetCurrentBusinessEntityId(), ContentType = formFile.ContentType, Deleted = false, DueDate = null, FileData = memoryStream.ToArray(), Name = formFile.FileName, UserSettingId = _currentUser.Id() }; var dealFile = new DealFile() { BusinessEntityId = _currentUser.GetCurrentBusinessEntityId(), Deal = deal, File = arq }; dealfiles.Add(dealFile); } } } try { dealfiles.ToList().ForEach(p => _dealFileServices.Add(p)); Adicionado.Add(new { Sucesso = true, Msg = "Ok" }); } catch (Exception e) { Adicionado.Add(new { Erro = true, Msg = e.InnerException.Message }); } return(Json(Adicionado)); }