public List<FileInfoMation> File_GetByAll() { List<FileInfoMation> list = new List<FileInfoMation>(); using (SqlConnection Conn = new SqlConnection(Common.GetConnectString())) { try { Conn.Open(); using (SqlCommand cmd = new SqlCommand("DDV_GetFileInfo", Conn)) { FileInfoMation obj = new FileInfoMation(); cmd.CommandType = CommandType.StoredProcedure; SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { list.Add(obj.CustomerIDataReader(dr)); } } dr.Close(); } } catch (Exception ex) { throw ex; } finally { Conn.Close(); } } return list; }
public void File_Insert(FileInfoMation data) { using (SqlConnection Conn = new SqlConnection(Common.GetConnectString())) { try { Conn.Open(); using (SqlCommand dbCmd = new SqlCommand("DDV_InsertFileInfo", Conn)) { dbCmd.CommandType = CommandType.StoredProcedure; dbCmd.Parameters.Add(new SqlParameter("@File_Sharing_ID", data.File_Sharing_ID)); dbCmd.Parameters.Add(new SqlParameter("@File_Name", data.File_Name)); dbCmd.Parameters.Add(new SqlParameter("@File_Size", data.File_Size)); dbCmd.Parameters.Add(new SqlParameter("@Upload_Date", data.Upload_Date)); dbCmd.ExecuteNonQuery(); } } catch (Exception ex) { throw ex; } finally { Conn.Close(); } } }
//Customer Insert public static void File_Insert(FileInfoMation obj) { db.File_Insert(obj); }
//Customer Update public static void File_Update(FileInfoMation obj) { db.File_Update(obj); }
public FileInfoMation CustomerIDataReader(IDataReader dr) { FileInfoMation obj = new FileInfoMation(); obj.File_Sharing_ID = (dr["File_Sharing_ID"] is DBNull) ? string.Empty : dr["File_Sharing_ID"].ToString(); obj.File_Name = (dr["File_Name"] is DBNull) ? string.Empty : dr["File_Name"].ToString(); obj.File_Size = (dr["File_Size"] is DBNull) ? string.Empty : dr["File_Size"].ToString(); obj.Upload_Date = (dr["Upload_Date"] is DBNull) ? string.Empty : dr["Upload_Date"].ToString(); return obj; }
/// <summary> /// ButtonAdd Click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ButtonAdd_Click(object sender, EventArgs e) { try { List<FileInfoMation> list = new List<FileInfoMation>(); //Check exist file file txtFilePath.Text = ""; if (PostedFiles.ContainsKey(Path.GetFileName(FileUploadSelect.PostedFile.FileName))) { //already exist file PostedFiles.Remove(Path.GetFileName(FileUploadSelect.PostedFile.FileName)); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('" + GetResource("MSG_SELECTED_FILE_ALREADY_UPLOAD") + "');", true); return; } if (string.IsNullOrEmpty(Path.GetFileName(FileUploadSelect.PostedFile.FileName))) { //Not file ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('" + GetResource("MSG_SELECTED_FILE_NOT_EXIST") + "');", true); return; } // pass if (!PostedFiles.ContainsKey(Path.GetFileName(FileUploadSelect.PostedFile.FileName))) { List<FileInfoMation> listtemp = new List<FileInfoMation>(); FileInfoMation obj = new FileInfoMation(); if (ViewState["HashCheckArray"] != null) list = (List<FileInfoMation>)ViewState["HashCheckArray"]; listtemp = list.Where(c => c.File_Name == Path.GetFileName(FileUploadSelect.PostedFile.FileName)).ToList(); if (listtemp.Count > 0) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('" + GetResource("MSG_SELECTED_FILE_ALREADY_UPLOAD") + "');", true); return; } if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "" && FileUploadSelect.FileContent.Length >= Constant.MAX_FILE_COMPARE) { string blobName = "Temp/" + HiddenFieldAccount.Value + "/" + FileUploadSelect.PostedFile.FileName; BlobManager blob = new BlobManager(); blob.UploadFromStream(FileUploadSelect.PostedFile.InputStream, blobName); PostedFiles.Add(Path.GetFileName(FileUploadSelect.PostedFile.FileName), null); } else { PostedFiles.Add(Path.GetFileName(FileUploadSelect.PostedFile.FileName), FileUploadSelect.PostedFile); } obj.File_Sharing_ID = HiddenFieldID.Value; obj.File_Name = Path.GetFileName(FileUploadSelect.PostedFile.FileName); obj.File_Size = FileUploadSelect.PostedFile.ContentLength.ToString(); obj.Upload_Date = DateTime.Now.ToString(); list.Add(obj); ViewState.Add("HashCheckArray", list); FillGridview(list); } } catch (Exception ex) { ButtonAddFile.Enabled = true; txtFilePath.Text = ""; RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("TITLE_ERROR"), ex.Message) + "\");"); } }
/// <summary> /// Upload............ /// </summary> /// <param name="dicPostedFiles"></param> private void StartUpload(Dictionary<string, HttpPostedFile> dicPostedFiles) { string EmailCustomer = ""; string EmailMember = ""; string listName = ""; #region Upload file if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "") { BlobManager blobManager = new BlobManager(); foreach (string fileName in dicPostedFiles.Keys) { HttpPostedFile postedFile = dicPostedFiles[fileName]; long ContentLength = 0; if (postedFile == null) { ContentLength = blobManager.CopyBlob("Temp/" + HiddenFieldAccount.Value + "/" + fileName, LabelCustomerName.Text + "/" + fileName); } else { ContentLength = postedFile.ContentLength; blobManager.UploadFromStream(postedFile.InputStream, LabelCustomerName.Text + "/" + fileName); } listName += fileName + ", "; FileInfoMation obj = new FileInfoMation(); obj.File_Sharing_ID = HiddenFieldID.Value; obj.File_Name = Path.GetFileName(fileName); obj.File_Size = ContentLength.ToString(); obj.Upload_Date = DateTime.Now.ToString(); FileInforMa.File_Insert(obj); } } else { foreach (HttpPostedFile postedFile in dicPostedFiles.Values) { CreateFolder(); string directoryPath = Server.MapPath("~/" + Constant.UPLOAD_STORAGE + "\\" + LabelCustomerName.Text.Trim()); postedFile.SaveAs(directoryPath + "\\" + Path.GetFileName(postedFile.FileName)); listName += Path.GetFileName(postedFile.FileName) + ", "; FileInfoMation obj = new FileInfoMation(); obj.File_Sharing_ID = HiddenFieldID.Value; obj.File_Name = Path.GetFileName(postedFile.FileName); obj.File_Size = postedFile.ContentLength.ToString(); obj.Upload_Date = DateTime.Now.ToString(); FileInforMa.File_Insert(obj); } } #endregion #region SendMail if (!string.IsNullOrEmpty(listName)) { listName = listName.Remove(listName.Length - 2); ///// send mail customer List<CustomerInfo> listCustomer = new List<CustomerInfo>(); listCustomer = CustomerCallControl.File_GetByAll(); listCustomer = listCustomer.Where(c => c.File_Sharing_ID == HiddenFieldID.Value).ToList(); EmailCustomer = listCustomer[0].CustomerEmail; UserMail mailSystemCus = new UserMail(HiddenFieldAccount.Value, HiddenFieldAccount.Value, EmailCustomer); mailSystemCus.AddParams("{FileName}", listName); string mailBody = GetMailBody("Alert_mail_upload.txt"); mailSystemCus.SendEmail(mailSystemCus, Common.GetResourceString("MAIL_UploadSubject"), mailBody); ///// send mail member List<DDMemberInfoCustomer> listMemberAccount = new List<DDMemberInfoCustomer>(); listMemberAccount = DDMemberCallControlCustomer.File_GetByAll(); listMemberAccount = listMemberAccount.Where(c => c.Account == HiddenFieldAccount.Value).ToList(); EmailMember = listMemberAccount[0].Email; UserMail mailSystemMem = new UserMail(HiddenFieldAccount.Value, HiddenFieldAccount.Value, EmailMember); mailSystemMem.AddParams("{FileName}", listName); mailSystemMem.SendEmail(mailSystemMem, Common.GetResourceString("MAIL_UploadSubject"), mailBody); PostedFiles = new Dictionary<string, HttpPostedFile>(); RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("TITLE_SUCESS"), GetResource("MSG_UPLOAD_SUCESS")) + "\");"); } else throw new Exception(GetResource("MSG_AT_LEAST_ONE_CUSTOMER")); #endregion }
protected void getOther(string id) { using (SqlConnection Conn = new SqlConnection(Common.GetConnectString())) { try { Conn.Open(); using (SqlCommand cmd = new SqlCommand("DDV_GetSharing", Conn)) { FileInfoMation obj = new FileInfoMation(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", id); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { LabelCustomerName.Text = dr.GetString(1); lbDate.Text = setDateFormat(dr.GetDateTime(2).ToShortDateString()); } } dr.Close(); } } catch (Exception ex) { throw ex; } finally { Conn.Close(); } } }
protected void getFile(string id) { using (SqlConnection Conn = new SqlConnection(Common.GetConnectString())) { try { Conn.Open(); using (SqlCommand cmd = new SqlCommand("DDV_GetFile", Conn)) { FileInfoMation obj = new FileInfoMation(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", id); fileGrid.DataSource = cmd.ExecuteReader(); fileGrid.DataBind(); } } catch (Exception ex) { throw ex; } finally { Conn.Close(); } } }