Пример #1
0
 protected void Update_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         Data.FilesUpload obj = new Data.FilesUpload();
         obj.Id               = Id;
         obj.ProductId        = ddlProduct.SelectedValue;
         obj.OriginalFileName = ddlProduct.SelectedItem.Text;
         obj.ThumbnailLink    = txtImage.Text;
         obj.Active           = chkActive.Checked ? "1" : "0";
         if (Insert == true)
         {
             obj.Name           = "";
             obj.IconLink       = "";
             obj.WebContentLink = "";
             FilesUploadService.FilesUpload_Insert(obj);
         }
         else
         {
             dt                 = FilesUploadService.FilesUpload_GetByTop("1", "Id='" + Id + "'", "");
             obj.Name           = dt.Rows[0]["Name"].ToString();
             obj.IconLink       = dt.Rows[0]["IconLink"].ToString();
             obj.WebContentLink = dt.Rows[0]["WebContentLink"].ToString();
             FilesUploadService.FilesUpload_Update(obj);
         }
         BindGrid();
         pnView.Visible   = true;
         pnUpdate.Visible = false;
         Insert           = false;
     }
 }
Пример #2
0
 private void BindGrid()
 {
     grdUploadFiles.DataSource = FilesUploadService.FilesUpload_GetByTop("", "", "Name");
     grdUploadFiles.DataBind();
     if (grdUploadFiles.PageCount <= 1)
     {
         grdUploadFiles.PagerStyle.Visible = false;
     }
     else
     {
         grdUploadFiles.PagerStyle.Visible = true;
     }
 }
Пример #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         if (!IsPostBack)
         {
             DataTable dt = FilesUploadService.FilesUpload_GetByTop("", "Active = 1", "Name");
             rptProducts.DataSource = dt;
             rptProducts.DataBind();
         }
     }
     catch (Exception ex)
     {
         MailSender.SendMail("", "", "Error System", ex.Message + "\n" + ex.StackTrace);
     }
 }
Пример #4
0
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            DataGridItem item = default(DataGridItem);

            for (int i = 0; i < grdUploadFiles.Items.Count; i++)
            {
                item = grdUploadFiles.Items[i];
                if (item.ItemType == ListItemType.AlternatingItem | item.ItemType == ListItemType.Item)
                {
                    if (((CheckBox)item.FindControl("ChkSelect")).Checked)
                    {
                        string strId = item.Cells[1].Text;
                        FilesUploadService.FilesUpload_Delete(strId);
                    }
                }
            }
            grdUploadFiles.CurrentPageIndex = 0;
            BindGrid();
        }
Пример #5
0
        protected void grdUploadFiles_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            string strCA = e.CommandArgument.ToString();

            switch (e.CommandName)
            {
            case "Edit":
                Insert = false;
                Id     = strCA;
                dt     = FilesUploadService.FilesUpload_GetByTop("1", "Id='" + Id + "'", "");
                LoadDropDownBoxProduct();
                if (!string.Empty.Equals(dt.Rows[0]["ProductId"].ToString()))
                {
                    ddlProduct.SelectedValue = dt.Rows[0]["ProductId"].ToString();
                }

                txtImage.Text     = dt.Rows[0]["ThumbnailLink"].ToString();
                imgImage.ImageUrl = dt.Rows[0]["ThumbnailLink"].ToString().Length > 0 ? dt.Rows[0]["ThumbnailLink"].ToString() : "";
                chkActive.Checked = dt.Rows[0]["Active"].ToString() == "1" || dt.Rows[0]["Active"].ToString() == "True";
                pnView.Visible    = false;
                pnUpdate.Visible  = true;
                break;

            case "Active":
                string strA = "";
                string str  = e.Item.Cells[2].Text;
                strA = str == "1" ? "0" : "1";
                SqlDataProvider sql = new SqlDataProvider();
                sql.ExecuteNonQuery("Update [FilesUpload] set Active=" + strA + "  Where Id='" + strCA + "'");
                BindGrid();
                break;

            case "Delete":
                FilesUploadService.FilesUpload_Delete(strCA);
                BindGrid();
                break;
            }
        }
Пример #6
0
 protected void btnAddCart_Click(object sender, EventArgs e)
 {
     try
     {
         if (isLogin)
         {
             if (isValidDownload)
             {
                 DataTable file = FilesUploadService.FilesUpload_GetByTop("1", "ProductId='" + id + "'", "");
                 if (file.Rows.Count == 0)
                 {
                     WebMsgBox.Show("File này không còn tồn tại trong hệ thống!");
                     return;
                 }
                 DownloadHistory history = new DownloadHistory();
                 history.UserId         = cus.Id;
                 history.FileId         = file.Rows[0]["Id"].ToString();
                 history.DownloadedDate = DateTime.Now.ToString("MM/dd/yyyy");
                 DownloadHistoryService.DownloadHistory_Insert(history);
                 Response.Redirect(file.Rows[0]["WebContentLink"].ToString(), false);
             }
             else
             {
                 WebMsgBox.Show("Bạn chỉ có thể tải miễn phí 2 lần/ngày");
             }
         }
         else
         {
             Response.Redirect("/thanh-vien/dang-nhap", false);
         }
     }
     catch (Exception ex)
     {
         MailSender.SendMail("", "", "Error System", ex.Message + "\n" + ex.StackTrace);
     }
 }
