/// <summary> /// 删除 /// </summary> private void Delete() { int index = 0; if (dgvImageRecord.SelectedRows.Count < 1) { MessageBox.Show("请选择至少一行进行删除"); return; } string sum = dgvImageRecord.SelectedRows[0].Cells["ImageRecord_Id"].Value.ToString(); for (int i = 0; i < this.dgvImageRecord.SelectedRows.Count; i++) { string SqlDelete = "delete ImageRecord where ImageRecord_Id=" + dgvImageRecord.SelectedRows[i].Cells["ImageRecord_Id"].Value.ToString(); int num = LinQBaseDao.ExecuteSql(SqlDelete); if (num > 0) { index++; } } if (index > 0) { MessageBox.Show("删除成功"); LoadData(""); } else { MessageBox.Show("删除失败"); } }
/// <summary> /// 新增修改数据的日志记录 /// </summary> /// <param name="operateContent">操作内容</param> public static void AddUpdateLog(string operateContent) { string operateUser = common.NAME; string operateTime = CommonalityEntity.GetServersTime().ToString(); string operateIP = ""; string sqlLog = string.Format("insert into eh_Operate(Operate_Content,Operate_User,Operate_Time,Operate_IP) values('{0}','{1}','{2}','{3}')", operateContent, operateUser, operateTime, operateIP); LinQBaseDao.ExecuteSql(sqlLog); }
/// <summary> /// 将Excel中的数据导入到SQL数据库中 /// </summary> /// <param name="fileName">文件名称(带后缀名)</param> /// <param name="tableName">表名</param> /// <param name="path">路径</param> private void setExcelout(string fileName, string tableName, string path) { string Countname = null; DataTable tableCountName = LinQBaseDao.Query("select name from Syscolumns where id=Object_id('" + tableName + "')").Tables[0]; for (int i = 0; i < tableCountName.Rows.Count; i++) { if (i >= 1) { Countname += "," + tableCountName.Rows[i][0].ToString(); } if (i == 0) { Countname += tableCountName.Rows[i][0].ToString(); } } DataTable table = new DataTable(); OleDbConnection dbcon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + fileName + ";Extended Properties=Excel 8.0"); if (dbcon.State == ConnectionState.Closed) { dbcon.Open(); LinQBaseDao.Query("truncate table " + tableName); } string sql = "select * from [" + tableName + "$]"; OleDbCommand cmd = new OleDbCommand(sql, dbcon); OleDbDataReader sdr = cmd.ExecuteReader(); table.Load(sdr); string strInsertComm; for (int i = 0; i < table.Rows.Count; i++) { strInsertComm = ""; strInsertComm = "set identity_insert " + tableName + " on ; Insert INTO " + tableName + "(" + Countname + ")"; strInsertComm += " values("; for (int j = 0; j < table.Columns.Count; j++) { if (j >= 1) { strInsertComm += ",'" + table.Rows[i][j].ToString().Trim() + "'"; } else { strInsertComm += "'" + table.Rows[i][j].ToString().Trim() + "'"; } } strInsertComm += ") ;set identity_insert " + tableName + " off;"; LinQBaseDao.ExecuteSql(strInsertComm); } if (dbcon.State == ConnectionState.Open) { dbcon.Close(); } }
/// <summary> ///删除预置皮重信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tbtnDelUser_delete() { try { int j = 0; if (lvwPresetTare.SelectedRows.Count > 0)//选中删除 { if (MessageBox.Show("确定要删除吗?", "系统提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { //选中数量 int count = lvwPresetTare.SelectedRows.Count; string id = ""; //遍历 for (int i = 0; i < count; i++) { id = lvwPresetTare.SelectedRows[i].Cells["PresetTare_ID"].Value.ToString(); string sql = "delete PresetTare where PresetTare_ID='" + id + "'"; try { j = j + LinQBaseDao.ExecuteSql(sql); } catch { } } if (j > 0) { MessageBox.Show("成功删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else//没有选中 { MessageBox.Show("请选择要删除的行!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } string strContent = "预置皮重编号为:" + this.lvwPresetTare.SelectedRows[0].Cells["PresetTare_ID"].Value.ToString();; Common.WriteLogData("删除", "删除 " + strContent + " 的信息 ", Common.USERNAME);//添加日志 } catch (Exception ex) { Common.WriteTextLog("预置皮重管理 tbtnDelUser_delete()+" + ex.Message.ToString()); } finally { page = new PageControl(); page.PageMaxCount = tscbxPageSize2.SelectedItem.ToString(); LoadData();//更新 } }
/// <summary> /// 登记 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button4_Click(object sender, EventArgs e) { string Instrument_ID = Getclbinstrument(); try { if (this.cob_ClientName.Text != "" && this.clbInstrument_Name.Text != "" && this.cob_Collection_Name.Text != "" && Instrument_ID != "") { string sql = null; //调用判断当前采集端是否被客户端占用的方法 if (!GetCollection_id(false)) { MessageBox.Show("修改失败,该采集端已被占用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //判断当前采集端是否被客户端占用或者仪表被占用 if (GetInstrument_ID(false)) { MessageBox.Show("修改失败,该仪表已被占用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } sql = "insert into dbo.PolicyConfigurationInfo values('" + this.cob_ClientName.SelectedValue + "','" + this.cob_Collection_Name.SelectedValue + "','" + Instrument_ID + "')"; int cou = LinQBaseDao.ExecuteSql(sql); if (cou > 0) { MessageBox.Show("登记成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); string strContent = "客户端为:" + this.cob_ClientName.Text; LogInfoDAL.loginfoadd("登记", "登记" + strContent + "的策略配置的信息", Common.USERNAME);//添加日志 InstrumentList(); return; } else { MessageBox.Show("登记失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { MessageBox.Show("客户端,采集端端,仪表不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception) { } InstrumentList(); }
/// <summary> /// 删除 /// </summary> private void InstrumentYanzheng() { string sql = null; try { if (MessageBox.Show("确定删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (this.dgvInstrumentInfo.SelectedRows.Count > 0)//选中删除 { bool r = false; //选中数量 int count = dgvInstrumentInfo.SelectedRows.Count; int cou = 0; for (int i = 0; i < count; i++) { int id = Convert.ToInt32(dgvInstrumentInfo.SelectedRows[i].Cells["Instrument_ID"].Value.ToString()); sql = "delete from dbo.InstrumentInfo where Instrument_ID= " + id; //受影响的行数 if (LinQBaseDao.ExecuteSql(sql) > 0) { string strContent = ":" + dgvInstrumentInfo.SelectedRows[i].Cells["Instrument_Name"].Value.ToString(); LogInfoDAL.loginfoadd("删除", "删除" + strContent + "仪表登记的信息", Common.USERNAME);//添加日志 cou++; } } if (cou > 0) { MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); BingList(); } else { MessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("请选择要删除的行!"); } } } catch (Exception) { } }
/// <summary> /// 确认修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { //得到要修改的仪表 string Instrument_Name = Getclbinstrument(); try { if (this.cob_ClientName.Text != "" && this.clbInstrument_Name.Text != "" && this.cob_Collection_Name.Text != "") { string sql = null; //调用判断当前采集端是否被客户端占用的方法 if (!GetCollection_id(false)) { MessageBox.Show("修改失败,该采集端已被占用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //判断当前采集端是否被客户端占用或者仪表被占用 if (GetInstrument_ID(false)) { MessageBox.Show("修改失败,该仪表已被占用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //修改客户端,采集表 int id = int.Parse(cob_ClientName.Tag.ToString()); sql = "Update dbo.PolicyConfigurationInfo set PolicyConfiguration_Client_ID=" + this.cob_ClientName.SelectedValue + ",PolicyConfiguration_Collection_ID=" + this.cob_Collection_Name.SelectedValue + ", PolicyConfiguration_Instrument_ID='" + Instrument_Name + "' where PolicyConfiguration_Id=" + id; if (LinQBaseDao.ExecuteSql(sql) > 0) { MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); string strContent = "编号为:" + this.cob_ClientName.Tag; LogInfoDAL.loginfoadd("修改", "修改" + strContent + "的策略配置的信息", Common.USERNAME);//添加日志 InstrumentList(); return; } else { MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } catch (Exception) { } }
/// <summary> /// U9数据传输设置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button4_Click(object sender, EventArgs e) { bool Water = false; if (Water1.Checked) { Water = true; } else { Water = false; } string sql = "update U9Start set U9Bool='" + Water + "'where U9Name='水分检测' "; if (Weight1.Checked) { Water = true; } else { Water = false; } sql = sql + "update U9Start set U9Bool='" + Water + "'where U9Name='重量检测' "; if (inspection1.Checked) { Water = true; } else { Water = false; } sql = sql + "update U9Start set U9Bool='" + Water + "'where U9Name='一检管理' "; int count = LinQBaseDao.ExecuteSql(sql); if (count > 0) { MessageBox.Show("保存成功!"); } else { MessageBox.Show("保存失败!"); } }
/// <summary> /// 添加仪表 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnADD_Click(object sender, EventArgs e) { try { if (txtInstrument_name.Text.Trim() == "") { MessageBox.Show("登记失败!仪表不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sql = ""; DataTable dt = SelectName(); //if (dt.Rows.Count <= 0) //{ if (cobInstrument_UserName.Text == "") { sql = "insert into InstrumentInfo(Instrument_Collection_ID,Instrument_Name,Instrument_Type) values( " + cmbCollection.SelectedValue + ",'" + txtInstrument_name.Text + "','" + cmbType.SelectedIndex + "')"; } else { sql = "insert into InstrumentInfo(Instrument_Collection_ID,Instrument_Name,Instrument_UserID,Instrument_Type) values(" + cmbCollection.SelectedValue + ",'" + txtInstrument_name.Text + "'," + cobInstrument_UserName.SelectedValue + ",'" + cmbType.SelectedIndex + "')"; } if (LinQBaseDao.ExecuteSql(sql) > 0) { MessageBox.Show("登记成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); string strContent = this.txtInstrument_name.Text; LogInfoDAL.loginfoadd("添加", "添加:" + strContent + "仪表登记的信息", Common.USERNAME); //添加日志 BingList(); } else { MessageBox.Show("登记失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //} //else //{ // MessageBox.Show("登记失败,该仪表或检测员已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); //} } catch (Exception) { } }
/// <summary> /// 确认修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { try { if (txtInstrument_name.Text.Trim() == "") { MessageBox.Show("修改失败!仪表不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { string sql = ""; DataTable dt = SelectName(); if (dt.Rows.Count > 0 && dt.Rows[0]["Instrument_ID"].ToString() != this.txtInstrument_name.Tag.ToString()) { MessageBox.Show("修改失败,该仪表已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } sql = "Update InstrumentInfo set Instrument_Collection_ID=" + cmbCollection.SelectedValue + ", Instrument_UserID=" + this.cobInstrument_UserName.SelectedValue + ",Instrument_Name='" + this.txtInstrument_name.Text + "',Instrument_Type='" + cmbType.SelectedIndex + "' where Instrument_ID=" + this.txtInstrument_name.Tag + ""; if (LinQBaseDao.ExecuteSql(sql) > 0) { MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); string strContent = this.txtInstrument_name.Text; LogInfoDAL.loginfoadd("修改", "修改:" + strContent + "仪表登记的信息", Common.USERNAME);//添加日志 BingList(); btnUpdate.Enabled = false; btnADD.Enabled = true; btnqk.Enabled = false; } else { MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception) { } }
/// <summary> /// 删除登记 支持多选 /// 2014-09-20 杨敦钦 /// </summary> private void QcInfoDel() { if (lvwUserList.SelectedRows.Count > 0)//选中行 { try { if (lvwUserList.SelectedRows.Count > 0) { int id = Convert.ToInt32(lvwUserList.SelectedRows[0].Cells["DRAW_EXAM_INTERFACE_ID"].Value); if (MessageBox.Show("确定要删除质检吗?", "系统提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { string strMessage = ""; string content = "删除质检是修改抽样表编号" + id + "的状态为未登记,注销质检信息QCInfo含有抽样表编号的数据,注销质检流水记录表QCRecord含有抽样表编号的数据。"; //修改抽样表状态为未登记 string strDelDRAW_EXAM_INTERFACE = "update DRAW_EXAM_INTERFACE set IS_DengJi = NULL where DRAW_EXAM_INTERFACE_ID = " + id + ""; int irnt = LinQBaseDao.ExecuteSql(strDelDRAW_EXAM_INTERFACE); if (irnt > 0) { strMessage += "删除质检成功共" + irnt + "条数据"; } //删除QCREcord记录 string strDelQcrecord = "delete QCRecord where QcRecord_QCInfo_ID in (select distinct QCInfo_ID from QCInfo where QCInfo_DRAW_EXAM_INTERFACE_ID=" + id + ")"; irnt = LinQBaseDao.ExecuteSql(strDelQcrecord); if (irnt > 0) { strMessage += ",删除质检记录(QCREcord)成功共" + irnt + "条数据"; } //删除QCInfo记录 string strDel = "delete QCInfo where QCInfo_DRAW_EXAM_INTERFACE_ID=" + id + ""; irnt = LinQBaseDao.ExecuteSql(strDel); if (irnt > 0) { strMessage += ",删除质检总记录(QCInfo)成功共" + irnt + "条数据"; } irnt = 0; strDel = "delete Packets where Packets_QCInfo_DRAW_EXAM_INTERFACE_ID=" + id; irnt = LinQBaseDao.ExecuteSql(strDel); if (irnt > 0) { strMessage += ",删除质检总记录(Packets)成功共" + irnt + "条数据"; } //日志记录 if (Common.NAME != "") { Common.WriteLogData("修改", content + strMessage, Common.NAME); } else { Common.WriteLogData("修改", content + strMessage, Common.USERNAME); } ids.Clear(); page = new PageControl(); page.PageMaxCount = tscbxPageSize2.SelectedItem.ToString(); Bangding_Load(RegistrationWhere());//更新数据 if (!string.IsNullOrEmpty(strMessage)) { MessageBox.Show(strMessage, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else//没有选中 { MessageBox.Show("请选择列表再删除质检!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { Common.WriteTextLog("删除质检异常:" + ex.Message); } } }
/// <summary> /// 调用U9接口 /// </summary> /// <param name="DRAW_EXAM_INTERFACE_ID">登记编号</param> /// <param name="QcInfoid">质检编号</param> /// <returns></returns> public static string updataIsU9(int DRAW_EXAM_INTERFACE_ID, string QcInfoid) { try { Expression <Func <DRAW_EXAM_INTERFACE, bool> > funDRAW_EXAM_INTERFACE = n => n.DRAW_EXAM_INTERFACE_ID == DRAW_EXAM_INTERFACE_ID; if (isIdebarJoinU9(DRAW_EXAM_INTERFACEDAL.Query(funDRAW_EXAM_INTERFACE).FirstOrDefault().PROD_ID)) { DataTable issendDT = LinQBaseDao.Query("select issend from RegisterLoosePaperDistribution where R_DRAW_EXAM_INTERFACE_ID=" + DRAW_EXAM_INTERFACE_ID).Tables[0]; if (issendDT.Rows.Count > 0) { object str = issendDT.Rows[0][0]; bool b = Convert.ToBoolean(str); if (!b) { string sql = "select QCInfo_PumpingPackets,QCInfo_BAGWeight,ExtensionField2,QCInfo_ID,SHIPMENT_NO,DepartmentCode from View_QCInfo where QCInfo_ID='" + QcInfoid + "'"; DataSet ds = LinQBaseDao.Query(sql); if (ds != null) { if (ds.Tables[0].Rows.Count > 0) { int count = int.Parse(ds.Tables[0].Rows[0]["QCInfo_PumpingPackets"].ToString()); double whiet = Convert.ToDouble(ds.Tables[0].Rows[0]["QCInfo_BAGWeight"].ToString());//重量 string dw = ds.Tables[0].Rows[0]["ExtensionField2"].ToString(); string bd = ds.Tables[0].Rows[0]["QCInfo_ID"].ToString(); string cgd = ds.Tables[0].Rows[0]["SHIPMENT_NO"].ToString(); string bmdm = ds.Tables[0].Rows[0]["DepartmentCode"].ToString(); object CountObj = LinQBaseDao.GetSingle("select count(*) from QCRecord where QCRecord_TestItems_ID=(select TestItems_ID from TestItems where TestItems_NAME='废纸包重') and QCRecord_UPDATE_REASON is NULL and QCRecord_QCInfo_ID=" + QcInfoid); if (count != (int)CountObj) { DialogResult dr = MessageBox.Show("质检信息不一致是否继续发送数据到U9", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Hand); if (dr.Equals(DialogResult.No)) { return("失败"); } } if (count > 0 && whiet > 0 && dw != "" && bd != "" && cgd != "" && bmdm != "") { bool isSend = U9Class.sendDate(count, whiet, dw, bd, cgd, bmdm); if (isSend) { //发送成功修改标识 int result = LinQBaseDao.ExecuteSql("update dbo.RegisterLoosePaperDistribution set issend=1 where R_DRAW_EXAM_INTERFACE_ID=" + DRAW_EXAM_INTERFACE_ID); return(""); } else { return("失败"); } } else { MessageBox.Show("数据不完整无法发送数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand); return("失败"); } } } } } } return(""); } catch (Exception err) { return("失败"); } }