private void btnSearch_Click(object sender, EventArgs e) { String cmdText = this.textBoxSql.Text; if (this.cbNoGrid.Checked) { this.richTextBoxInfo.AppendText( string.Format("mysql> {0}", cmdText) + Environment.NewLine); String errMsg = String.Empty; String outputText = String.Empty; DataTable dt = sqlData.SelectAllDataBySqlText(cmdText, ref errMsg); if (dt == null) { outputText = errMsg + Environment.NewLine; UpdateRichTextBox(outputText); } else { UpdateRichTextBox(CommonDataTable.ConvertFilmInfoToGrid(dt)); } } else { SqlQueryAction?.Invoke(cmdText); } this.richTextBoxInfo.Focus(); }
public override DataTable GetSearchLogDatabaseTransferData() { String cmdText = String.Format("select * from {0} order by id;", "search_log"); DataTable dt = CommonDataTable.GetSearchLogDataTable(); using (SQLiteConnection sqlCon = new SQLiteConnection(SQLOpenCmdText)) { sqlCon.Open(); using (SQLiteCommand sqlCmd = new SQLiteCommand(cmdText, sqlCon)) { using (SQLiteDataReader sqlDataReader = sqlCmd.ExecuteReader()) { while (sqlDataReader.Read()) { DataRow dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { dr[i] = sqlDataReader[i]; } dt.Rows.Add(dr); } } } sqlCon.Close(); } for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i][0] = i + 1; } return(dt); }
public void UpdateRichTextBox(DataTable dt) { this.richTextBoxInfo.AppendText( CommonDataTable.DataTableFormatToString(dt, this.outputSet) + Environment.NewLine); richTextBoxInfo.SelectionStart = richTextBoxInfo.Text.Length; richTextBoxInfo.SelectionLength = 0; }
private DataTable ConvertDiskInfoToGrid(DataTable diDt) { DataTable dt = CommonDataTable.GetSettingGridDataTable(); for (int i = 0; i < diDt.Rows.Count; i++) { DataRow dr = dt.NewRow(); dr[0] = i + 1; dr[1] = diDt.Rows[i][1]; dr[2] = Helper.GetSizeString(Convert.ToInt64(diDt.Rows[i][2])); dr[3] = Helper.GetSizeString(Convert.ToInt64(diDt.Rows[i][3])); Boolean completeScan = Convert.ToBoolean(diDt.Rows[i][4]); dr[4] = completeScan ? "✔" : "✘"; dr[5] = diDt.Rows[i][5]; dt.Rows.Add(dr); } return(dt); }
public void ScanDisk() { progressSetView?.Invoke(0, diskPath); diskScanNum = CountDisk(); actualMaxScanLayer = 0; bCompleteScan = true; int maxId = sqlData.GetMaxIdOfFilmInfo(); int startId = maxId + 1; startIdGlobal = startId; diskScanIndex = 1; DriveInfo driveInfo = new DriveInfo(diskPath); DataTable dt = CommonDataTable.GetFilmInfoDataTable(); DataRow dr = dt.NewRow(); dr["id"] = startIdGlobal++; dr["name"] = driveInfo.RootDirectory.Name; dr["path"] = driveInfo.RootDirectory.FullName; dr["size"] = -1; dr["create_t"] = driveInfo.RootDirectory.CreationTime; dr["modify_t"] = driveInfo.RootDirectory.LastWriteTime; dr["is_folder"] = true; dr["to_watch"] = false; dr["to_watch_ex"] = false; dr["s_w_t"] = System.Data.SqlTypes.SqlDateTime.MinValue.Value; dr["to_delete"] = false; dr["to_delete_ex"] = false; dr["s_d_t"] = System.Data.SqlTypes.SqlDateTime.MinValue.Value; dr["content"] = String.Empty; dr["pid"] = -1; dr["disk_desc"] = diskDescribe; dt.Rows.Add(dr); Dictionary <String, int> maxCidDic = new Dictionary <String, int>(); maxCidDic.Add(driveInfo.RootDirectory.FullName, startIdGlobal - 1); ScanAllInFolder(driveInfo.RootDirectory, startIdGlobal - 1, setMaxScanLayer, ref dt, ref maxCidDic); progressSetView?.Invoke(96, "写入数据库"); Dictionary <int, long> sizeDic = new Dictionary <int, long>(); for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToBoolean(dt.Rows[i]["is_folder"])) { int maxCid = maxCidDic[dt.Rows[i]["path"].ToString()]; dt.Rows[i]["max_cid"] = maxCid; if (bCompleteScan) { sizeDic.Add(i, 0); for (int j = i + 1; j + startId <= maxCid; j++) { if (!Convert.ToBoolean(dt.Rows[j]["is_folder"])) { sizeDic[i] += Helper.CalcSpace(Convert.ToInt64(dt.Rows[j]["size"])); } } } } else { dt.Rows[i]["max_cid"] = dt.Rows[i]["id"]; } } // 简略扫描不计算文件夹大小 if (bCompleteScan) { foreach (KeyValuePair <int, long> kv in sizeDic) { dt.Rows[kv.Key]["size"] = kv.Value; } } sqlData.InsertDataToFilmInfo(dt); // 更新磁盘信息 sqlData.InsertOrUpdateDataToDiskInfo( diskDescribe, driveInfo.TotalFreeSpace, driveInfo.TotalSize, bCompleteScan, bCompleteScan ? actualMaxScanLayer : setMaxScanLayer); progressSetView?.Invoke(100, "完成"); threadCallback?.Invoke(bCompleteScan); progressFinish?.Invoke(); }
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); }
public override DataTable GetFilmInfoDatabaseTransferData() { String cmdText = String.Format("select * from {0} where disk_desc!=@disk_desc order by id;", "film_info"); DataTable dt = CommonDataTable.GetFilmInfoDataTable(); List <int> continuedMinList = new List <int>(); List <int> continuedMaxList = new List <int>(); List <int> subtractList = new List <int>(); int continuedMin = -1, continuedMax = -1, subtract = -1, id = -1, preID = -1; using (SQLiteConnection sqlCon = new SQLiteConnection(SQLOpenCmdText)) { sqlCon.Open(); using (SQLiteCommand sqlCmd = new SQLiteCommand(cmdText, sqlCon)) { sqlCmd.Parameters.AddWithValue("@disk_desc", CommonString.RealOrFake4KDiskName); using (SQLiteDataReader sqlDataReader = sqlCmd.ExecuteReader()) { while (sqlDataReader.Read()) { DataRow dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { dr[i] = sqlDataReader[i]; } dt.Rows.Add(dr); preID = id; id = Convert.ToInt32(dr["id"]); if (continuedMin == -1) { continuedMin = preID; } if (preID != -1 && id - preID > 1) { continuedMax = preID; if (continuedMinList.Count == 0) { subtract = continuedMin - 1; } else { subtract = subtractList[subtractList.Count - 1] + continuedMin - continuedMaxList[continuedMaxList.Count - 1] - 1; } continuedMinList.Add(continuedMin); continuedMaxList.Add(continuedMax); subtractList.Add(subtract); continuedMin = -1; } } continuedMax = id; if (continuedMinList.Count == 0) { subtract = continuedMin - 1; } else { subtract = subtractList[subtractList.Count - 1] + continuedMin - continuedMaxList[continuedMaxList.Count - 1] - 1; } continuedMinList.Add(continuedMin); continuedMaxList.Add(continuedMax); subtractList.Add(subtract); } } sqlCon.Close(); } int[] cols = new int[3] { 0, 14, 15 }; int startIndex = 0; for (int i = 0; i < dt.Rows.Count; i++) { id = Convert.ToInt32(dt.Rows[i][0]); for (int j = startIndex; j < continuedMaxList.Count; j++) { if (id <= continuedMaxList[j]) { startIndex = j; break; } } foreach (int col in cols) { int num = Convert.ToInt32(dt.Rows[i][col]); if (num != -1) { dt.Rows[i][col] = num - subtractList[startIndex]; } } } return(dt); }
/// <summary> /// -1 从网页抓取数据失败,0 从网页抓取数据条数和数据库相同只更新时间 /// 返回抓取数据条数 /// </summary> /// <param name="strMsg">输出信息,用于显示</param> /// <param name="crawlTime">抓取时间</param> /// <returns></returns> public void Update4KInfo() { RealOrFake4KWebDataCaptureResult rst = new RealOrFake4KWebDataCaptureResult(); rst.crawlTime = DateTime.Now; string errMsg = ""; DataTable crawlDt = CrawlData(ref errMsg, this.crawlURL); if (crawlDt == null || crawlDt.Rows.Count == 0) { rst.strMsg = string.Format("从网页\n{0}\n抓取数据失败\n{1}", this.crawlURL, errMsg); rst.code = -1; this.threadWebDataCaptureCallback?.Invoke(rst); this.threadWebDataCaptureFinish?.Invoke(); return; } int diskCount = sqlData.CountRowsOfDiskFromFilmInfo( CommonString.RealOrFake4KDiskName); if ((diskCount - 1) >= crawlDt.Rows.Count) { // 更新时间 int affectedCount = sqlData.UpdateDiskRealOrFake4KInModifyTimeFromDiskInfo( rst.crawlTime); Debug.Assert(diskCount == affectedCount); rst.strMsg = string.Format( "从网页\n{0}\n抓取数据条数 {1} 小于或等于数据库已存在条数 {2}\n不更新数据库信息", this.crawlURL, crawlDt.Rows.Count, diskCount - 1); rst.code = 0; this.threadWebDataCaptureCallback?.Invoke(rst); this.threadWebDataCaptureFinish?.Invoke(); return; } sqlData.DeleteByDiskDescribeFromFilmInfo(CommonString.RealOrFake4KDiskName); int maxId = sqlData.GetMaxIdOfFilmInfo(); int startId = maxId + 1; int diskId = startId; DataTable dt = CommonDataTable.GetFilmInfoDataTable(); DataRow drDisk = dt.NewRow(); drDisk["id"] = startId++; drDisk["name"] = CommonString.RealOrFake4KDiskName; drDisk["path"] = "------"; drDisk["size"] = -1; drDisk["create_t"] = rst.crawlTime; drDisk["modify_t"] = rst.crawlTime; drDisk["is_folder"] = true; drDisk["to_watch"] = false; drDisk["to_watch_ex"] = false; drDisk["s_w_t"] = System.Data.SqlTypes.SqlDateTime.MinValue.Value; drDisk["to_delete"] = false; drDisk["to_delete_ex"] = false; drDisk["s_d_t"] = System.Data.SqlTypes.SqlDateTime.MinValue.Value; drDisk["content"] = String.Empty; drDisk["pid"] = -1; drDisk["max_cid"] = startId - 1 + crawlDt.Rows.Count; drDisk["disk_desc"] = CommonString.RealOrFake4KDiskName; dt.Rows.Add(drDisk); foreach (DataRow crawlDr in crawlDt.Rows) { DataRow dr = dt.NewRow(); dr["id"] = startId++; dr["name"] = string.Join(" | ", crawlDr.ItemArray.Cast <string>(). Where(x => !string.IsNullOrWhiteSpace(x))); dr["path"] = "------"; dr["size"] = -1; dr["create_t"] = rst.crawlTime; dr["modify_t"] = rst.crawlTime; dr["is_folder"] = false; dr["to_watch"] = false; dr["to_watch_ex"] = false; dr["s_w_t"] = System.Data.SqlTypes.SqlDateTime.MinValue.Value; dr["to_delete"] = false; dr["to_delete_ex"] = false; dr["s_d_t"] = System.Data.SqlTypes.SqlDateTime.MinValue.Value; dr["content"] = String.Empty; dr["pid"] = diskId; dr["max_cid"] = startId - 1; dr["disk_desc"] = CommonString.RealOrFake4KDiskName; dt.Rows.Add(dr); } sqlData.InsertDataToFilmInfo(dt); rst.strMsg = string.Format("从网页\n{0}\n抓取数据 {1} 条,已写入数据库", this.crawlURL, crawlDt.Rows.Count); rst.code = crawlDt.Rows.Count; this.threadWebDataCaptureCallback?.Invoke(rst); this.threadWebDataCaptureFinish?.Invoke(); }
private void SqlForm_Load(object sender, EventArgs e) { this.Text = CommonString.MainFormTitle; this.Icon = Properties.Resources.Film; this.cbindex.Checked = true; this.cbid.Checked = false; this.cbname.Checked = true; this.cbpath.Checked = true; this.cbsize.Checked = true; this.cbcreate_t.Checked = true; this.cbto_delete.Checked = true; this.cbto_delete_ex.Checked = true; this.cbs_w_t.Checked = true; this.cbto_watch.Checked = true; this.cbto_watch_ex.Checked = true; this.cbis_folder.Checked = true; this.cbmodify_t.Checked = true; this.cbdisk_desc.Checked = true; this.cbmax_cid.Checked = false; this.cbpid.Checked = false; this.cbcontent.Checked = false; this.cbs_d_t.Checked = true; cbs = new CheckBox[] { this.cbindex, this.cbid, this.cbname, this.cbpath, this.cbsize, this.cbcreate_t, this.cbto_delete, this.cbto_delete_ex, this.cbs_w_t, this.cbto_watch, this.cbto_watch_ex, this.cbis_folder, this.cbmodify_t, this.cbdisk_desc, this.cbmax_cid, this.cbpid, this.cbcontent, this.cbs_d_t, }; this.outputSet = new HashSet <string>(); foreach (CheckBox cb in cbs) { if (cb.Checked) { this.outputSet.Add(cb.Text); } cb.CheckedChanged += this.output_CheckedChanged; } this.cbOutputCtl.Checked = true; this.cbOutputCtl.CheckedChanged += this.outputCtl_CheckedChanged; this.richTextBoxInfo.Text = "mysql> desc film_info" + Environment.NewLine; String descFilmInfo = CommonDataTable.DataTableFormatToString( sqlData.GetDescriptionOfFilmInfo(), null); UpdateRichTextBox(descFilmInfo); }