Пример #7
0
        protected void lbtSynch_Click(object sender, EventArgs e)
        {
            try
            {
                DriveService service   = CreateDriveService();
                string       pageToken = null;
                List <Google.Apis.Drive.v3.Data.File> lstFiles = new List <Google.Apis.Drive.v3.Data.File>();
                do
                {
                    lstFiles.AddRange(ListFiles(service, ref pageToken));
                } while (pageToken != null);
                lstFiles = lstFiles.Distinct().ToList();
                List <Google.Apis.Drive.v3.Data.File> lstNewFiles = new List <Google.Apis.Drive.v3.Data.File>();
                DataTable dtFiles = FilesUploadService.FilesUpload_GetByTop("", "", "");
                for (int i = 0; i < lstFiles.Count; i++)
                {
                    DataRow[] rows = dtFiles.Select("Id='" + lstFiles[i].Id + "'");
                    if (rows == null || rows.Length == 0)
                    {
                        lstNewFiles.Add(lstFiles[i]);
                    }
                }
                if (lstNewFiles.Count == 0)
                {
                    WebMsgBox.Show("Không có file mới để đồng bộ!");
                    return;
                }
                string    json = Newtonsoft.Json.JsonConvert.SerializeObject(lstNewFiles);
                DataTable pDt  = JsonConvert.DeserializeObject <DataTable>(json);
                foreach (var column in pDt.Columns.Cast <DataColumn>().ToArray())
                {
                    if (pDt.AsEnumerable().All(dr => dr.IsNull(column)))
                    {
                        pDt.Columns.Remove(column);
                    }
                }
                pDt.Columns.Add("OriginalFileName", typeof(string));
                if (pDt.Columns["thumbnailLink"] == null)
                {
                    pDt.Columns.Add("thumbnailLink", typeof(string));
                }
                pDt.Columns.Add("Active", typeof(int));
                pDt.Columns.Add("ProductId", typeof(int));
                pDt.Columns["Id"].SetOrdinal(0);
                pDt.Columns["Name"].SetOrdinal(1);
                pDt.Columns["thumbnailLink"].SetOrdinal(2);
                pDt.Columns["IconLink"].SetOrdinal(3);
                pDt.Columns["WebContentLink"].SetOrdinal(4);
                for (int i = 0; i < pDt.Rows.Count; i++)
                {
                    pDt.Rows[i]["Active"] = 1;
                }
                pDt.AcceptChanges();

                BulkInsert(pDt);
                BindGrid();
                WebMsgBox.Show("Đồng bộ dữ liệu thành công!");
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #8
0
        private string UploadFile(string filename)
        {
            try
            {
                // get the exact file name from the path
                String strFile = System.IO.Path.GetFileName(filename);

                // create an instance fo the Local service
                //localhost_UploadFile.FilesUploadService srv = new localhost_UploadFile.FilesUploadService();

                // create an instance fo the web service
                FilesUploadService srv = new FilesUploadService();

                // get the file information form the selected file
                FileInfo fInfo = new FileInfo(filename);

                long   numBytes = fInfo.Length;
                double dLen     = Convert.ToDouble(fInfo.Length / 1024000);

                if (dLen < 10)
                {
                    // set up a file stream and binary reader for the
                    // selected file

                    FileStream   fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
                    BinaryReader br      = new BinaryReader(fStream);

                    // convert the file to a byte array
                    byte[] data = br.ReadBytes((int)numBytes);
                    br.Close();
                    // pass the byte array (file) and file name to the web service
                    dest = cmbFileType.SelectedValue.ToString();

                    string sTmp = srv.UploadFiles(strFile, data, dest, "0000");// Hàm đẩy file lên server
                    for (int i = 0; i < dLen; i++)
                    {
                        processbarUpload.Value = (i / 0.5) * 100;
                    }

                    fStream.Close();
                    fStream.Dispose();
                    srv.Dispose();
                    // this will always say OK unless an error occurs,
                    // if an error occurs, the service returns the error message

                    //MessageBox.Show("File Upload Status: " + sTmp, "File Upload");
                    return(sTmp);
                }
                else
                {
                    // Display message if the file was too large to upload
                    //MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size");
                    return("The file selected exceeds the size limit for uploads.");
                }
            }
            catch (Exception ex)
            {
                // display an error message to the user
                //MessageBox.Show(ex.Message.ToString(), "Upload Error");
                return("Upload Error" + ex.Message.ToString());
            }
        }