public static void LoadHighlightinngs(this System.Windows.Forms.RichTextBox codeEditSpace) { void Select(System.Windows.Forms.RichTextBox codeEdit, int start, int length, Color color) { codeEdit.Select(start, length); codeEdit.SelectionColor = color; } codeEditSpace.Enabled = false; int selectionStart = codeEditSpace.SelectionStart; var higlights = SyntaxHighlighter.SyntaxHighlighter.Parse(codeEditSpace.Text); foreach (var higlight in higlights) { Select(codeEditSpace, higlight.StartPosition, higlight.EndPosition - higlight.StartPosition, higlight.Color); } /* * if (codeEditSpace.Lines.Length == 0) * { * var higlights = SyntaxHighlighter.SyntaxHighlighter.Parse(codeEditSpace.Text); * foreach (var higlight in higlights) * { * Select(codeEditSpace, higlight.StartPosition, * higlight.EndPosition - higlight.StartPosition, * higlight.Color); * } * } * else * { * //using (var writer = new StreamWriter("log.txt")) * // { * for (int i = 0; i < codeEditSpace.Lines.Length; i++) * { * var higlights = SyntaxHighlighter.SyntaxHighlighter.Parse(codeEditSpace.Lines[i]); * foreach (var higlight in higlights) * { * * //writer.WriteLine( * //$"{higlight.Key} - {higlight.Color.A}; {higlight.Color.R}; {higlight.Color.B}; {higlight.Color.G}"); * * var startPos = codeEditSpace.GetFirstCharIndexFromLine(i); * Select(codeEditSpace, startPos + higlight.StartPosition, * higlight.EndPosition - higlight.StartPosition, higlight.Color); * } * } * //} */ codeEditSpace.Select(selectionStart, 0); //} codeEditSpace.Enabled = true; codeEditSpace.Focus(); }
public static void Insert(this System.Windows.Forms.RichTextBox richTextBox, string text) { int startIndex = richTextBox.SelectionStart; string selectedText = richTextBox.SelectedText; if (selectedText.Length > 0) { richTextBox.Text = richTextBox.Text.Remove(startIndex, selectedText.Length); } richTextBox.Text = richTextBox.Text.Insert(startIndex, text); richTextBox.Select(startIndex, text.Length); richTextBox.Focus(); }
public static void SelectLine(this System.Windows.Forms.RichTextBox source, int line, int length = 0) { string[] objTextboxLines = source.Lines; if (line < 1 || source.Lines.Length < line) { return; } if (length != 0) { source.Select(source.GetFirstCharIndexFromLine(line - 1), length); } else { source.Select(source.GetFirstCharIndexFromLine(line - 1), objTextboxLines[line].Length - 1); } source.ScrollToCaret(); source.Focus(); }
/// <summary> /// メッセージにフォーカスをセット /// </summary> public void Focus() { txtMsg.Focus(); }
//导入到宣三系统 /// <summary> /// 根据算法按照分配百分比,导入相对应数据 /// </summary> /// <param name="gettotal"></param> /// <param name="sw"></param> /// <param name="rich"></param> public void daoruxuansan(GetTotaldaoruxuansan gettotal, GetMday getmtotal, System.Diagnostics.Stopwatch sw, System.Windows.Forms.RichTextBox rich) { wznr_Servise service = new wznr_Servise(); servicemodel.service model = new servicemodel.service(); serviceBLL bll = new serviceBLL(); StringBuilder sb = new StringBuilder(); string sql = ""; string sqlfenye = ""; double[] numbers = new double[5] { 0.31, 0.27, 0.08, 0.21, 0.13 }; int totalRecords = 0; int total = 0; string name = ""; int temp = 0;//循环第一次的值 //for 两个循环,第一循环控制年份,第二循环控制月份, sw.Start(); for (int y = 2010; y < 2013; y++) { for (int m = 1; m < 13; m++) { int temp1 = 0; //计数器 double num = 0; //获取人员分配条数 sql = "select * from KFLR where datepart(mm,pubtime)=" + m + " and DATEPART(yy,pubtime)=" + y; ////获取每月数据 int count = service.GetRecordCount("select count(*) from KFLR where datepart(mm,pubtime)=" + m + " and DATEPART(yy,pubtime)=" + y); //按照比例分配 count*numbers[i],按照每个部门分配比例循环获按月份取条数 Form2WaittingGetTotalRecords form = new Form2WaittingGetTotalRecords(); form.Show(); form.Text = string.Format("{2}年-{0}月数据:{1}条", m.ToString(), count.ToString(), y.ToString()); totalRecords = GetTotalMXS(form.GetTotalNum, sql);//fBatchInsert.GetTotalXS(form.GetTotalNum); for (int t = 0; t < numbers.Length; t++) { switch (numbers[t].ToString()) { case "0.31": name = "杨敏月"; break; case "0.27": name = "刘洪那"; break; case "0.08": name = "朱欢"; break; case "0.21": name = "门诊"; //默认刘雪梅部门 break; case "0.13": name = "马健"; break; default: break; } num = Convert.ToInt32(Math.Round((totalRecords * numbers[t]), 0)); //Round((totalRecords * numbers[t]), 0); temp = Convert.ToInt32(Math.Round((totalRecords * numbers[0]), 0)); //记录第一次值 //select top 10 * from KFLR where ID not in(select top (10*(2-1)) ID from KFLR where DATEPART(MM,PubTime)=5 and DATEPART(YY,PubTime)=2010) and datepart(mm,pubtime)=5 and DATEPART(yy,pubtime)=2010 sqlfenye = "select top " + num + " * from KFLR where ID not in(select top " + temp1 + " ID from KFLR where DATEPART(MM,PubTime)=" + m + " and DATEPART(YY,PubTime)=" + y + ") and datepart(mm,pubtime)=" + m + " and DATEPART(yy,pubtime)=" + y + ""; temp1 = temp1 + Convert.ToInt32(num);//每次循环出来的值+上一次num的值 //DataTable dt = service.GetDataTable2("select top " + num + " * from KFLR where datepart(mm,pubtime)=" + m + " and DATEPART(yy,pubtime)=" + y); DataTable dt = service.GetDataTable2(sqlfenye); for (int i = 0; i < dt.Rows.Count; i++) { model.username = Convert.ToString(dt.Rows[i]["username"]); //患者名称 model.userage = Convert.ToString(dt.Rows[i]["age"]); //患者年龄 model.usersex = "不详"; //患者性别 model.userphoto = Convert.ToString(dt.Rows[i]["tel"]); //患者电话 model.useraddress = Convert.ToString(dt.Rows[i]["address"]); //患者地址 model.subtime = Convert.ToDateTime(dt.Rows[i]["pubtime"]); //提交时间 model.zhengzhuang = Convert.ToString(dt.Rows[i]["bingzhong"]); //病情症状 model.chats = Convert.ToString(dt.Rows[i]["ltrecord"]); //内容 model.eatime = dt.Rows[i]["teltime"] == DBNull.Value ? Convert.ToDateTime(dt.Rows[i]["pubtime"]) : Convert.ToDateTime(dt.Rows[i]["teltime"]); //通话日期 model.telextract = null; model.eaname = Convert.ToString(dt.Rows[i]["zbusername"]); //值班人 model.userweb = Convert.ToString(dt.Rows[i]["webaddress"]); //所属网站 model.theirpeople = Convert.ToString(dt.Rows[i]["pubusername"]); //录入人员 model.flag = 0; model.memo = Convert.ToString(dt.Rows[i]["beizhu"]).Trim(); //备注 model.bj = "0"; model.sfzy = "1"; model.typeflag = "1"; model.hfdata = dt.Rows[i]["retime"] == DBNull.Value ? Convert.ToDateTime(dt.Rows[i]["pubtime"]) : Convert.ToDateTime(dt.Rows[i]["retime"]); //回复日期 model.sfyx = "0"; //是否有效 model.zzy = "所属资源是:" + Convert.ToString(dt.Rows[i]["zbusername"]); //所属资源 model.sfdh = "1"; model.deleflag = "0"; model.zhenduan = Convert.ToString(dt.Rows[i]["bingzhong"]);//病种 model.stas = "0"; model.zzystas = "0"; model.lasttime = dt.Rows[i]["teltime"] == DBNull.Value ? Convert.ToDateTime(dt.Rows[i]["pubtime"]) : Convert.ToDateTime(dt.Rows[i]["teltime"]); model.flagbumen = name + "部门"; model.xcbumen = "宣传四"; model.kfbumen = "宣传四"; model.bianyuan = "0"; model.urltext = null; model.bqname = null; model.byname = Convert.ToString(dt.Rows[i]["username"]); model.byphone = Convert.ToString(dt.Rows[i]["tel2"]); model.zydate = Convert.ToDateTime(dt.Rows[i]["pubtime"]); model.strurl = "没有网址"; model.hotflag = ""; model.menzhenname = Convert.ToString(dt.Rows[i]["username2"]); model.menzhenphone = Convert.ToString(dt.Rows[i]["tel2"]); model.kefuname = Convert.ToString(dt.Rows[i]["username"]); model.kefuphone = Convert.ToString(dt.Rows[i]["tel"]); model.memo2 = Convert.ToString(dt.Rows[i]["juage3"]); model.flag2 = "0"; model.jdflag = "0"; model.xcname = null; model.baobei = Convert.ToDateTime("1987-06-19 00:00:00.000"); bll.Add(model); total++; gettotal(total); } //rich.AppendText(string.Format("{2}年-{0}月数据:{1}条", m.ToString(), count.ToString(), y.ToString()) + "分配给" + name + "" + num + "条分配语句:\n" + sqlfenye+ temp1 + "\n"); rich.AppendText(string.Format("{2}年-{0}月数据:{1}条", m.ToString(), count.ToString(), y.ToString()) + "分配给" + name + "" + num + "\n"); rich.ForeColor = System.Drawing.Color.Green;//设置字体颜色 rich.Focus(); } form.Close(); } } // 停止计时 sw.Stop(); }
//导出数据db3 public void OutPut(GetTotalDelegateOutPut gettotaldelegateoutput, System.Diagnostics.Stopwatch sw, System.Windows.Forms.RichTextBox rich) { wznr_Servise wznr = new wznr_Servise(); int totalRecords = 0; string dbn = "SpiderResult.db3";//数据库文件名称 // 创建数据库文件 File.Delete(dbn); SQLiteConnection.CreateFile(dbn); DbProviderFactory factory = SQLiteFactory.Instance; using (DbConnection conn = factory.CreateConnection()) { // 连接数据库 conn.ConnectionString = "Data Source=" + dbn + ""; conn.Open(); // 创建数据表 string sql = "CREATE TABLE Content([ID] integer primary key autoincrement,[已采] tinyint(1) default 0,[已发] tinyint(1) default 0,[标题] Text,[内容] Text,[PageUrl] Text)"; DbCommand cmd = conn.CreateCommand(); cmd.Connection = conn; cmd.CommandText = sql; cmd.ExecuteNonQuery(); sw.Start(); DbTransaction trans = conn.BeginTransaction(); // <------------------- try { // 查询出数据导出 通过数据库查询出 DataTable dt = wznr.GetDataTable("SELECT Title, p FROM test5Table"); for (int i = 0; i < dt.Rows.Count; i++) { totalRecords++; gettotaldelegateoutput(totalRecords); cmd.CommandText = "insert into [Content] ([已采],[已发],[标题],[内容],[PageUrl]) values (?,?,?,?,?)"; SQLiteParameter[] parameter = { new SQLiteParameter("@[已采]", DbType.Byte, 1), new SQLiteParameter("@[已发]", DbType.Byte, 1), new SQLiteParameter("@[标题]", DbType.Object), new SQLiteParameter("@[内容]", DbType.Object), new SQLiteParameter("@[PageUrl]", DbType.Object) }; //foreach (SQLiteParameter p in parameter) //{ // cmd.Parameters.Add(p); //} cmd.Parameters[0].Value = 1; cmd.Parameters[1].Value = 0; cmd.Parameters[2].Value = dt.Rows[i][0].ToString(); cmd.Parameters[3].Value = dt.Rows[i][1].ToString(); cmd.Parameters[4].Value = "http://www.9111766.com"; //rich.Text += cmd.Parameters[2].Value.ToString()+"-----导出成功\n"; //StreamWriter sr = File.CreateText(dt.Rows[i][0].ToString().Trim()+".txt"); //sr.WriteLine(dt.Rows[i][0].ToString()+"\n"+dt.Rows[i][1].ToString()); //sr.Close(); rich.AppendText(cmd.Parameters[2].Value.ToString() + "-----导出成功\n"); rich.ForeColor = System.Drawing.Color.Green;//ConsoleColor.Green; rich.Focus(); cmd.ExecuteNonQuery(); } trans.Commit(); // <------------------- } catch { trans.Rollback(); // <------------------- throw; // <------------------- } // 停止计时 sw.Stop(); } }
//导出access数据库 public void access_OutPut(GetTotalDelegateOutPut gettotaldelegateoutput, System.Diagnostics.Stopwatch sw, System.Windows.Forms.RichTextBox rich) { wznr_Servise wznr = new wznr_Servise(); int totalRecords = 0; string dbn = System.AppDomain.CurrentDomain.BaseDirectory + "Access_Data\\" + "SpiderResult.mdb";//数据库文件名称 // 创建数据库文件 File.Delete(dbn); ADOX.Catalog catalog = new Catalog(); catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbn + ";Jet OLEDB:Engine Type=5"); OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbn); conn.Open(); // 创建数据表 string sql = "CREATE TABLE Content([ID] Counter primary key,[已采] Bit,[已发] Bit,[标题] Memo,[内容] Memo,[PageUrl] Memo)"; OleDbCommand cmd = conn.CreateCommand(); cmd.Connection = conn; cmd.CommandText = sql; cmd.ExecuteNonQuery(); sw.Start(); //DbTransaction trans = conn.BeginTransaction(); // <------------------- try { // 查询出数据导出 通过数据库查询出 DataTable dt = wznr.GetDataTable("SELECT Title, p FROM test5Table order by NEWID()"); for (int i = 0; i < dt.Rows.Count; i++) { totalRecords++; gettotaldelegateoutput(totalRecords); //cmd.CommandText = "insert into [Content] ([已采],[已发],[标题],[内容],[PageUrl]) values (?,?,?,?,?)"; string strSql = "insert into [Content]([已采],[已发],[标题],[内容],[PageUrl]) values(?,?,?,?,?)"; OleDbParameter[] parameter = { new OleDbParameter("@[已采]", OleDbType.Boolean, 1), new OleDbParameter("@[已发]", OleDbType.Boolean, 1), new OleDbParameter("@[标题]", OleDbType.VarChar, 0), new OleDbParameter("@[内容]", OleDbType.VarChar, 0), new OleDbParameter("@[PageUrl]", OleDbType.VarChar, 0) }; parameter[0].Value = 1; parameter[1].Value = 0; parameter[2].Value = dt.Rows[i][0].ToString(); parameter[3].Value = dt.Rows[i][1].ToString(); parameter[4].Value = "http://www.xxx.com.cn"; rich.AppendText(parameter[2].Value.ToString() + "-----导出成功\n"); rich.ForeColor = System.Drawing.Color.Green;//ConsoleColor.Green; rich.Focus(); DbHelperOleDb.GetSingle(strSql.ToString(), parameter); //cmd.ExecuteNonQuery(); } //trans.Commit(); // <------------------- } catch { // trans.Rollback(); // <------------------- throw; // <------------------- // } // 停止计时 } sw.Stop(); }