开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 122

库卡青年/DevelopAssistant

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
标签 (3)
master
V5.0.2
V4.8.32
V4.3.31
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
标签 (3)
master
V5.0.2
V4.8.32
V4.3.31
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
标签 (3)
master
V5.0.2
V4.8.32
V4.3.31
MainForm.cs 30.33 KB
一键复制 编辑 原始数据 按行查看 历史
wxd_tony1984 提交于 2019年05月11日 15:19 +08:00 . 一些修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
using DevelopAssistant.Service;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.WinFormsUI.Docking;
using ICSharpCode.WinFormsUI.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DevelopAssistant.AddIn.SQLProfesser
{
public partial class MainForm : DockContent
{
bool isThreadBusy = false;
string assemblyPath = string.Empty;
string connectionString = string.Empty;
TreeNode LastCheckedNode = null;
BaseForm _MainForm = null;
public MainForm()
{
InitializeComponent();
InitializeControls();
}
public MainForm(BaseForm baseForm, DockPanel panel)
: this()
{
toolStripButtonOpen.Enabled = true;
toolStripButtonSave.Enabled = true;
_MainForm = baseForm;
}
private void InitializeControls()
{
connectionString = "Server=192.168.0.116;Initial Catalog=CMSGroupSet;User ID=sa;Pwd=YHPych920,.;";
textEditorControl1.ShowEOLMarkers = false;
textEditorControl1.ShowHRuler = false;
textEditorControl1.ShowInvalidLines = false;
textEditorControl1.ShowMatchingBracket = true;
textEditorControl1.ShowSpaces = false;
textEditorControl1.ShowTabs = false;
textEditorControl1.ShowVRuler = false;
textEditorControl1.AllowCaretBeyondEOL = false;
textEditorControl1.SetHighlighting("Default", "TSQL");
//textEditorControl1.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("Default", "TSQL");
//textEditorControl1.Encoding = Encoding.GetEncoding("GB2312");
panel1.BorderColor = SystemColors.ControlDarkDark;
assemblyPath = string.Format("{0}\\AddIn\\{1}", AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'), "DevelopAssistant.SQLProfesser.AddIn"); //DevelopAssistant.AddIn.SQLProfesser
//DevelopAssistant.Common.NLogger.BaseDirectory = string.Format("{0}\\Logger", AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'));
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (this.IsHandleCreated)
{
if (this.NProgressBar != null)
{
this.NProgressBar.Location = new Point((this.textEditorControl1.Width - this.NProgressBar.Width) / 2,
(this.textEditorControl1.Height - this.NProgressBar.Height) / 2);
}
}
}
private void MainForm_Load(object sender, EventArgs e)
{
LoadConfigure();
LoadTreeview();
}
private void LoadTreeview()
{
if (!isThreadBusy)
{
isThreadBusy = true;
System.Threading.Thread thread =
new System.Threading.Thread(LoadTreeview_Handler);
thread.IsBackground = true;
thread.Start();
}
else
{
MessageBox.Show(this,"系统正忙,请稍候再试...","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void LoadTreeview_Handler()
{
if (zTreeview.InvokeRequired)
{
zTreeview.Invoke(new MethodInvoker(delegate()
{
toolStripStatusLabel2.Text = "开始加载树";
zTreeview.Nodes.Clear();
}));
}
else
{
toolStripStatusLabel2.Text = "开始加载树";
zTreeview.Nodes.Clear();
}
try
{
using (var db = NORM.DataBase.DataBaseFactory.Create(connectionString, NORM.DataBase.DataBaseTypes.SqlDataBase))
{
LoadTreeview_Node(db, null);
}
if (zTreeview.InvokeRequired)
{
zTreeview.Invoke(new MethodInvoker(delegate()
{
zTreeview.ExpandAll();
toolStripStatusLabel2.Text = "完成";
}));
}
else
{
zTreeview.ExpandAll();
toolStripStatusLabel2.Text = "完成";
}
}
catch (Exception ex)
{
DevelopAssistant.Common.NLogger.WriteToLine(ex.Message, "错误", DateTime.Now, ex.Source, ex.StackTrace);
if (zTreeview.InvokeRequired)
{
zTreeview.Invoke(new MethodInvoker(delegate()
{
zTreeview.ExpandAll();
toolStripStatusLabel2.Text = ex.Message;
}));
}
else
{
zTreeview.ExpandAll();
toolStripStatusLabel2.Text = ex.Message;
}
}
isThreadBusy = false;
}
private void LoadTreeview_Node(NORM.DataBase.DataBase db, TreeViewNode node)
{
string sql = string.Empty;
if (node == null)
{
sql = "SELECT [NodeID] ,[NodeName] ,[NodeType] ,[NodeDescription] ,[AlarmSeverity] ,[ParentNodeID] ,[NodeSequence] ,[RefreshTime] ,[NodeCode] ,[ServerAddr] ,[DataBaseName] ,[DataPsd] ,[DataUser] ,[DataName] FROM [CMSGroupSet].[dbo].[TreeGroup] WHERE ParentNodeID = - 1 ";
}
else
{
sql = "SELECT [NodeID] ,[NodeName] ,[NodeType] ,[NodeDescription] ,[AlarmSeverity] ,[ParentNodeID] ,[NodeSequence] ,[RefreshTime] ,[NodeCode] ,[ServerAddr] ,[DataBaseName] ,[DataPsd] ,[DataUser] ,[DataName] FROM [CMSGroupSet].[dbo].[TreeGroup] WHERE ParentNodeID = "+node.NodeId+" ";
}
var data = db.QueryTable(sql, null);
if (node == null)
{
foreach (DataRow row in data.Rows)
{
TreeViewNode treenode = new TreeViewNode();
treenode.ImageIndex = 1;
treenode.SelectedImageIndex = treenode.ImageIndex;
treenode.Name = row["NodeID"].ToString().Trim();
treenode.NodeId = Convert.ToInt32(row["NodeID"]);
treenode.Text = row["NodeName"].ToString().Trim();
this.zTreeview.Invoke(new MethodInvoker(delegate() {
this.zTreeview.Nodes.Add(treenode);
}));
LoadTreeview_Node(db, treenode);
}
}
else
{
foreach (DataRow row in data.Rows)
{
TreeViewNode treenode = new TreeViewNode();
if (node.Level == 1)
{
treenode.ImageIndex = 2;
}
else
{
treenode.ImageIndex = 1;
}
treenode.SelectedImageIndex = treenode.ImageIndex;
treenode.Name = row["NodeID"].ToString().Trim();
treenode.NodeId = Convert.ToInt32(row["NodeID"]);
treenode.Text = row["NodeName"].ToString().Trim();
treenode.Server = row["ServerAddr"]+"";
treenode.UserID = row["DataUser"] + "";
treenode.Password = row["DataPsd"]+"";
treenode.ConfigureDataBase = row["DataBaseName"] + "";
treenode.MeasureDataBase = row["DataName"] + "";
this.zTreeview.Invoke(new MethodInvoker(delegate()
{
node.Nodes.Add(treenode);
}));
LoadTreeview_Node(db, treenode);
}
}
}
private void zTreeview_AfterCollapse(object sender, TreeViewEventArgs e)
{
e.Node.ImageIndex = 0;
e.Node.SelectedImageIndex = e.Node.ImageIndex;
}
private void zTreeview_AfterExpand(object sender, TreeViewEventArgs e)
{
e.Node.ImageIndex = 1;
e.Node.SelectedImageIndex = e.Node.ImageIndex;
}
private void zTreeview_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
TreeNode node = e.Node;
zTreeview.SelectedNode = e.Node;
LastCheckedNode = node;
}
}
private void zTreeview_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
TreeViewNode node = (TreeViewNode)e.Node;
if (node.Level == 2)
{
NORM.Common.ConnectionString connection = new NORM.Common.ConnectionString();
connection.DataBaseName = node.ConfigureDataBase;
connection.Server = node.Server;
connection.UserId = node.UserID;
connection.Password = node.Password;
using (var db = NORM.DataBase.DataBaseFactory.Create(connection.connectionString, NORM.DataBase.DataBaseTypes.SqlDataBase))
{
string Message=string.Empty;
if (db.TestConnect(out Message))
{
string sql = "SELECT [NodeID] ,[NodeName] ,[NodeType] ,[NodeDescription] ,[AlarmSeverity] ,[ParentNodeID] ,[NodeSequence] ,[RefreshTime] ,[Active] ,[HasChild] ,[Diagram] ,[OutCode] ";
sql += "FROM [TreeStructure] WHERE [NodeType]='设备' ";
sql += "ORDER BY [NodeName] ASC ";
var data = db.QueryTable(sql, null);
if (data.Rows.Count > 0)
{
if (node.Nodes.Count <= 0)
{
foreach (DataRow row in data.Rows)
{
TreeViewNode nde = new TreeViewNode();
nde.ImageIndex = 3;
nde.SelectedImageIndex = nde.ImageIndex;
nde.NodeId = Convert.ToInt32(row["NodeID"] + "");
nde.Text = row["NodeName"] + "";
node.Nodes.Add(nde);
}
node.Expand();
e.Node.ImageIndex = 1;
e.Node.SelectedImageIndex = e.Node.ImageIndex;
}
}
}
else
{
MessageBox.Show(this, Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void zTreeview_AfterCheck(object sender, TreeViewEventArgs e)
{
if (e.Action == TreeViewAction.ByMouse)
{
TreeNode node = e.Node;
zTreeview.SelectedNode = e.Node;
zTreeview_NodeChildrenHandle(node);
zTreeview_NodeParentHandle(node);
LastCheckedNode = node;
}
}
private void zTreeview_NodeChildrenHandle(TreeNode node)
{
foreach (TreeNode nde in node.Nodes)
{
nde.Checked = node.Checked;
zTreeview_NodeChildrenHandle(nde);
}
}
private void zTreeview_NodeParentHandle(TreeNode node)
{
if (node.Parent != null)
{
if (node.Checked)
{
node.Parent.Checked = node.Checked;
}
if (!node.Checked)
{
bool allunchecked = true;
foreach (TreeNode nde in node.Parent.Nodes)
{
if (nde.Checked)
{
allunchecked = false;
break;
}
}
if (allunchecked)
{
node.Parent.Checked = false;
}
}
zTreeview_NodeParentHandle(node.Parent);
}
}
private void btnExecute_Click(object sender, EventArgs e)
{
ExecuteCommand();
}
private void toolStripButtonRefresh_Click(object sender, EventArgs e)
{
LoadTreeview();
}
private void toolStripButtonConnectionSetting_Click(object sender, EventArgs e)
{
SettingsForm form = new SettingsForm(this.connectionString);
if (this._MainForm != null)
{
form.Text = _MainForm.Text;
form.XTheme = _MainForm.XTheme;
}
if (form.ShowDialog(this).Equals(DialogResult.OK))
{
this.connectionString = form.ConnectionString.ToString();
SaveConfigure();
}
}
private void toolStripButtonSQLFormat_Click(object sender, EventArgs e)
{
string sql = this.textEditorControl1.Text;
textEditorControl1.Text = "格式化中...";
System.Threading.Thread th = new System.Threading.Thread(() => {
string sqlformat = DevelopAssistant.Format.TsqlFormatHelper.FormatToTSQL(sql, AppSettings.EditorSettings.KeywordsCase);
this.Invoke(new MethodInvoker(delegate() { textEditorControl1.Text = sqlformat; }));
});
th.IsBackground = true;
th.Start();
}
private void LoadConfigure()
{
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load(assemblyPath);
try
{
var element = xmlDoc.SelectSingleNode("//ConnectionString");
if (element != null)
{
string value =element.InnerText;
connectionString = NORM.Common.DEncrypt.Decrypt(value, "#ZB@8741Z");
}
}
catch (Exception ex)
{
}
}
private void SaveConfigure()
{
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load(assemblyPath);
try
{
var element = xmlDoc.SelectSingleNode("//ConnectionString");
if (element != null)
{
string value = NORM.Common.DEncrypt.Encrypt(connectionString, "#ZB@8741Z");
element.InnerText = value;
}
xmlDoc.Save(assemblyPath);
}
catch (Exception ex)
{
}
}
private void ExecuteCommand()
{
if (!isThreadBusy)
{
string CommandText = this.textEditorControl1.ActiveTextAreaControl.SelectionManager.SelectedText;
if (string.IsNullOrEmpty(CommandText))
{
CommandText = this.textEditorControl1.ActiveTextAreaControl.Document.TextContent;
}
if (string.IsNullOrEmpty(CommandText))
{
isThreadBusy = false;
MessageBox.Show(this, "SQL命令文本不能为空", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (!chkConfigure.Checked && !chkMeasureData.Checked)
{
isThreadBusy = false;
MessageBox.Show(this, "请先选择要执行的数据库类型", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
isThreadBusy = true;
NProgressBar.Visible = true;
progressBar1.Value = 0;
label1.Text = "任务开始执行 校验中...";
System.Threading.Thread th =
new System.Threading.Thread(delegate() { ExecuteCommand_Handler(CommandText); });
th.IsBackground = true;
th.Start();
}
else
{
MessageBox.Show(this,"系统正忙,请稍候再试","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void ExecuteCommand_Handler(string sql)
{
int zcount = 0;
foreach (TreeNode node in this.zTreeview.Nodes)
{
foreach (TreeNode node2 in node.Nodes)
{
foreach (TreeNode node3 in node2.Nodes)
{
if (node3.Checked)
{
zcount++;
}
}
}
}
if (chkConfigure.Checked && chkMeasureData.Checked)
{
zcount = zcount * 2;
}
int index = 0; double value = 0;
NProgressBar.Invoke(new MethodInvoker(delegate() { label1.Text = "已完成: " + index + " / " + zcount; }));
foreach (TreeViewNode node in this.zTreeview.Nodes)
{
foreach (TreeViewNode node2 in node.Nodes)
{
foreach (TreeViewNode node3 in node2.Nodes)
{
if (node3.Checked)
{
if (chkConfigure.Checked)
{
index++;
value = index * 1.0 / zcount * 100;
NORM.Common.ConnectionString connect = new NORM.Common.ConnectionString();
connect.Server = node3.Server;
connect.UserId = node3.UserID;
connect.Password = node3.Password;
connect.DataBaseName = node3.ConfigureDataBase;
ExceuteTSQL(connect, sql);
NProgressBar.Invoke(new MethodInvoker(delegate()
{
label1.Text ="已完成: "+ index + " / " + zcount;
progressBar1.Value = (int)value;
}));
}
if (chkMeasureData.Checked)
{
index++;
value = index * 1.0 / zcount * 100;
NORM.Common.ConnectionString connect = new NORM.Common.ConnectionString();
connect.Server = node3.Server;
connect.UserId = node3.UserID;
connect.Password = node3.Password;
connect.DataBaseName = node3.MeasureDataBase;
ExceuteTSQL(connect, sql);
NProgressBar.Invoke(new MethodInvoker(delegate()
{
label1.Text = "已完成: " + index + " / " + zcount;
progressBar1.Value = (int)value;
}));
}
}
}
}
}
isThreadBusy = false;
NProgressBar.Invoke(new MethodInvoker(delegate()
{
NProgressBar.Visible = false;
}));
}
private void ExceuteTSQL(NORM.Common.ConnectionString conn,string sql)
{
string Message = string.Empty;
if (string.IsNullOrEmpty(conn.Server))
{
return;
}
if (string.IsNullOrEmpty(conn.DataBaseName))
{
return;
}
using (var db = NORM.DataBase.DataBaseFactory.Create(conn.ToString(),NORM.DataBase.DataBaseTypes.SqlDataBase))
{
var connected = db.TestConnect(out Message);
if (connected)
{
try
{
var SqlCommands = System.Text.RegularExpressions.Regex.Split(
sql //System.Text.RegularExpressions.Regex.Replace(sql, "[\r\n|\r|\n]+", "\r\n", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
, @"\r\n\s*go", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
foreach (var command in SqlCommands)
{
string commandText = System.Text.RegularExpressions.Regex.Replace(command, "/\\*.*\\*/", " ", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
commandText = System.Text.RegularExpressions.Regex.Replace(commandText.Replace("数据库名", conn.DataBaseName), "[\r\n|\r|\n]+", "\r\n", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (!string.IsNullOrEmpty(commandText.Replace("\r\n","").Trim()))
{
db.Execute(CommandType.Text, commandText, null);
}
}
//db.Execute(CommandType.Text, sql, null);
}
catch (Exception ex)
{
//记录日志
DevelopAssistant.Common.NLogger.WriteToLine(ex.Message, "系统错误", DateTime.Now, ex.Source, ex.StackTrace);
this.Invoke(new MethodInvoker(() => { ICSharpCode.WinFormsUI.Forms.MessageForm.Show(this._MainForm, ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); }));
}
}
}
}
private void toolStripButtonRebuild_Click(object sender, EventArgs e)
{
RebuildIndxes();
}
private void RebuildIndxes()
{
int checkedNodesCount = 0;
foreach (TreeViewNode node1 in this.zTreeview.Nodes)
{
foreach (TreeViewNode node2 in node1.Nodes)
{
foreach (TreeViewNode node3 in node2.Nodes)
{
if (node3.Checked)
{
checkedNodesCount++;
}
}
}
}
if (checkedNodesCount > 0)
{
isThreadBusy = true;
NProgressBar.Visible = true;
progressBar1.Value = 0;
label1.Text = "任务开始执行 校验中...";
System.Threading.Thread th = new System.Threading.Thread(() =>
{
var result = RebuildIndexes_Handler(checkedNodesCount);
isThreadBusy = false;
NProgressBar.Invoke(new MethodInvoker(delegate()
{
label1.Text = "任务执行完成 详细信息请查看日志";
NProgressBar.Visible = false;
}));
});
th.IsBackground = true;
th.Start();
}
else
{
MessageBox.Show(this, "请左侧选择风场节点", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private bool RebuildIndexes_Handler(int zcount)
{
int index = 0;
foreach (TreeViewNode node1 in this.zTreeview.Nodes)
{
foreach (TreeViewNode node2 in node1.Nodes)
{
foreach (TreeViewNode node3 in node2.Nodes)
{
if (node3.Checked)
{
NORM.Common.ConnectionString connect = new NORM.Common.ConnectionString();
connect.Server = node3.Server;
connect.UserId = node3.UserID;
connect.Password = node3.Password;
connect.DataBaseName = node3.MeasureDataBase;
RebuildIndexesTSQL(connect);
index++;
double value = index * 1.0 / zcount * 100;
NProgressBar.Invoke(new MethodInvoker(delegate() {
progressBar1.Value = (int)value;
label1.Text = "任务开始执行 已完成 " + index + " / " + zcount;
}));
}
}
}
}
return true;
}
private void RebuildIndexesTSQL(NORM.Common.ConnectionString conn)
{
using (var db = NORM.DataBase.DataBaseFactory.Create(conn.ToString(), NORM.DataBase.DataBaseTypes.SqlDataBase))
{
string message=string.Empty;
if(db.TestConnect(out message))
{
string sql = "SELECT Name FROM SysObjects Where XType='U' ";
sql += "AND ( Name LIKE 'MeasureValues_%' OR Name LIKE 'WaveData_%') ";
sql += "ORDER BY Name ";
var data = db.QueryTable(sql);
int timeout = 2 * 60;
foreach (DataRow row in data.Rows)
{
string name = (row["Name"] + "").Trim();
if (name.Equals("MeasureValuesA", StringComparison.OrdinalIgnoreCase))
{
continue;
}
try
{
string command = "DROP INDEX [IX_" + name + "] ON [dbo].[" + name + "] ";
db.Execute(CommandType.Text,command,null);
if (name.StartsWith("WaveData", StringComparison.OrdinalIgnoreCase))
{
command = "DROP INDEX [PK_" + name + "] ON [dbo].[" + name + "] ";
db.Execute(CommandType.Text, command, null);
}
DevelopAssistant.Common.NLogger.WriteToLine("表 [" + name + "] 删除索引成功", "DevelopAssistant.AddIn.SQLProfesser", DateTime.Now, "", "");
}
catch (Exception ex)
{
DevelopAssistant.Common.NLogger.WriteToLine(ex.Message, "DevelopAssistant.AddIn.SQLProfesser", DateTime.Now, ex.Source, ex.StackTrace);
}
try
{
string command = "CREATE NONCLUSTERED INDEX [IX_" + name + "] ON [dbo].[" + name + "] ";
if (name.StartsWith("MeasureValues", StringComparison.OrdinalIgnoreCase))
{
command += "( [Datetime] DESC ) ";
}
else
{
command += "( [DateTime] DESC,[NodeID] ASC,[ParaID] ASC ) ";
}
command += "WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ";
db.Execute(CommandType.Text, command, null);
DevelopAssistant.Common.NLogger.WriteToLine("表 [" + name + "] 创建索引成功", "完成", DateTime.Now, "DevelopAssistant.AddIn.SQLProfesser");
}
catch (Exception ex)
{
DevelopAssistant.Common.NLogger.WriteToLine(ex.Message, "错误", DateTime.Now, ex.Source, ex.StackTrace);
}
}
}
}
}
private void toolStripButtonOpen_Click(object sender, EventArgs e)
{
var openfiledlg = new OpenFileDialog();
openfiledlg.Filter = "sql脚本|*.sql|text文本|*.txt";
if (openfiledlg.ShowDialog(this).Equals(DialogResult.OK))
{
if (!string.IsNullOrEmpty(openfiledlg.FileName))
{
string filePath = openfiledlg.FileName;
string content = string.Empty;
using (System.IO.StreamReader sr = new System.IO.StreamReader(filePath,System.Text.Encoding.Default))
{
content = sr.ReadToEnd();
}
this.textEditorControl1.Text = content;
}
}
}
private void toolStripButtonSave_Click(object sender, EventArgs e)
{
var savefiledlg = new SaveFileDialog();
savefiledlg.Filter = "sql脚本|*.sql";
if (savefiledlg.ShowDialog(this).Equals(DialogResult.OK))
{
if (!string.IsNullOrEmpty(savefiledlg.FileName))
{
string savePath = savefiledlg.FileName;
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(savePath, false, System.Text.Encoding.Default))
{
sw.Write(this.textEditorControl1.Text);
}
}
}
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

开发助手是一款面向开发人员的辅助助手,它集数据库管理(目前支持sqlserver,sqlite,mysql,postgresql),代码生成(支持从数据库生成实体映射类,数据库操作DAL中间层),数据库文档生成,代码收藏夹(支持C#,SQL,Javascrip,Html,XML,Python语法高亮),富文本编辑,插件管理等功能模块。自2015年到如今,它已经历过4个重大版本的升级,径过不断修复和完善,目前已成为一款堪称得心应手的开发辅助工具。
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/wwwpythonpw/DevelopAssistant.git
git@gitee.com:wwwpythonpw/DevelopAssistant.git
wwwpythonpw
DevelopAssistant
DevelopAssistant
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /