Example #1
0
        private bool OnGetSetResponse(HttpRequest request, HttpResponse response)
        {
            RequestURLInfo = new RequestURL(request.RawURL);
            if (!RequestURLInfo.IsValid)
            {
                return(false);
            }

            if (RequestURLInfo.RequestType == RequestURL.RequestTypeEnum.FILE)
            {
                string requestURL = request.URL.TrimStart(new char[] { '/' });
                Match  match      = iconRegex.Match(requestURL);
                if (match.Success && (!string.IsNullOrWhiteSpace(match.Groups[1].Value)))
                {
                    string strTemp   = string.Format("*.{0}", match.Groups[1].Value);
                    byte[] iconBytes = null;
                    if (ImageBytesDic.ContainsKey(strTemp))
                    {
                        iconBytes = ImageBytesDic[strTemp];
                    }
                    else
                    {
                        try
                        {
                            iconBytes = Helper.IconToBytes(IconReader.GetFileIcon(
                                                               strTemp, IconReader.IconSize.Small, false));
                            response.Content_Type = ContentTypeDic[".ico"];
                        }
                        catch
                        {
                            iconBytes             = ExistResourcesBytesDic["warn.png"];
                            response.Content_Type = ContentTypeDic[".png"];
                        }
                        ImageBytesDic.Add(strTemp, iconBytes);
                    }

                    response.SetContent(iconBytes);
                }
                else if (ExistResourcesBytesDic.ContainsKey(requestURL))
                {
                    response.SetContent(ExistResourcesBytesDic[requestURL]);
                    response.Content_Type = ContentTypeDic[Path.GetExtension(requestURL)];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                TotalItemCount = 0;
                PageCount      = 0;
                PageIndex      = -1;
                ItemIndex      = -1;

                UpFolderId        = -2;
                CurrentFolderId   = -2;
                CurrentFolderPath = "";

                if (RequestURLInfo.Offset >= 0)
                {
                    PageIndex = RequestURLInfo.Offset / PageItemCount;
                    ItemIndex = RequestURLInfo.Offset % PageItemCount;
                }

                string    strTitle          = RequestURLInfo.SearchKeyWord;
                int[]     idList            = null;
                DataTable dt                = null;
                DataTable diskRootDataTable = sqlData.DiskRootDataTable;

                SelectAllDisk = string.Format("全部(共 {0} 磁盘)",
                                              diskRootDataTable.Rows.Count);
                DiskDescList.Clear();
                DiskDescList.Add(SelectAllDisk);
                foreach (DataRow dr in diskRootDataTable.Rows)
                {
                    DiskDescList.Add(dr["disk_desc"].ToString());
                }

                if (RequestURLInfo.DiskDescribe != "")
                {
                    if (!DiskDescList.Contains(RequestURLInfo.DiskDescribe))
                    {
                        return(false);
                    }
                }
                else
                {
                    RequestURLInfo.DiskDescribe = SelectAllDisk;
                }

                switch (RequestURLInfo.QueryType)
                {
                case RequestURL.QueryTypeEnum.DISK_ROOT:
                {
                    TotalItemCount = diskRootDataTable.Rows.Count;
                    strTitle       = string.Format("INDEX[{0}]", TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.DATABASE_ID:
                {
                    dt = sqlData.GetDataByIdFromFilmInfo(RequestURLInfo.DataBaseId);
                    if (dt != null && dt.Rows.Count == 1)
                    {
                        TotalItemCount = 1;
                        strTitle       = string.Format("ID[{0}][{1}]", RequestURLInfo.DataBaseId, TotalItemCount);

                        CurrentFolderId = Convert.ToInt32(dt.Rows[0]["pid"]);
                        if (CurrentFolderId >= 0)
                        {
                            DataTable folderDt = sqlData.GetDataByIdFromFilmInfo(CurrentFolderId);
                            if (folderDt != null && folderDt.Rows.Count == 1)
                            {
                                UpFolderId        = Convert.ToInt32(folderDt.Rows[0]["pid"]);
                                CurrentFolderPath = folderDt.Rows[0]["path"].ToString();
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                break;

                case RequestURL.QueryTypeEnum.DATABASE_PID:
                {
                    CurrentFolderId = RequestURLInfo.DataBasePid;
                    if (CurrentFolderId >= 0)
                    {
                        dt = sqlData.GetDataByIdFromFilmInfo(CurrentFolderId);
                        if (dt != null && dt.Rows.Count == 1)
                        {
                            UpFolderId        = Convert.ToInt32(dt.Rows[0]["pid"]);
                            CurrentFolderPath = dt.Rows[0]["path"].ToString();
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    idList = sqlData.GetDataByPidFromFilmInfo(RequestURLInfo.DataBasePid);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    strTitle = string.Format("PID[{0}][{1}]", RequestURLInfo.DataBasePid, TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.SEARCH:
                {
                    idList = sqlData.SearchKeyWordFromFilmInfo(
                        RequestURLInfo.SearchKeyWord,
                        RequestURLInfo.DiskDescribe == SelectAllDisk ? null : RequestURLInfo.DiskDescribe);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    sqlData.InsertDataToSearchLog(
                        RequestURLInfo.SearchKeyWord, TotalItemCount, DateTime.Now);

                    strTitle = string.Format("SEARCH[{0}][1]", RequestURLInfo.SearchKeyWord, TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.TO_DELETE_BY_TIME:
                {
                    idList = sqlData.GetDeleteDataFromFilmInfo(
                        RequestURLInfo.DiskDescribe == SelectAllDisk ? null : RequestURLInfo.DiskDescribe);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    strTitle = string.Format("TO_DELETE_TIME[{0}][1]", RequestURLInfo.SearchKeyWord, TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.TO_DELETE_BY_DISK:
                {
                    idList = sqlData.GetDeleteDataFromFilmInfoGroupByDisk(
                        RequestURLInfo.DiskDescribe == SelectAllDisk ? null : RequestURLInfo.DiskDescribe);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    strTitle = string.Format("TO_DELETE_DISK[{0}][1]", RequestURLInfo.SearchKeyWord, TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.TO_WATCH:
                {
                    idList = sqlData.GetWatchDataFromFilmInfo(
                        RequestURLInfo.DiskDescribe == SelectAllDisk ? null : RequestURLInfo.DiskDescribe);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    strTitle = string.Format("TO_WATCH[{0}][1]", RequestURLInfo.SearchKeyWord, TotalItemCount);
                }
                break;

                default:
                    return(false);
                }

                if (RequestURLInfo.Offset == 0 && TotalItemCount == 0)
                {
                    gridData = diskRootDataTable.Clone();
                }
                else if (RequestURLInfo.Offset >= 0 && RequestURLInfo.Offset < TotalItemCount)
                {
                    switch (RequestURLInfo.QueryType)
                    {
                    case RequestURL.QueryTypeEnum.DISK_ROOT:
                        gridData = diskRootDataTable
                                   .AsEnumerable()
                                   .Where((row, index) => index >= PageIndex * PageItemCount && index < (PageIndex + 1) * PageItemCount)
                                   .CopyToDataTable();
                        break;

                    case RequestURL.QueryTypeEnum.DATABASE_ID:
                        gridData = CommonDataTable.ConvertFilmInfoToGrid(dt);
                        break;

                    case RequestURL.QueryTypeEnum.DATABASE_PID:
                    case RequestURL.QueryTypeEnum.SEARCH:
                    case RequestURL.QueryTypeEnum.TO_DELETE_BY_TIME:
                    case RequestURL.QueryTypeEnum.TO_DELETE_BY_DISK:
                    case RequestURL.QueryTypeEnum.TO_WATCH:
                        dt = sqlData.SelectDataByIDList(
                            Helper.ArraySlice(idList, PageIndex * PageItemCount, PageItemCount));
                        gridData = CommonDataTable.ConvertFilmInfoToGrid(dt);
                        break;

                    default:
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                PageCount = TotalItemCount / PageItemCount +
                            (TotalItemCount % PageItemCount == 0 ? 0 : 1);

                string strResponse = Properties.Resources.main_html.Replace("${title}",
                                                                            string.Format("{0} - {1}", strTitle, TitleSuffix));
                strResponse = strResponse.Replace("${title_app}", TitleSuffix);
                strResponse = strResponse.Replace("${select_items}", GetSelectBoxHtmlString());
                strResponse = strResponse.Replace("${search_keyword}", RequestURLInfo.SearchKeyWord);
                strResponse = strResponse.Replace("${table_content}", GetTableHtmlString());
                strResponse = strResponse.Replace("${cut_page_index}", GetCutPageHtmlString());

                response.SetContent(strResponse);
                response.Content_Type = ContentTypeDic[".html"];
            }

            response.StatusCode = "200";
            return(true);
        }
Example #2
0
        private void btnMoveFolderOrFile_Click(object sender, EventArgs e)
        {
            if (this.dataGridView.SelectedRows.Count != 1)
            {
                MessageBox.Show("请选中一行!", "提示", MessageBoxButtons.OK);
                return;
            }

            FolderBrowserDialog dlg = new FolderBrowserDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (!dlg.SelectedPath.EndsWith(":\\"))
                {
                    MessageBox.Show("请选择磁盘根目录!", "提示", MessageBoxButtons.OK);
                    return;
                }

                String log         = String.Empty;
                String logSuccess  = String.Empty;
                int    moveSuccess = 0;
                String logFailed   = String.Empty;
                int    moveFailed  = 0;

                String diskDescribe = this.dataGridView.SelectedRows[0].Cells[1].Value.ToString();
                String localDisk    = dlg.SelectedPath;
                String moveToFolder = Path.Combine(localDisk, "ToDelete");

                if (MessageBox.Show(
                        string.Format("确定要将磁盘 \'{0}\',实际磁盘 \'{1}\' 中的待删项移到 \'{2}\' 吗?",
                                      diskDescribe, localDisk, moveToFolder), "提示",
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Question) ==
                    DialogResult.Cancel)
                {
                    return;
                }

                //int deleteNumber = sqlData.CountDeleteDataFromFilmInfo(diskDescribe);
                //DataTable dt = sqlData.GetDeleteDataFromFilmInfo(0, deleteNumber, diskDescribe);

                int[]     idList = sqlData.GetDeleteDataFromFilmInfo(diskDescribe);
                DataTable dt     = sqlData.SelectDataByIDList(idList);
                Debug.Assert(idList.Length == dt.Rows.Count);

                if (!Directory.Exists(moveToFolder))
                {
                    Directory.CreateDirectory(moveToFolder);
                }

                log += String.Format("查询到待删记录 {0} 条\r\n", dt.Rows.Count);
                log += String.Format("目标文件夹 {0}\r\n", moveToFolder);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    String  name     = dt.Rows[i]["name"].ToString();
                    String  path     = dt.Rows[i]["path"].ToString();
                    Boolean isFolder = Convert.ToBoolean(dt.Rows[i]["is_folder"]);

                    String moveToPath = Path.Combine(moveToFolder, name);
                    // 更改磁盘名称(扫描时的磁盘和此时的磁盘名称可能不同)
                    String moveFromPath = localDisk[0] + path.Substring(1);

                    if (isFolder)
                    {
                        if (Directory.Exists(moveFromPath))
                        {
                            Directory.Move(moveFromPath, moveToPath);
                            moveSuccess++;
                            logSuccess += String.Format("{0} ---> {1}\r\n", moveFromPath, moveToPath);
                        }
                        else
                        {
                            moveFailed++;
                            logFailed += String.Format("{0}\r\n", moveFromPath);
                        }
                    }
                    else
                    {
                        if (File.Exists(moveFromPath))
                        {
                            File.Move(moveFromPath, moveToPath);
                            moveSuccess++;
                            logSuccess += String.Format("{0} ---> {1}\r\n", moveFromPath, moveToPath);
                        }
                        else
                        {
                            moveFailed++;
                            logFailed += String.Format("{0}\r\n", moveFromPath);
                        }
                    }
                }

                log += String.Format("\r\n成功 {0} 项:\r\n{1}\r\n失败 {2} 项:\r\n{3}",
                                     moveSuccess, logSuccess, moveFailed, logFailed);

                String filePath = Path.Combine(CommonString.MyFilmApplicationDataFolder, "MyfilmTemp.txt");
                File.WriteAllText(filePath, log, System.Text.Encoding.UTF8);

                Helper.OpenEdit(filePath, log);
            }
        }