private void button3_Click(object sender, EventArgs e) //工作面来压情况保存预览 { string date = year + "-" + month + "-" + day; string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; //插入或更新来压情况 string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[工作面来压情况] WHERE [日期] = '{0}' AND [工作面] = N'{1}') BEGIN INSERT INTO [UPRESSURE].[dbo].[工作面来压情况]([日期], [工作面], [已来压次数],[上次位置], [上次时间],[步距], [本次来压情况],[持续距离], [预计下次时间],[预计下次位置], [预计下次步距],[下一危险区域名称], [距离危险区域]) VALUES('{0}', N'{1}', '{2}', '{3}', N'{4}', '{5}', N'{6}', '{7}', N'{8}', '{9}', '{10}', N'{11}', '{12}') END ELSE BEGIN UPDATE [UPRESSURE].[dbo].[工作面来压情况] SET [已来压次数] = '{2}', [上次位置] = '{3}', [上次时间] = N'{4}', [步距] = '{5}', [本次来压情况] = N'{6}', [持续距离] = '{7}', [预计下次时间] = N'{8}', [预计下次位置] = '{9}', [预计下次步距] = '{10}', [下一危险区域名称] = N'{11}', [距离危险区域] = '{12}' WHERE [日期] = '{0}' AND [工作面] = N'{1}' END", date, working_face, (textBox21.Text == "") ? 0 : Convert.ToInt32(textBox21.Text), //已来压次数 (textBox20.Text == "") ? 0.0 : Convert.ToDouble(textBox20.Text), //上次位置 (textBox19.Text == "") ? "无" : textBox19.Text, //上次时间 (textBox18.Text == "") ? 0.0 : Convert.ToDouble(textBox18.Text), //步距 (textBox17.Text == "") ? "无" : textBox17.Text, //本次来压情况 (textBox16.Text == "") ? 0.0 : Convert.ToDouble(textBox16.Text), //持续距离 (textBox26.Text == "") ? "无" : textBox26.Text, //预计下次时间 (textBox24.Text == "") ? 0.0 : Convert.ToDouble(textBox24.Text), //预计下次位置 (textBox22.Text == "") ? 0.0 : Convert.ToDouble(textBox22.Text), //预计下次步距 (textBox25.Text == "") ? "无" : textBox25.Text, //下一危险区域名称 (textBox23.Text == "") ? 0.0 : Convert.ToDouble(textBox23.Text)); //距离危险区域 using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); MessageBox.Show("完成"); } } }
private void button6_Click(object sender, EventArgs e) //应力在线保存预览 { string date_t = year + "-" + month + "-" + day; string date_y = year1 + "-" + month1 + "-" + day1; gt.setToday(date_t); gt.setYesToday(date_y); gt.setWorkFace(working_face); string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[地表沉降数据] WHERE [日期] = '{0}') BEGIN INSERT INTO [UPRESSURE].[dbo].[地表沉降数据]([日期], [观察日期], [最大沉降量], [平均沉降量], [最大沉降位置]) VALUES('{0}', N'{1}', N'{2}', N'{3}', N'{4}') END ELSE BEGIN UPDATE [UPRESSURE].[dbo].[地表沉降数据] SET [观察日期] = N'{1}', [最大沉降量] = N'{2}', [平均沉降量] = N'{3}', [最大沉降位置] = N'{4}' WHERE [日期] = '{0}' END", date_t, (textBox7.Text == "") ? null : textBox7.Text, (textBox8.Text == "") ? null : textBox8.Text, (textBox9.Text == "") ? null : textBox9.Text, (textBox10.Text == "") ? null : textBox10.Text ); using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); Properties.Settings.Default.Save(); MessageBox.Show("完成"); StressTest st = new StressTest(working_face); st.Start(gt); MessageBox.Show("应力监测ok"); } } }
private void button7_Click(object sender, EventArgs e) //现场显现记录保存预览 { string date = year + "-" + month + "-" + day; string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[现场显现记录] WHERE [日期] = '{0}') BEGIN INSERT INTO [UPRESSURE].[dbo].[现场显现记录]([日期], [现场记录], [微震对应], [具体对应位置], [现场详细描述], [分析说明]) VALUES('{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}') END ELSE BEGIN UPDATE [UPRESSURE].[dbo].[现场显现记录] SET [现场记录] = N'{1}', [微震对应] = N'{2}', [具体对应位置] = N'{3}', [现场详细描述] = N'{4}', [分析说明] = N'{5}' WHERE [日期] = '{0}' END", date, (textBox11.Text == "") ? null : textBox11.Text, (textBox27.Text == "") ? null : textBox27.Text, (textBox12.Text == "") ? null : textBox12.Text, (textBox13.Text == "") ? null : textBox13.Text, (textBox14.Text == "") ? null : textBox14.Text ); using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); Properties.Settings.Default.Save(); MessageBox.Show("完成"); } } gt.setToday(date); gt.setWorkFace(working_face); new Record().Start(gt); MessageBox.Show("现场ok"); }
private void button6_Click(object sender, EventArgs e) //应力在线保存预览 { string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[地表沉降数据] WHERE [日期] = N'{0}') BEGIN INSERT INTO [UPRESSURE].[dbo].[地表沉降数据]([日期], [最大沉降量], [平均沉降量], [最大沉降位置]) VALUES(N'{0}', N'{1}', N'{2}', N'{3}') END ELSE BEGIN UPDATE [UPRESSURE].[dbo].[地表沉降数据] SET [最大沉降量] = N'{1}', [平均沉降量] = N'{2}', [最大沉降位置] = N'{3}' WHERE [日期] = N'{0}' END", (textBox7.Text == "") ? " " : textBox7.Text, (textBox8.Text == "") ? null : textBox8.Text, (textBox9.Text == "") ? null : textBox9.Text, (textBox10.Text == "") ? null : textBox10.Text ); using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); Properties.Settings.Default.Save(); MessageBox.Show("完成"); } } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; string date_t = year + "-" + month + "-" + day; string date_y = year1 + "-" + month1 + "-" + day1; gt.setToday(date_t); gt.setYesToday(date_y); gt.setWorkFace(working_face); string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[地表沉降数据] WHERE [日期] = '{0}') BEGIN INSERT INTO [UPRESSURE].[dbo].[地表沉降数据]([日期], [观察日期], [最大沉降量], [平均沉降量], [最大沉降位置]) VALUES('{0}', N'{1}', N'{2}', N'{3}', N'{4}') END ELSE BEGIN UPDATE [UPRESSURE].[dbo].[地表沉降数据] SET [观察日期] = N'{1}', [最大沉降量] = N'{2}', [平均沉降量] = N'{3}', [最大沉降位置] = N'{4}' WHERE [日期] = '{0}' END", date_t, (textBox7.Text == "") ? null : textBox7.Text, (textBox8.Text == "") ? null : textBox8.Text, (textBox9.Text == "") ? null : textBox9.Text, (textBox10.Text == "") ? null : textBox10.Text ); using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); Properties.Settings.Default.Save(); //MessageBox.Show("完成"); } } try { StressTest st = new StressTest(working_face); st.Start(gt); for (int i = 0; i < 100; i++) { Thread.Sleep(100); worker.ReportProgress(i); } MessageBox.Show("完成"); MessageBox.Show("应力监测ok"); } catch (Exception) { MessageBox.Show("应力监测数据错误"); } sign[5] = true; for (int i = 0; i < sign.Length; i++) { if (sign[i] == false) { sign_ = false; } } if (sign_ == true) { button2.Enabled = true; } sign_ = true; }
private void button8_Click(object sender, EventArgs e) //综合分析保存预览 { string date = year + "-" + month + "-" + day; string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[综合分析] WHERE [日期] = '{0}') BEGIN INSERT INTO [UPRESSURE].[dbo].[综合分析]([日期], [综合分析], [采取措施], [轨顺钻孔施工地点], [胶运钻孔施工地点], [轨顺孔深], [胶运孔深], [轨顺孔间距], [胶运孔间距], [轨顺设计个数], [胶运设计个数], [轨顺当日施工个数], [胶运当日施工个数], [轨顺剩余个数], [胶运剩余个数]) VALUES('{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}', N'{6}', N'{7}', N'{8}', N'{9}', N'{10}', N'{11}', N'{12}', N'{13}', N'{14}') END ELSE BEGIN UPDATE [UPRESSURE].[dbo].[综合分析] SET [综合分析] = N'{1}', [采取措施] = N'{2}', [轨顺钻孔施工地点] = N'{3}', [胶运钻孔施工地点] = N'{4}', [轨顺孔深] = N'{5}', [胶运孔深] = N'{6}', [轨顺孔间距] = N'{7}', [胶运孔间距] = N'{8}', [轨顺设计个数] = N'{9}', [胶运设计个数] = N'{10}', [轨顺当日施工个数] = N'{11}', [胶运当日施工个数] = N'{12}', [轨顺剩余个数] = N'{13}', [胶运剩余个数] = N'{14}' WHERE [日期] = '{0}' END", date, (textBox42.Text == "") ? null : textBox42.Text, (checkCombo1.Value == "") ? null : checkCombo1.Value, (textBox28.Text == "") ? null : textBox28.Text, (textBox29.Text == "") ? null : textBox29.Text, (textBox32.Text == "") ? null : textBox32.Text, (textBox33.Text == "") ? null : textBox33.Text, (textBox34.Text == "") ? null : textBox34.Text, (textBox35.Text == "") ? null : textBox35.Text, (textBox37.Text == "") ? null : textBox37.Text, (textBox36.Text == "") ? null : textBox36.Text, (textBox39.Text == "") ? null : textBox39.Text, (textBox38.Text == "") ? null : textBox38.Text, (textBox41.Text == "") ? null : textBox41.Text, (textBox40.Text == "") ? null : textBox40.Text ); using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); Properties.Settings.Default.Save(); MessageBox.Show("完成"); } } gt.setToday(date); gt.setWorkFace(working_face); try { ch.Start(gt); MessageBox.Show("ojbk!!!"); } catch (Exception) { throw; } sign[7] = true; for (int i = 0; i < sign.Length; i++) { if (sign[i] == false) { sign_ = false; } } if (sign_ == true) { button2.Enabled = true; } sign_ = true; }
private void button3_Click(object sender, EventArgs e) //工作面来压情况保存预览 { string date = year + "-" + month + "-" + day; string date_y = year1 + "-" + month1 + "-" + day1; string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; //插入或更新来压情况 string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[工作面来压情况] WHERE [日期] = '{0}' AND [工作面] = N'{1}') BEGIN INSERT INTO [UPRESSURE].[dbo].[工作面来压情况]([日期], [工作面], [已来压次数],[上次位置], [上次时间],[步距], [本次来压情况],[持续距离], [预计下次时间],[预计下次位置], [预计下次步距],[下一危险区域名称], [距离危险区域]) VALUES('{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}', N'{6}', N'{7}', N'{8}', N'{9}', N'{10}', N'{11}', N'{12}') END ELSE BEGIN UPDATE [UPRESSURE].[dbo].[工作面来压情况] SET [已来压次数] = N'{2}', [上次位置] = N'{3}', [上次时间] = N'{4}', [步距] = N'{5}', [本次来压情况] = N'{6}', [持续距离] = N'{7}', [预计下次时间] = N'{8}', [预计下次位置] = N'{9}', [预计下次步距] = N'{10}', [下一危险区域名称] = N'{11}', [距离危险区域] = N'{12}' WHERE [日期] = '{0}' AND [工作面] = N'{1}' END", date, working_face, (textBox21.Text == "") ? null : textBox21.Text, //已来压次数 (textBox20.Text == "") ? null : textBox20.Text, //上次位置 (textBox19.Text == "") ? null : textBox19.Text, //上次时间 (textBox18.Text == "") ? null : textBox18.Text, //步距 (textBox17.Text == "") ? null : textBox17.Text, //本次来压情况 (textBox16.Text == "") ? null : textBox16.Text, //持续距离 (textBox26.Text == "") ? null : textBox26.Text, //预计下次时间 (textBox24.Text == "") ? null : textBox24.Text, //预计下次位置 (textBox22.Text == "") ? null : textBox22.Text, //预计下次步距 (textBox25.Text == "") ? null : textBox25.Text, //下一危险区域名称 (textBox23.Text == "") ? null : textBox23.Text //距离危险区域 ); using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); MessageBox.Show("完成"); } } gt.setToday(date); gt.setYesToday(date_y); gt.setWorkFace(working_face); try { wfw.Start(gt); MessageBox.Show("来压ok"); } catch (Exception) { throw; } sign[1] = true; for (int i = 0; i < sign.Length; i++) { if (sign[i] == false) { sign_ = false; } } if (sign_ == true) { button2.Enabled = true; } sign_ = true; }
private void button1_Click(object sender, EventArgs e) //基本信息保存预览 { string date = year + "-" + month + "-" + day; string date_y = year1 + "-" + month1 + "-" + day1; string constr = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; //插入主键时间+工作面 string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[基本数据表] WHERE [日期] = '{0}' AND [工作面] = N'{1}') BEGIN INSERT INTO [UPRESSURE].[dbo].[基本数据表]([日期], [工作面]) VALUES('{0}', N'{1}') END", date, working_face); //寻找插入数据的上一条数据 string sqlString_find = string.Format(@"SELECT TOP 1 * FROM [UPRESSURE].[dbo].[基本数据表] WHERE [工作面] LIKE N'{0}' AND [日期] < '{1}' ORDER BY [日期] DESC", working_face, date); using (SqlConnection sqlConnection = new SqlConnection(constr)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); DataTable datatable = new DataTable(); SqlCommand cmd_find = new SqlCommand(sqlString_find, sqlConnection); using (SqlDataAdapter da = new SqlDataAdapter(cmd_find)) { da.Fill(datatable); } //上一条记录进尺 double auxiliary_y = Convert.ToDouble(datatable.Rows[0][2].ToString()); double rubber_y = Convert.ToDouble(datatable.Rows[0][3].ToString()); //总进尺 auxiliary = (textBox1.Text == "") ? auxiliary_y : Convert.ToDouble(textBox1.Text); //辅 rubber = (textBox2.Text == "") ? rubber_y : Convert.ToDouble(textBox2.Text); //胶 double transport_avg = Math.Round((auxiliary + rubber) / 2, 1); //当日进尺 double auxiliary_td = Math.Round(auxiliary - auxiliary_y, 1); double rubber_td = Math.Round(rubber - rubber_y, 1); double transport_td_avg = Math.Round((auxiliary_td + rubber_td) / 2, 1); //涌水量 double water = (textBox3.Text == "") ? 0.0 : Convert.ToDouble(textBox3.Text); //DataRow dr = datatable.NewRow(); //object[] objs = { date, working_face, auxiliary, rubber, transport_avg, auxiliary_td, rubber_td, transport_td_avg, water, textBox4.Text, textBox5.Text, textBox6.Text, (2077 - transport_avg), textBox15.Text }; //dr.ItemArray = objs; //datatable.Rows.Add(dr); //datatable写入数据库 string sqlString_insdata = string.Format(@"UPDATE [UPRESSURE].[dbo].[基本数据表] SET [辅运顺槽总进尺] = '{0}', [胶运顺槽总进尺] = '{1}', [总进尺平均] = '{2}', [辅运当日进尺] = '{3}', [胶运当日进尺] = '{4}', [当日平均] = '{5}', [工作面涌水量] = '{6}', [初采时间] = N'{7}', [实测倾斜长度] = '{8}', [平均采高] = '{9}', [剩余推进长度] = '{10}', [时空关系] = N'{11}' WHERE [日期] = '{12}' AND [工作面] = N'{13}'", auxiliary, rubber, transport_avg, auxiliary_td, rubber_td, transport_td_avg, water, textBox4.Text, textBox5.Text, textBox6.Text, (2077 - transport_avg), textBox15.Text, date, working_face); SqlCommand cmd_insdata = new SqlCommand(sqlString_insdata, sqlConnection); cmd_insdata.ExecuteNonQuery(); Properties.Settings.Default.Save(); } } //charu gt.setToday(date); gt.setYesToday(date_y); gt.setWorkFace(working_face); try { bdt.Start(gt); MessageBox.Show("基本数据完成"); } catch (Exception) { MessageBox.Show("基本数据异常"); throw; } sign[0] = true; for (int i = 0; i < sign.Length; i++) { if (sign[i] == false) { sign_ = false; } } if (sign_ == true) { button2.Enabled = true; } sign_ = true; }
private void comboBox18_SelectedIndexChanged(object sender, EventArgs e) //钻屑法类型选择 { if (MessageBox.Show("是否已经输完" + type + "数据", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (comboBox2.Text != "") { loaddata(); } //loaddata(); string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; //string constr = "server=.;database=UPRESSURE;uid=sa;pwd=sdkjdx"; string date = year + "-" + month + "-" + day; if (tab == 1) { using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { for (int i = 0; i < count; i++) { string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[钻屑法数据表] WHERE [日期] = '{0}' AND [钻孔编号] = '{1}'AND [胶运] = '{21}') BEGIN INSERT INTO [UPRESSURE].[dbo].[钻屑法数据表]([日期], [钻孔编号], [1m], [2m], [3m], [4m], [5m], [6m], [7m], [8m], [9m], [10m], [11m], [12m], [13m], [14m], [15m], [距工作面距离], [单孔最大值], [最大孔深], [单孔平均], [胶运]) VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}' ) END ELSE BEGIN UPDATE [UPRESSURE].[dbo].[钻屑法数据表] SET [1m] = '{2}', [2m] = '{3}',[3m] = '{4}',[4m] = '{5}',[5m] = '{6}', [6m] = '{7}',[7m] = '{8}',[8m] = '{9}',[9m] = '{10}',[10m] = '{11}', [11m] = '{12}',[12m] = '{13}',[13m] = '{14}',[14m] = '{15}',[15m] = '{16}', [距工作面距离] = '{17}', [单孔最大值] = '{18}', [最大孔深] = '{19}', [单孔平均] = '{20}' WHERE [日期] = '{0}' AND [钻孔编号] = '{1}' AND [胶运] = '{21}' END", date, i + 1, data[0, i], data[1, i], data[2, i], data[3, i], data[4, i], data[5, i], data[6, i], data[7, i], data[8, i], data[9, i], data[10, i], data[11, i], data[12, i], data[13, i], data[14, i], data[15, i], data[16, i], data[17, i], data[18, i], data[19, i]); SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); } } } Array.Clear(data, 0, data.Length); count = 1; label38.Text = count.ToString() + "号钻孔"; MessageBox.Show("完成"); } } else { comboBox18.Text = type; } }
private void button4_Click(object sender, EventArgs e) //钻屑法保存预览按钮 { Format format = new Format(); string date = year + "-" + month + "-" + day; string date_y = year1 + "-" + month1 + "-" + day1; gt.setToday(date); gt.setYesToday(date_y); gt.setWorkFace(working_face); string filename = string.Format("{0}工作面钻屑监测统计表{1}年{2}月.xlsx", working_face, year, month); string headline = string.Format("{0}月{1}日轨顺槽钻屑监测统计表", month, day); string headline1 = string.Format("{0}月{1}日运顺槽钻屑监测统计表", month, day); string path = @"F:\" + filename; string test = @"F:\钻屑监测统计表模板_test.xlsx"; if (comboBox2.Text != "") { loaddata(); count++; label38.Text = count.ToString() + "号钻孔"; } string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; string constr = "server=192.168.1.111;database=UPRESSURE;uid=sa;pwd=sdkjdx"; if (tab == 1) { using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { for (int i = 0; i < count - 1; i++) { string sqlString_ins = string.Format(@"IF NOT EXISTS(SELECT 1 FROM [UPRESSURE].[dbo].[钻屑法数据表] WHERE [日期] = '{0}' AND [钻孔编号] = '{1}'AND [胶运] = '{21}') BEGIN INSERT INTO [UPRESSURE].[dbo].[钻屑法数据表]([日期], [钻孔编号], [1m], [2m], [3m], [4m], [5m], [6m], [7m], [8m], [9m], [10m], [11m], [12m], [13m], [14m], [15m], [距工作面距离], [单孔最大值], [最大孔深], [单孔平均], [胶运]) VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}' ) END ELSE BEGIN UPDATE [UPRESSURE].[dbo].[钻屑法数据表] SET [1m] = '{2}', [2m] = '{3}',[3m] = '{4}',[4m] = '{5}',[5m] = '{6}', [6m] = '{7}',[7m] = '{8}',[8m] = '{9}',[9m] = '{10}',[10m] = '{11}', [11m] = '{12}',[12m] = '{13}',[13m] = '{14}',[14m] = '{15}',[15m] = '{16}', [距工作面距离] = '{17}', [单孔最大值] = '{18}', [最大孔深] = '{19}', [单孔平均] = '{20}' WHERE [日期] = '{0}' AND [钻孔编号] = '{1}' AND [胶运] = '{21}' END", date, i + 1, data[0, i], data[1, i], data[2, i], data[3, i], data[4, i], data[5, i], data[6, i], data[7, i], data[8, i], data[9, i], data[10, i], data[11, i], data[12, i], data[13, i], data[14, i], data[15, i], data[16, i], data[17, i], data[18, i], data[19, i]); SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); } MessageBox.Show("完成"); count = 1; label38.Text = count.ToString() + "号钻孔"; } } } try { //调用钻屑法按钮 dt.Start(gt); MessageBox.Show("钻屑法ok"); } catch (Exception) { MessageBox.Show("钻屑法错误 请重新检查数据"); throw; } sign[3] = true; for (int i = 0; i < sign.Length; i++) { if (sign[i] == false) { sign_ = false; } } if (sign_ == true) { button2.Enabled = true; } sign_ = true; }
private void button4_Click(object sender, EventArgs e) //钻屑法保存预览按钮 { Format format = new Format(); string filename = string.Format("{0}工作面钻屑监测统计表{1}年{2}月.xlsx", working_face, year, month); string headline = string.Format("{0}月{1}日轨顺槽钻屑监测统计表", month, day); string headline1 = string.Format("{0}月{1}日运顺槽钻屑监测统计表", month, day); string path = @"F:\" + filename; string test = @"F:\钻屑监测统计表模板_test.xlsx"; loaddata(); if (data[0, count - 1] != 0) { count++; } //生成添加钻屑监测统计表 if (!File.Exists(path)) { data_test[0] = 1.6; data_test[1] = 3.2; string a = data_test[3].ToString(); MessageBox.Show(a); } else { Workbook workbook1 = new Workbook(test); Worksheet DetailSheet = workbook1.Worksheets[0]; Cells cells = DetailSheet.Cells; cells.Merge(0, 2, 2, count - 1); cells[0, 2].PutValue(headline);//填写标题 cells[0, 2].SetStyle(format.Titlestyle(workbook1)); for (int i = 1; i < count; i++)//填写钻孔编号 { cells[2, i + 1].PutValue(i); cells[2, i + 1].SetStyle(format.Titlestyle(workbook1)); } for (int i = 0; i < 15; i++) { for (int j = 0; j < list_ComboBox.Count() + 4; j++) { if (data[j, i] == 0) { continue; } else { switch (data[j, i].ToString()) { case "-1": cells[3 + j, 2 + i].PutValue("吸钻"); cells[3 + j, 2 + i].SetStyle(format.Titlestyle(workbook1)); break; case "-2": cells[3 + j, 2 + i].PutValue("卡钻"); cells[3 + j, 2 + i].SetStyle(format.Titlestyle(workbook1)); break; case "-3": cells[3 + j, 2 + i].PutValue("煤炮"); cells[3 + j, 2 + i].SetStyle(format.Titlestyle(workbook1)); break; case "-4": cells[3 + j, 2 + i].PutValue("卡钻吸钻"); cells[3 + j, 2 + i].SetStyle(format.Titlestyle(workbook1)); break; default: cells[3 + j, 2 + i].PutValue(data[j, i]); cells[3 + j, 2 + i].SetStyle(format.Titlestyle(workbook1)); break; } } } } try { workbook1.Save(@"F:\Hello_test.xlsx"); MessageBox.Show("完成"); } catch { MessageBox.Show("该文件已打开,请关闭文件后再点击“完成预览”"); } } string constr_test = "server=.;database=UPRESSURE;uid=sa;pwd=sakjdx"; string constr = "server=192.168.1.111;database=UPRESSURE;uid=sa;pwd=sdkjdx"; string sqlString_ins = ""; using (SqlConnection sqlConnection = new SqlConnection(constr_test)) { bool conok = SqlExtensions.QuickOpen(sqlConnection, 5000); //连接到数据库 if (conok) { SqlCommand cmd_ins = new SqlCommand(sqlString_ins, sqlConnection); cmd_ins.ExecuteNonQuery(); MessageBox.Show("完成"); } } }