//private static void zedGraphControl1_MouseMove(object sender, MouseEventArgs e)//鼠标移动出现虚线 //{ // using (Graphics gc = MainForm.getInstance().DTSReal.CreateGraphics()) // using (Pen pen = new Pen(Color.Gray)) // { // pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; // RectangleF rect = MainForm.getInstance().DTSReal.GraphPane.Chart.Rect; // //确保在画图区域 // if (rect.Contains(e.Location)) // { // MainForm.getInstance().DTSReal.Refresh(); // gc.DrawLine(pen, e.X, rect.Top, e.X, rect.Bottom); // gc.DrawLine(pen, rect.Left, e.Y, rect.Right, e.Y); // } // } //} public static void drawRealDTS(List <DataTable> dt) { float wellzero = ZedGraphClass.getWellZero(); ZedGraph.GraphPane gp = MainForm.getInstance().DTSReal.GraphPane; MainForm.getInstance().DTSReal.PointValueEvent += new ZedGraphControl.PointValueHandler(ZedGraphClass.MyPointValueHandlerTime);//设置节点信息显示样式 //MainForm.getInstance().DTSReal.IsShowHScrollBar = true;//横向滚动条 // MainForm.getInstance().DTSReal.MouseMove += zedGraphControl1_MouseMove;//鼠标在图上移动出现x虚线 MainForm.getInstance().DTSReal.IsShowPointValues = true; // MainForm.getInstance().DTSReal.IsZoomOnMouseCenter = false; //使用滚轮时以鼠标所在点进行缩放还是以图形中心进行缩放。 gp.GraphObjList.Clear(); gp.CurveList.Clear(); //int Linenumber = Convert.ToInt32(MainForm.getInstance().DTSLineNumber.Text); //int k = 0; //if (dt.Count - Linenumber < 0) //{ //} //else //{ // k = dt.Count - Linenumber; //} for (int i = 1; i < dt.Count; i++)//从第一条线开始,并且两条线 { DataTable table = dt[i]; string Linename = table.Rows[0][0].ToString(); PointPairList list1 = new PointPairList(); for (int j = 0; j < table.Rows.Count; j++) { double x; float y; //X轴减去部分井口数据。 x = float.Parse(table.Rows[j][1].ToString()) - wellzero; y = float.Parse(table.Rows[j][2].ToString()); list1.Add(x, y); } if (list1.Count == 0)//如果曲线没有数据 { continue; } else { Color co = ZedGraphClass.GetColor(i); LineItem _lineitem2 = gp.AddCurve(Linename, list1, ZedGraphClass.GetColor(i), SymbolType.Circle); _lineitem2.Line.Width = 2.0F; //线的宽度 string la = _lineitem2.Label.Text.ToString(); _lineitem2.Symbol.Size = 2.4F; //线上节点的大小 _lineitem2.Symbol.Fill = new Fill(co); //线上节点的颜色 //gp.AxisChange();//若是 } } gp.AxisChange();//若是放到上面的那一行,因为数据太多,会有延迟,导致图形颜色不断变化(一条线一条线的画) MainForm.getInstance().DTSReal.Refresh(); }
public static string getWellStr() { float wellzero = ZedGraphClass.getWellZero(); MySqlConnection mycon = new MySqlConnection(); mycon = getMycon(); string Str = null; //string aa = MainForm.getInstance().WellTime.Value.ToString(); DateTime aa = MainForm.getInstance().WellTime.Value;//获取时间 //string name = CreateTable.getTableName(aa, "DTS");//获取文件将要存入的表名称 //CreateTable.CDataTable(name);//创建表 string str = "SELECT DISTINCT folderTime from alltemporpary_data WHERE folderTime >= \'" + aa + "\' order by folderTime"; System.Data.DataTable dt = getDataTable(str, mycon); if (dt.Rows.Count != 0) { aa = Convert.ToDateTime(dt.Rows[0]["folderTime"]); string name = CreateTable.getTableName(aa, "DTS");//获取文件将要存入的表名称 Str = "Select wellbore.mD,wellbore.DepthH,wellbore.TVD,wellbore.inclAngle," + name + ".TM from wellbore ," + name + " Where wellbore.mD =(" + name + ".Depth-" + wellzero + ") and " + name + ".RecordTime='" + aa + "'"; } return(Str); }
public static void DrawingDep()//画时间温度曲线 { //获取时间的查询条件 string messageError = null; String SQLstr = getSQLstr(); MySqlConnection mycon = new MySqlConnection(); mycon = getMycon(); //获取井口位置 float wellzero = ZedGraphClass.getWellZero(); //获取循环(单循环还是多循环) string button = MainForm.getInstance().number.Text; //画图图禁止菜单和画图区域 MainForm.getInstance().groupBox2.Enabled = false; MainForm.getInstance().zgcDep.Enabled = false; //新建数据库连接 string DsingleDepth = MainForm.getInstance().DsingleDepth.Text; if (SQLstr != null) { DataTable SQLName = getTNameTable(DintervalTime1, DintervalTime2);//获取需要使用的表名称 if (SQLName.Rows.Count != 0) { ArrayList SQLList = MyDataTable.getDepth(wellzero, DsingleDepth); //获取深度值 if (SQLList.Count <= 15 && SQLList.Count > 0) //15条线之内 { SQLList = ZedGraphClass.getNewDepth(SQLList); //去重 ZedGraph.GraphPane gp = MainForm.getInstance().zgcDep.GraphPane; //gp.CurveList.Clear();//清除上一步画的图 gp.GraphObjList.Clear(); gp.CurveList.Clear(); //是否X、Y轴缩放的定义 if (MainForm.getInstance().label1.Text == "1") { MainForm.getInstance().zgcDep.IsEnableVZoom = true; //Y轴缩放 MainForm.getInstance().zgcDep.IsEnableHZoom = true; //x轴缩放 } else { MainForm.getInstance().zgcDep.IsEnableVZoom = false; //禁止Y轴缩放 MainForm.getInstance().zgcDep.IsEnableHZoom = true; //x轴缩放 } MainForm.getInstance().zgcDep.PointValueEvent += new ZedGraphControl.PointValueHandler(ZedGraphClass.MyPointValueHandlerDep); //设置节点信息显示样式 MainForm.getInstance().zgcDep.MouseMove += zedGraphControl1_MouseMove; //鼠标在图上移动出现x虚线 MainForm.getInstance().zgcDep.IsShowPointValues = true; //显示节点坐标值 MainForm.getInstance().zgcDep.IsZoomOnMouseCenter = false; //使用滚轮时以鼠标所在点进行缩放还是以图形中心进行缩放。 if (MainForm.getInstance().DintervalTM1.Text != "" && MainForm.getInstance().DintervalTM2.Text != "") { gp.YAxis.Scale.Min = float.Parse(MainForm.getInstance().DintervalTM1.Text); gp.YAxis.Scale.Max = float.Parse(MainForm.getInstance().DintervalTM2.Text); } else { gp.YAxis.Scale.MaxAuto = true; //自动设置大小 gp.YAxis.Scale.MinAuto = true; } MainForm.getInstance().zgcDep.IsAutoScrollRange = false; //坐标轴刻度格式 gp.XAxis.Scale.Format = "yyyy-MM-dd HH:mm:ss"; //横轴格式 gp.XAxis.Type = AxisType.Date; //格式 string[] hn = new string[SQLList.Count]; //折线的标签 if (button == "two") //循环作图 { for (int xunhuan = 0; xunhuan < 4; xunhuan++) { //清除上一步画的图 gp.GraphObjList.Clear(); gp.CurveList.Clear(); for (int i = 0; i < SQLList.Count; i++) { System.Threading.Thread.Sleep(1000); PointPairList list1 = new PointPairList(); DataTable dtValue = new DataTable(); string SQLque = "RecordTime"; dtValue = MyDataTable.getDataTable(SQLName, Convert.ToInt32(SQLList[i]), SQLstr, SQLque, mycon); float e = Convert.ToInt32(SQLList[i].ToString()) - wellzero; hn[i] = e + "m"; for (int k = 0; k < dtValue.Rows.Count; k++) { int bili = 1; if (dtValue.Rows.Count > 1000) { bili = dtValue.Rows.Count / 500; } if (k % bili == 0) { double x = (double)new XDate((DateTime)dtValue.Rows[k]["RecordTime"]); string a = dtValue.Rows[k]["RecordTime"].ToString(); double y = double.Parse(dtValue.Rows[k]["TM"].ToString()); list1.Add(x, y); } } if (list1.Count == 0 && xunhuan == 0) //如果曲线没有数据 { messageError += "深度" + SQLList[i] + "m无数据\n"; continue; } else { Color co = ZedGraphClass.GetColor(i); LineItem _lineitem2 = gp.AddCurve(hn[i], list1, co, SymbolType.Circle); _lineitem2.Line.Width = 2.0F; //线的宽度 //节点设置 if (drawAttribute.Linenum == 2) { _lineitem2.Line.IsVisible = false; } _lineitem2.Symbol.Size = 2.4F; //线上节点的大小 _lineitem2.Symbol.Fill = new Fill(co); //线上节点的颜色 gp.AxisChange(); MainForm.getInstance().zgcDep.Refresh(); } } } } else { for (int i = 0; i < SQLList.Count; i++) { PointPairList list1 = new PointPairList(); DataTable dtValue = new DataTable(); string SQLque = "RecordTime"; dtValue = MyDataTable.getDataTable(SQLName, Convert.ToInt32(SQLList[i]), SQLstr, SQLque, mycon); float e = Convert.ToInt32(SQLList[i].ToString()) - wellzero; hn[i] = e + "m"; for (int k = 0; k < dtValue.Rows.Count; k++) { int bili = 1; if (dtValue.Rows.Count > 1000) { bili = dtValue.Rows.Count / 500; } if (k % bili == 0) { double x = (double)new XDate((DateTime)dtValue.Rows[k]["RecordTime"]); string a = dtValue.Rows[k]["RecordTime"].ToString(); double y = double.Parse(dtValue.Rows[k]["TM"].ToString()); list1.Add(x, y); } } if (list1.Count == 0) //如果曲线没有数据 { messageError += "深度" + SQLList[i] + "m无数据\n"; continue; } else { Color co = ZedGraphClass.GetColor(i); LineItem _lineitem2 = gp.AddCurve(hn[i], list1, co, SymbolType.Circle); _lineitem2.Line.Width = 2.0F; //线的宽度 //节点设置 if (drawAttribute.Linenum == 2) { _lineitem2.Line.IsVisible = false; } _lineitem2.Symbol.Size = 2.4F; //线上节点的大小 _lineitem2.Symbol.Fill = new Fill(co); //线上节点的颜色 gp.AxisChange(); MainForm.getInstance().zgcDep.Refresh(); } } } } else if (SQLList.Count > 15) { //MessageBox.Show("深度区间太大,曲线条数大于15"); MessageBox.Show("深度区间太大,曲线条数大于15!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { // MessageBox.Show("在所选时间区间内数据库中无数据");//表中无数据 MessageBox.Show("请填写深度!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { // MessageBox.Show("所选时间区间内没有数据,请更改时间区域!"); //没有表 MessageBox.Show("所选时间区间内没有数据,请更改时间区域!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (messageError != null) { MessageBox.Show("以下深度点无数据!\n" + messageError, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { // MessageBox.Show("时间区间选择不正确,请修改!"); MessageBox.Show("时间区间选择不正确,请修改!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } MainForm.getInstance().groupBox2.Enabled = true; MainForm.getInstance().zgcDep.Enabled = true; mycon.Close(); mycon.Dispose(); SQLstr = null; }
public static void SaveCSV(System.Data.DataTable dt, string fullPath, int exportNum)//table数据写入csv { //exportNum:最初DTS和FBG不一样,只有DTS需要井口位置,现在都需要了,所以这个量不需要了,但是现在指示代码注释。 float wellzero = ZedGraphClass.getWellZero(); System.IO.FileInfo fi = new System.IO.FileInfo(fullPath); if (!fi.Directory.Exists) { fi.Directory.Create(); } System.IO.FileStream fs = new System.IO.FileStream(fullPath, System.IO.FileMode.Create, System.IO.FileAccess.Write); System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.UTF8); string data = "列名,"; string data1; System.Data.DataTable dtTime = null; //获取时间 System.Data.DataTable dtDepth = null; //获取深度 if (MainForm.getInstance().comboBox1.Text == "深度为纵轴,时间为横轴") { dtTime = export.SelectDistinct(dt, dt.Columns[1].ColumnName.ToString()); //获取不同的时间数据 dtDepth = export.SelectDistinct(dt, dt.Columns[0].ColumnName.ToString()); //获取不同的深度数据 for (int i = 0; i < dtTime.Rows.Count; i++) //写入列名 { data1 = dtTime.Rows[i][0].ToString(); data += data1; if (i < dtTime.Rows.Count - 1) { data += ","; } } sw.WriteLine(data); for (int i = 0; i < dtDepth.Rows.Count; i++) //写入各行数据 { //得到row的数据 string data2; //if (exportNum!=1) //{ // data2 = dtDepth.Rows[i][0].ToString(); //} //else{ data2 = ((float)(dtDepth.Rows[i][0]) - wellzero).ToString(); //} string aaa = dtDepth.Rows[i][0].ToString(); DataRow[] drss = null; drss = dt.Select("Depth = '" + aaa + "'", "RecordTime asc");//每行数据 for (int k = 0; k < drss.Length; k++) { string b = drss[k][2].ToString(); data2 += "," + b; } sw.WriteLine(data2); } } else { dtTime = export.SelectDistinct(dt, dt.Columns[0].ColumnName.ToString()); dtDepth = export.SelectDistinct(dt, dt.Columns[1].ColumnName.ToString()); for (int i = 0; i < dtTime.Rows.Count; i++)//写入列名 { //if (exportNum != 1) //{ // data1 = dtTime.Rows[i][0].ToString(); //} //else //{ data1 = ((float)(dtTime.Rows[i][0]) - wellzero).ToString(); //} data += data1;//"\t"是为了导出时保留原格式 if (i < dtTime.Rows.Count - 1) { data += ","; } } sw.WriteLine(data); for (int i = 0; i < dtDepth.Rows.Count; i++) //写入各行数据 { //得到row的数据 string data2 = dtDepth.Rows[i][0].ToString(); // data2 = "\t" + data2; // data2 = data2; DataRow[] drss = null; drss = dt.Select("RecordTime = '" + data2 + "'", "Depth asc");//从小到大 for (int k = 0; k < drss.Length; k++) { string b = drss[k][2].ToString(); // data2 += "," + "\t" + b; data2 += "," + b; } sw.WriteLine(data2); } } sw.Close(); fs.Close(); }
public static string getstr1()//获取SQL语句 { string str1 = null; float wellzero = ZedGraphClass.getWellZero(); if (MainForm.getInstance().intervalTime2.Value >= MainForm.getInstance().intervalTime1.Value)//如果时间正确 { intervalTime1 = MainForm.getInstance().intervalTime1.Value; intervalTime2 = MainForm.getInstance().intervalTime2.Value; if (MainForm.getInstance().singleDepth.Text == "")//如果深度单项为空 { try { intervalDepth1 = float.Parse(MainForm.getInstance().intervalDepth1.Text) + wellzero; intervalDepth2 = float.Parse(MainForm.getInstance().intervalDepth2.Text) + wellzero; if (intervalDepth2 >= intervalDepth1 && intervalDepth1 >= 0) { if (MainForm.getInstance().intervalTM1.Text == "" && MainForm.getInstance().intervalTM2.Text == "")//如果温度为空 { str1 = " WHERE RecordTime BETWEEN \'" + intervalTime1 + "\' and \'" + intervalTime2 + "\'and Depth between " + intervalDepth1 + " and " + intervalDepth2; } else if (MainForm.getInstance().intervalTM1.Text != "" && MainForm.getInstance().intervalTM2.Text != "")//如果温度存在 { intervalTM1 = float.Parse(MainForm.getInstance().intervalTM1.Text); intervalTM2 = float.Parse(MainForm.getInstance().intervalTM2.Text); if (intervalTM2 >= intervalTM1)// { str1 = " WHERE RecordTime BETWEEN \'" + intervalTime1 + "\' and \'" + intervalTime2 + "\'and Depth between " + intervalDepth1 + " and " + intervalDepth2 + " and TM between " + intervalTM1 + " and " + intervalTM2; string a = str1; //MessageBox.Show("热“"); } else { MessageBox.Show("区间温度填写不正确", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("请将区间温度填写完成", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("深度区间不正确", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { MessageBox.Show("区间深度输入格式不正确\n", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else //如果深度单项为条件 { try { singleDepth = MainForm.getInstance().singleDepth.Text; String [] strs = singleDepth.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int[] strs1 = new int[strs.Length]; for (int i = 0; i < strs.Length; i++)//将单项深度导入int数组,看是否正确 { strs1[i] = int.Parse(strs[i]); } string singleDepth1 = null; for (int i = 0; i < strs.Length; i++) { float dep = strs1[i] + wellzero; singleDepth1 = singleDepth1 + dep + ','; } singleDepth1 = singleDepth1.Remove(singleDepth1.Length - 1, 1); if (MainForm.getInstance().intervalTM1.Text == "" && MainForm.getInstance().intervalTM2.Text == "")//如果温度为空 { str1 = " WHERE RecordTime BETWEEN \'" + intervalTime1 + "\' and \'" + intervalTime2 + "\'and Depth in (" + singleDepth1 + ") "; } else if (MainForm.getInstance().intervalTM1.Text != "" && MainForm.getInstance().intervalTM2.Text != "")//如果温度存在 { intervalTM1 = float.Parse(MainForm.getInstance().intervalTM1.Text); intervalTM2 = float.Parse(MainForm.getInstance().intervalTM2.Text); if (intervalTM2 >= intervalTM1)// { str1 = " WHERE RecordTime BETWEEN \'" + intervalTime1 + "\' and \'" + intervalTime2 + "\' and Depth in (" + singleDepth1 + ") and TM between " + intervalTM1 + " and " + intervalTM2; string a = str1; } else { MessageBox.Show("区间温度填写不正确", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("请将区间温度填写完成", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch //深度格式不正确 { MessageBox.Show("单项深度输入格式不正确\n", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { MessageBox.Show("时间选择不正确", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(str1); }
public static void DrawingGratDep()//画时间温度曲线 { MyThread myt = new MyThread(); string messageError = null; string GratDepth = MainForm.getInstance().textBox3.Text; String SQLstr = getstr();//获取str MainForm.getInstance().groupBox1.Enabled = false; MainForm.getInstance().GDep.Enabled = false; MySqlConnection mycon = new MySqlConnection(); mycon = getMycon(); string button = MainForm.getInstance().number.Text; float wellzero = ZedGraphClass.getWellZero(); if (SQLstr != null) { DataTable SQLName = getTNameTable(GratDepTime1, GratDepTime2);//获取需要使用的表名称 if (SQLName.Rows.Count != 0) { ArrayList SQLList = MyDataTable.getDepth(wellzero, GratDepth);//获取深度值 if (SQLList.Count != 0) { SQLList = ZedGraphClass.getNewDepth(SQLList);//去重 ZedGraph.GraphPane gp = MainForm.getInstance().GDep.GraphPane; gp.GraphObjList.Clear(); gp.CurveList.Clear(); if (MainForm.getInstance().label1.Text == "1") { MainForm.getInstance().GDep.IsEnableVZoom = true; //Y轴缩放 MainForm.getInstance().GDep.IsEnableHZoom = true; //x轴缩放 } else { MainForm.getInstance().GDep.IsEnableVZoom = false; //禁止Y轴缩放 MainForm.getInstance().GDep.IsEnableHZoom = true; //x轴缩放 } MainForm.getInstance().GDep.PointValueEvent += new ZedGraphControl.PointValueHandler(ZedGraphClass.MyPointValueHandlerDep); //设置节点信息显示样式 //MainForm.getInstance().GDep.IsShowHScrollBar = true; //是否显示横向滚动条。 //MainForm.getInstance().GDep.ZoomStepFraction = 0;//不允许鼠标放大缩小 MainForm.getInstance().GDep.MouseMove += zedGraphControl1_MouseMove; //鼠标在图上移动出现x虚线 MainForm.getInstance().GDep.IsShowPointValues = true; //显示节点坐标值 MainForm.getInstance().GDep.IsZoomOnMouseCenter = false; //使用滚轮时以鼠标所在点进行缩放还是以图形中心进行缩放。 if (MainForm.getInstance().GratDepTM1.Text != "" && MainForm.getInstance().GratDepTM2.Text != "") { gp.YAxis.Scale.Min = float.Parse(MainForm.getInstance().GratDepTM1.Text); gp.YAxis.Scale.Max = float.Parse(MainForm.getInstance().GratDepTM2.Text); } else { gp.YAxis.Scale.MaxAuto = true;//自动设置大小 gp.YAxis.Scale.MinAuto = true; } MainForm.getInstance().GDep.IsAutoScrollRange = false; gp.XAxis.Scale.Format = "yyyy-MM-dd HH:mm:ss"; //横轴格式 gp.XAxis.Type = AxisType.Date; //格式 string[] hn = new string[SQLList.Count]; //折现的标签 if (button == "two") { for (int k = 0; k < 4; k++) { gp.GraphObjList.Clear(); gp.CurveList.Clear();//清除上一步画的图 for (int i = 0; i < SQLList.Count; i++) { System.Threading.Thread.Sleep(1000); DataTable dtValue = new DataTable(); string SQLque = "RecordTime"; dtValue = MyDataTable.getDataTable(SQLName, Convert.ToInt32(SQLList[i]), SQLstr, SQLque, mycon); float e = Convert.ToInt32(SQLList[i].ToString()) - wellzero; hn[i] = e + "m"; //hn[i] = SQLList[i] + "m"; PointPairList list1 = new PointPairList(); for (int j = 0; j < dtValue.Rows.Count; j++) { int bili = 1; if (dtValue.Rows.Count > 1000) { bili = dtValue.Rows.Count / 500; } if (j % bili == 0) { // string a = dt.Rows[j]["RecordTime"].ToString(); double x = (double)new XDate((DateTime)dtValue.Rows[j]["RecordTime"]); //double x = (double)new XDate((DateTime)dt.Rows[j]["RecordTime"]); float y = float.Parse(dtValue.Rows[j]["TM"].ToString()); list1.Add(x, y); } //TextObj text = new TextObj("shiji", x, y); //gp.GraphObjList.Add(text); } if (list1.Count == 0 && k == 0)//如果曲线没有数据或缺少数据 { //MessageBox.Show("曲线不存在"); messageError += "深度" + SQLList[i] + "m无数据\n"; continue; } else { Color co = ZedGraphClass.GetColor(i); LineItem _lineitem2 = gp.AddCurve(hn[i], list1, ZedGraphClass.GetColor(i), SymbolType.Circle); //_lineitem2.Label.IsVisible = false;//名称不见的一种形式 _lineitem2.Line.Width = 2.0F;//线的宽度 //节点设置 if (drawAttribute.Linenum == 2) { _lineitem2.Line.IsVisible = false; } _lineitem2.Symbol.Size = 2.4F; //线上节点的大小 _lineitem2.Symbol.Fill = new Fill(co); //线上节点的颜色 gp.AxisChange(); MainForm.getInstance().GDep.Refresh(); } } } } else { for (int i = 0; i < SQLList.Count; i++)//先做深度循环 { DataTable dtValue = new DataTable(); string SQLque = "RecordTime"; dtValue = MyDataTable.getDataTable(SQLName, Convert.ToInt32(SQLList[i]), SQLstr, SQLque, mycon); float e = Convert.ToInt32(SQLList[i].ToString()) - wellzero; hn[i] = e + "m"; PointPairList list1 = new PointPairList(); for (int j = 0; j < dtValue.Rows.Count; j++) { int bili = 1; if (dtValue.Rows.Count > 1000) { bili = dtValue.Rows.Count / 500; } if (j % bili == 0) { double x = (double)new XDate((DateTime)dtValue.Rows[j]["RecordTime"]); // string a = dt.Rows[j]["RecordTime"].ToString(); double y = double.Parse(dtValue.Rows[j]["TM"].ToString()); list1.Add(x, y); } } if (list1.Count == 0)//如果曲线没有数据 { messageError += "深度" + SQLList[i] + "m无数据\n"; continue; } else { Color co = ZedGraphClass.GetColor(i); LineItem _lineitem2 = gp.AddCurve(hn[i], list1, co, SymbolType.Circle); _lineitem2.Line.Width = 2.0F;//线的宽度 string la = _lineitem2.Label.Text.ToString(); //节点设置 if (drawAttribute.Linenum == 2) { _lineitem2.Line.IsVisible = false; } _lineitem2.Symbol.Size = 2.4F; //线上节点的大小 _lineitem2.Symbol.Fill = new Fill(co); //线上节点的颜色 gp.AxisChange(); MainForm.getInstance().GDep.Refresh(); } } } } else { //MessageBox.Show("深度输入不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("请填写深度!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { //MessageBox.Show("所选时间区间内没有数据,请更改时间区域!"); //没有表 MessageBox.Show("所选时间区间内没有数据,请更改时间区域!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (messageError != null) { MessageBox.Show("以下深度点无数据!\n" + messageError, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("时间区间选择不正确,请修改!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } MainForm.getInstance().groupBox1.Enabled = true; MainForm.getInstance().GDep.Enabled = true; mycon.Close(); mycon.Dispose(); SQLstr = null; }
//private static void zedGraphControl1_MouseMove(object sender, MouseEventArgs e)//鼠标移动出现虚线 //{ // using (Graphics gc = MainForm.getInstance().GratReal.CreateGraphics()) // using (Pen pen = new Pen(Color.Gray)) // { // pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; // RectangleF rect = MainForm.getInstance().GratReal.GraphPane.Chart.Rect; // //确保在画图区域 // if (rect.Contains(e.Location)) // { // MainForm.getInstance().GratReal.Refresh(); // gc.DrawLine(pen, e.X, rect.Top, e.X, rect.Bottom); // gc.DrawLine(pen, rect.Left, e.Y, rect.Right, e.Y); // } // } //} public static void drawRealGrat(List <DataTable> dt) { int Linenumber = Convert.ToInt32(MainForm.getInstance().GratLineNumber.Text); float wellzero = ZedGraphClass.getWellZero(); //if (dt.Count <= Linenumber) //{ // //画图 //} //else //{ // //达到11的话,删除最初的列表。并作图。 // int j = dt.Count - Linenumber; // if (j > 0) // { // for (int i = 0; i < j; i++) // { // dt.RemoveAt(0); // } // } //} ZedGraph.GraphPane gp = MainForm.getInstance().GratReal.GraphPane; MainForm.getInstance().GratReal.PointValueEvent += new ZedGraphControl.PointValueHandler(ZedGraphClass.MyPointValueHandlerTime);//设置节点信息显示样式 //MainForm.getInstance().GratReal.IsShowHScrollBar = true;//横向滚动条 //MainForm.getInstance().GratReal.MouseMove += zedGraphControl1_MouseMove;//鼠标在图上移动出现x虚线 MainForm.getInstance().GratReal.IsShowPointValues = true; // MainForm.getInstance().GratReal.IsZoomOnMouseCenter = false; //使用滚轮时以鼠标所在点进行缩放还是以图形中心进行缩放。 gp.GraphObjList.Clear(); gp.CurveList.Clear(); int k = 0; if (dt.Count - Linenumber < 0) { } else { k = dt.Count - Linenumber; } for (int i = k; i < dt.Count; i++)//从第几条线开始,到结束 { DataTable table = dt[i]; string Linename = table.Rows[0][0].ToString(); PointPairList list1 = new PointPairList(); for (int j = 0; j < table.Rows.Count; j++) { double x; float y; x = float.Parse(table.Rows[j]["fb"].ToString()) - wellzero; y = float.Parse(table.Rows[j]["fc"].ToString()); list1.Add(x, y); } if (list1.Count == 0)//如果曲线没有数据 { //MessageBox.Show("曲线不存在"); continue; } else { Color co = ZedGraphClass.GetColor(i); LineItem _lineitem2 = gp.AddCurve(Linename, list1, ZedGraphClass.GetColor(i), SymbolType.Circle); _lineitem2.Line.Width = 2.0F; //线的宽度 string la = _lineitem2.Label.Text.ToString(); _lineitem2.Symbol.Size = 2.4F; //线上节点的大小 _lineitem2.Symbol.Fill = new Fill(co); //线上节点的颜色 gp.AxisChange(); } } MainForm.getInstance().GratReal.Refresh(); }
public static System.Data.DataTable getDepcdsql(MySqlConnection mycon)//的到菜单导出SQL { //获取井深 float wellzero = ZedGraphClass.getWellZero(); DataTable dtValue = new DataTable(); System.Data.DataTable dt = new DataTable(); string SQLstr = null; //获取部分SQL语句 string strSql = null; //获取全部的SQL if (MainForm.getInstance().tabControl1.SelectedIndex == 0) //如果是DTSDep页面 { string DsingleDepth = MainForm.getInstance().DsingleDepth.Text; DateTime DintervalTime1 = MainForm.getInstance().DintervalTime1.Value; DateTime DintervalTime2 = MainForm.getInstance().DintervalTime2.Value; DataTable tableName = drawingDTSDep.getTNameTable(DintervalTime1, DintervalTime2);//获取需要使用的表名称 SQLstr = drawingDTSDep.getSQLstr(); if (SQLstr != null) { ArrayList h = MyDataTable.getDepth(wellzero, DsingleDepth); string DepString; if (h.Count != 0) { DepString = "\'" + h[0].ToString() + "\'"; for (int i = 1; i < h.Count; i++) { DepString = DepString + ",\'" + h[i].ToString() + "\'"; } for (int j = 0; j < tableName.Rows.Count; j++) { strSql = null; strSql = "SELECT Depth,RecordTime,TM from " + tableName.Rows[j][0] + " " + SQLstr + " and Depth in (" + DepString + ") ORDER BY RecordTime"; dt = getDataTable(strSql, mycon); dtValue.Merge(dt); } return(dtValue); } else { return(dtValue); } } else { return(null); } } else if (MainForm.getInstance().tabControl1.SelectedIndex == 1)//如果是DTSTime页面 { SQLstr = drawingzgcTime.getstrT(wellzero); if (SQLstr != null) { DataTable SQLTableTime = drawingzgcTime.getTime(mycon); if (SQLTableTime.Rows.Count != 0) { for (int i = 0; i < SQLTableTime.Rows.Count; i++) { strSql = null; strSql = "SELECT Depth,RecordTime,TM from " + SQLTableTime.Rows[i]["folderTable"] + " " + SQLstr + " and RecordTime = '" + SQLTableTime.Rows[i]["folderTime"] + "'ORDER BY RecordTime"; dt = getDataTable(strSql, mycon); dtValue.Merge(dt); } return(dtValue); } else { return(null); } } else { return(null); } } else if (MainForm.getInstance().tabControl1.SelectedIndex == 2)//如果是DTSTime页面 { string GratDepth = MainForm.getInstance().textBox3.Text; DateTime GratDepTime1 = MainForm.getInstance().GratDepTime1.Value; DateTime GratDepTime2 = MainForm.getInstance().GratDepTime2.Value; DataTable tableName = drawingGDep.getTNameTable(GratDepTime1, GratDepTime2); //获取需要使用的表名称 SQLstr = drawingGDep.getstr(); //获取str if (SQLstr != null) { ArrayList h = MyDataTable.getDepth(wellzero, GratDepth); h = getNewDepth(h); // string str1 = null, Strnum = null; string DepString; if (h.Count != 0) { DepString = "\'" + h[0].ToString() + "\'"; for (int i = 1; i < h.Count; i++) { DepString = DepString + ",\'" + h[i].ToString() + "\'"; } // str1 = str + " and Depth in (" + DepString + ")"; for (int j = 0; j < tableName.Rows.Count; j++) { strSql = null; strSql = "SELECT Depth,RecordTime,TM from " + tableName.Rows[j][0] + " " + SQLstr + " and Depth in (" + DepString + ") ORDER BY RecordTime"; dt = getDataTable(strSql, mycon); dtValue.Merge(dt); } return(dtValue); } else { return(null); } } else { return(null); } } else if (MainForm.getInstance().tabControl1.SelectedIndex == 3)//如果是DTSTime页面 { DataTable SQLTableTime = drawingGTime.getGTime(mycon); if (SQLTableTime.Rows.Count != 0) { for (int i = 0; i < SQLTableTime.Rows.Count; i++) { strSql = null; strSql = "SELECT Depth,RecordTime,TM from " + SQLTableTime.Rows[i]["folderTable"] + " where RecordTime = '" + SQLTableTime.Rows[i]["folderTime"] + "'ORDER BY RecordTime"; dt = getDataTable(strSql, mycon); dtValue.Merge(dt); } return(dtValue); } else { return(null); } } else { //MessageBox.Show("此图形数据无导出功能"); return(dtValue); } }
public static void DrawingGratTime()//画深度温度曲线 { float wellzero = ZedGraphClass.getWellZero(); MainForm.getInstance().groupBox4.Enabled = false; MainForm.getInstance().GTime.Enabled = false; MySqlConnection mycon = new MySqlConnection(); mycon = getMycon(); string button = MainForm.getInstance().number.Text; //ArrayList h2 = getGTime(mycon);//获取表名称列表 DataTable SQLTableTime = getGTime(mycon); //获取时间值 if (SQLTableTime.Rows.Count < 15 && SQLTableTime.Rows.Count > 0) //15条线之内 { ZedGraph.GraphPane gp = MainForm.getInstance().GTime.GraphPane; gp.GraphObjList.Clear(); gp.CurveList.Clear(); //清除上一步画的图 if (MainForm.getInstance().label1.Text == "1") { MainForm.getInstance().GTime.IsEnableVZoom = true; //Y轴缩放 MainForm.getInstance().GTime.IsEnableHZoom = true; //x轴缩放 } else { MainForm.getInstance().GTime.IsEnableVZoom = false; //禁止Y轴缩放 MainForm.getInstance().GTime.IsEnableHZoom = true; //x轴缩放 } MainForm.getInstance().GTime.PointValueEvent += new ZedGraphControl.PointValueHandler(ZedGraphClass.MyPointValueHandlerTime); //设置节点信息显示样式 //MainForm.getInstance().GTime.IsShowHScrollBar = true;//横向滚动条 MainForm.getInstance().GTime.MouseMove += zedGraphControl1_MouseMove; //鼠标在图上移动出现x虚线 MainForm.getInstance().GTime.IsShowPointValues = true; // MainForm.getInstance().GTime.IsZoomOnMouseCenter = false; //使用滚轮时以鼠标所在点进行缩放还是以图形中心进行缩放。 //设置XY轴的起始点 if (MainForm.getInstance().GratDepTM3.Text != "" && MainForm.getInstance().GratDepTM4.Text != "") { gp.YAxis.Scale.Min = float.Parse(MainForm.getInstance().GratDepTM3.Text); gp.YAxis.Scale.Max = float.Parse(MainForm.getInstance().GratDepTM4.Text); } else { gp.YAxis.Scale.MaxAuto = true; gp.YAxis.Scale.MinAuto = true; } MainForm.getInstance().GTime.IsAutoScrollRange = false; //ZedGraphClass.stile(gp);//在程序打开时已经加载过了 //坐标轴标题格式 // gp.Title.Text = "LD27-2平台 A22H井 温度深度曲线"; //图表轴名称 //gp.XAxis.Title.Text = "深度"; //X轴名称; //gp.YAxis.Title.Text = "温度"; //Y轴名称 string[] hn = new string[SQLTableTime.Rows.Count]; //图例名称 if (button == "two") //循环生成 { for (int k = 0; k < 4; k++) //循环四次结束循环 { gp.GraphObjList.Clear(); gp.CurveList.Clear(); for (int i = 0; i < SQLTableTime.Rows.Count; i++) { //清除上一步画的图 System.Threading.Thread.Sleep(1500); string Str = null; DataTable dtValue = new DataTable(); Str = "SELECT Depth,RecordTime,TM from " + SQLTableTime.Rows[i]["folderTable"] + " where RecordTime=\'" + Convert.ToDateTime(SQLTableTime.Rows[i]["folderTime"]) + "\' ORDER BY Depth"; // str3 = "SELECT COUNT(*) from " + tableName.Rows[j][0] + " WHERE RecordTime between \'" + DintervalTime1 + "\' AND \'" + DintervalTime2 + "\'"; dtValue = getDataTable(Str, mycon); hn[i] = SQLTableTime.Rows[i]["folderTime"].ToString(); PointPairList list1 = new PointPairList(); for (int j = 0; j < dtValue.Rows.Count; j++) { double x; float y; if (num == 1) { x = float.Parse(dtValue.Rows[j]["TM"].ToString()); y = float.Parse(dtValue.Rows[j]["Depth"].ToString()) - wellzero; } else { x = float.Parse(dtValue.Rows[j]["Depth"].ToString()) - wellzero; y = float.Parse(dtValue.Rows[j]["TM"].ToString()); } list1.Add(x, y); } if (list1.Count == 0 && k == 0) //如果曲线没有数据 { messageError += "时间" + (MainForm.getInstance().TimeList.Items[i]).ToString() + "无数据\n"; continue; } else { Color co = ZedGraphClass.GetColor(i); LineItem _lineitem2 = gp.AddCurve(hn[i], list1, ZedGraphClass.GetColor(i), SymbolType.Circle); _lineitem2.Line.Width = 2.0F; //线的宽度 _lineitem2.Symbol.Size = 2.4F; //线上节点的大小 if (drawAttribute.Linenum == 2) { _lineitem2.Line.IsVisible = false; } _lineitem2.Symbol.Fill = new Fill(co); //线上节点的颜色 gp.AxisChange(); MainForm.getInstance().GTime.Refresh(); } } } } else //生成 { for (int i = 0; i < SQLTableTime.Rows.Count; i++) { string Str = null; DataTable dtValue = new DataTable(); Str = "SELECT Depth,RecordTime,TM from " + SQLTableTime.Rows[i]["folderTable"] + " where RecordTime=\'" + Convert.ToDateTime(SQLTableTime.Rows[i]["folderTime"]) + "\' ORDER BY Depth"; // str3 = "SELECT COUNT(*) from " + tableName.Rows[j][0] + " WHERE RecordTime between \'" + DintervalTime1 + "\' AND \'" + DintervalTime2 + "\'"; dtValue = getDataTable(Str, mycon); hn[i] = SQLTableTime.Rows[i]["folderTime"].ToString(); PointPairList list1 = new PointPairList(); for (int j = 0; j < dtValue.Rows.Count; j++) { double x; float y; if (num == 1) { x = float.Parse(dtValue.Rows[j]["TM"].ToString()); y = float.Parse(dtValue.Rows[j]["Depth"].ToString()) - wellzero; } else { x = float.Parse(dtValue.Rows[j]["Depth"].ToString()) - wellzero; y = float.Parse(dtValue.Rows[j]["TM"].ToString()); } list1.Add(x, y); } if (list1.Count == 0) //如果曲线没有数据 { messageError += "时间" + (MainForm.getInstance().TimeList.Items[i]).ToString() + "无数据\n"; continue; } else { Color co = ZedGraphClass.GetColor(i); LineItem _lineitem2 = gp.AddCurve(hn[i], list1, ZedGraphClass.GetColor(i), SymbolType.Circle); _lineitem2.Line.Width = 2.0F; //线的宽度 //string la = _lineitem2.Label.Text.ToString(); if (drawAttribute.Linenum == 2) { _lineitem2.Line.IsVisible = false; } _lineitem2.Symbol.Size = 2.4F; //线上节点的大小 _lineitem2.Symbol.Fill = new Fill(co); //线上节点的颜色 gp.AxisChange(); MainForm.getInstance().GTime.Refresh(); } } } } else if (SQLTableTime.Rows.Count > 15) { MessageBox.Show("时间区间太大,曲线条数大于15"); } else { if (messageError == null) { MessageBox.Show("没有添加时间点!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } MainForm.getInstance().groupBox4.Enabled = true; MainForm.getInstance().GTime.Enabled = true; mycon.Close(); if (messageError != null) { MessageBox.Show("以下时间点无数据!\n" + messageError, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }