/// <summary> /// 获得附件数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public DataSet GetAttatch(ModelDEV_UPGRADERECORD model) { try { Log.Info("DalDEV_UPGRADERECORD->GetAttatch---START"); StringBuilder strSql = new StringBuilder(); strSql.Append("select F_ATTATCHMENT from T_DEV_UPGRADERECORD"); strSql.Append(" where 1=1 AND F_DEV_TYPE=:F_DEV_TYPE and F_DEV_ID=:F_DEV_ID and F_HARDWARE_VERSION=:F_HARDWARE_VERSION and F_SOFTWARE_VERSION=:F_SOFTWARE_VERSION "); OracleParameter[] parameters = { new OracleParameter(":F_DEV_TYPE", OracleType.Number, 8), new OracleParameter(":F_DEV_ID", OracleType.VarChar, 20), new OracleParameter(":F_HARDWARE_VERSION", OracleType.VarChar, 100), new OracleParameter(":F_SOFTWARE_VERSION", OracleType.VarChar, 100) }; parameters[0].Value = model.F_DEV_TYPE; parameters[1].Value = model.F_DEV_ID; parameters[2].Value = model.F_HARDWARE_VERSION; parameters[3].Value = model.F_SOFTWARE_VERSION; return(Query(strSql.ToString(), parameters)); } catch (Exception ex) { Log.Error("DalDEV_UPGRADERECORD->GetAttatch---FAILED", ex); throw ex; } }
/// <summary> /// 判断是否有附件 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool HasAttatch(ModelDEV_UPGRADERECORD model) { try { Log.Info("DalDEV_UPGRADERECORD->HasAttatch---START"); StringBuilder strSql = new StringBuilder(); strSql.Append("select NVL (LENGTH (T_DEV_UPGRADERECORD.F_ATTATCHMENT), 0) "); strSql.Append(" from T_DEV_UPGRADERECORD "); strSql.Append(" where F_DEV_TYPE=:F_DEV_TYPE and F_DEV_ID=:F_DEV_ID and F_HARDWARE_VERSION=:F_HARDWARE_VERSION and F_SOFTWARE_VERSION=:F_SOFTWARE_VERSION "); OracleParameter[] parameters = { new OracleParameter(":F_DEV_TYPE", OracleType.Number, 8), new OracleParameter(":F_DEV_ID", OracleType.VarChar, 20), new OracleParameter(":F_HARDWARE_VERSION", OracleType.VarChar, 100), new OracleParameter(":F_SOFTWARE_VERSION", OracleType.VarChar, 100) }; parameters[0].Value = model.F_DEV_TYPE; parameters[1].Value = model.F_DEV_ID; parameters[2].Value = model.F_HARDWARE_VERSION; parameters[3].Value = model.F_SOFTWARE_VERSION; DataSet ds = Query(strSql.ToString(), parameters); if (ds != null && ds.Tables.Count > 0) { return(int.Parse(ds.Tables[0].Rows[0][0].ToString()) > 0); } return(false); } catch (Exception ex) { Log.Error("DalDEV_UPGRADERECORD->HasAttatch---FAILED", ex); throw ex; } }
/// <summary> /// 准备要操作Model /// </summary> /// <returns></returns> private ModelDEV_UPGRADERECORD PrepareModelSubordinateHis() { try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); ModelDEV_UPGRADERECORD modelDevUpgraderecord = new ModelDEV_UPGRADERECORD(); //设备代码 modelDevUpgraderecord.F_DEV_TYPE = decimal.Parse(lueF_DEV_TYPE.EditValue.ToString()); //设备编号 modelDevUpgraderecord.F_DEV_ID = lueF_DEV_ID.EditValue.ToString(); //设备名称 modelDevUpgraderecord.F_DEV_NAME = lueF_DEV_ID.Text; // 硬件版本 modelDevUpgraderecord.F_HARDWARE_VERSION = txtF_HARDWARE_VERSION.Text; // 软件版本 modelDevUpgraderecord.F_SOFTWARE_VERSION = txtF_SOFTWARE_VERSION.Text; // 更新时间 modelDevUpgraderecord.F_UPDATE_DATE = dteF_UPDATE_DATE.DateTime; // 启用时间 modelDevUpgraderecord.F_USED_DATE = dteF_USED_DATE.DateTime; // 备注 modelDevUpgraderecord.F_MEMO = txtF_MEMO.Text; //创建时间 DateTime optDateTime = DateTime.Now; modelDevUpgraderecord.F_CREATE_TIME = optDateTime; //操作员 modelDevUpgraderecord.F_OPERATOR_ID = AppGlobal.GUserId; //操作时间 modelDevUpgraderecord.F_OPERATIONTIME = optDateTime; //是否删除 modelDevUpgraderecord.F_DEL = 0; return(modelDevUpgraderecord); } catch (Exception ex) { Log.Error(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }
/// <summary> /// 点击表格 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gvList_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); if (gvList.FocusedRowHandle < 0) { return; } decimal devType = decimal.Parse(gvList.GetFocusedRowCellValue("F_DEV_TYPE").ToString()); string devId = gvList.GetFocusedRowCellValue("F_DEV_ID").ToString(); string hardVersion = gvList.GetFocusedRowCellValue("F_HARDWARE_VERSION").ToString(); string softVersion = gvList.GetFocusedRowCellValue("F_SOFTWARE_VERSION").ToString(); ModelDEV_UPGRADERECORD modelDevUpgraderecord = _bllDevUpgraderecord.GetModel(devType, devId, hardVersion, softVersion); //设备类型 lueF_DEV_TYPE.EditValue = devType; //设备编号 lueF_DEV_ID.EditValue = devId; //硬件版本 txtF_HARDWARE_VERSION.Text = modelDevUpgraderecord.F_HARDWARE_VERSION; //软件版本 txtF_SOFTWARE_VERSION.Text = modelDevUpgraderecord.F_SOFTWARE_VERSION; //上位机信息 dteF_UPDATE_DATE.DateTime = modelDevUpgraderecord.F_UPDATE_DATE; //工作状态 dteF_USED_DATE.DateTime = modelDevUpgraderecord.F_USED_DATE; //备注 txtF_MEMO.Text = gvList.GetFocusedRowCellValue("F_MEMO").ToString(); chkF_ATTATCHMENT.Checked = _bllDevUpgraderecord.HasAttatch(modelDevUpgraderecord); } catch (Exception ex) { Log.Error(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }
/// <summary> /// 获得附件 /// </summary> /// <param name="model"></param> /// <returns></returns> public DataSet GetAttatch(ModelDEV_UPGRADERECORD model) { try { Log.Info("BllDEV_UPGRADERECORD->Update---START"); ConnectionOpen(); dal.SetDBAccess(GetDBAccess()); return(dal.GetAttatch(model)); } catch (Exception ex) { Log.Error("BllDEV_UPGRADERECORD->Update---FAILED", ex); throw ex; } finally { ConnectionClose(); Log.Info("BllDEV_UPGRADERECORD->Update---finally"); } }
/// <summary> /// 彻底删除一条记录,一旦删除无法恢复,建议不要使用此功能 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelete_Click(object sender, EventArgs e) { try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //删除前判断 DialogResult dialogResult = DevExpress.DXCore.Controls.XtraEditors.XtraMessageBox.Show("此操作将永久删除数据并有可能导致其他关联数据出错,是否继续?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelDEV_UPGRADERECORD modelDevUpgraderecord = PrepareModelSubordinateHis(); //更新数据 bool status = _bllDevUpgraderecord.Drop(modelDevUpgraderecord.F_DEV_TYPE, modelDevUpgraderecord.F_DEV_ID, modelDevUpgraderecord.F_HARDWARE_VERSION, modelDevUpgraderecord.F_SOFTWARE_VERSION); if (status) { XtraMessageBox.Show("此数据已删除。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("没有数据被更新,操作中断。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { Log.Error(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }
/// <summary> /// 下载附件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDownload_Click(object sender, EventArgs e) { //检查是否有这条记录存在 try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); if (!chkF_ATTATCHMENT.Checked) { XtraMessageBox.Show("当前记录没有附件,执行中断。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelDEV_UPGRADERECORD modelDevUpgraderecord = PrepareModelSubordinateHis(); //判断此数据是否已经存在 bool isDataExist = _bllDevUpgraderecord.Exists(modelDevUpgraderecord.F_DEV_TYPE, modelDevUpgraderecord.F_DEV_ID, modelDevUpgraderecord.F_HARDWARE_VERSION, modelDevUpgraderecord.F_SOFTWARE_VERSION); if (!isDataExist) { XtraMessageBox.Show("没有此条数据。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "压缩文件 (*.zip)|*.zip"; DialogResult dialogResult = saveFileDialog.ShowDialog(); if (dialogResult == DialogResult.Cancel) { return; } //打开文件 string fileName = saveFileDialog.FileName; //读取附件数据 DataSet dsAttatch = _bllDevUpgraderecord.GetAttatch(modelDevUpgraderecord); if (dsAttatch != null && dsAttatch.Tables.Count > 0) { byte[] objFileBuffer = (byte[])dsAttatch.Tables[0].Rows[0]["F_ATTATCHMENT"]; FileStream fs = new FileStream(fileName, FileMode.Create); fs.Write(objFileBuffer, 0, objFileBuffer.Length); fs.Flush(); fs.Close(); } XtraMessageBox.Show("附件已下载。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { Log.Error(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }
/// <summary> /// 上传附件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpload_Click(object sender, EventArgs e) { //检查是否有这条记录存在 try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelDEV_UPGRADERECORD modelDevUpgraderecord = PrepareModelSubordinateHis(); //判断此数据是否已经存在 bool isDataExist = _bllDevUpgraderecord.Exists(modelDevUpgraderecord.F_DEV_TYPE, modelDevUpgraderecord.F_DEV_ID, modelDevUpgraderecord.F_HARDWARE_VERSION, modelDevUpgraderecord.F_SOFTWARE_VERSION); if (!isDataExist) { XtraMessageBox.Show("请先保存数据再上传附件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //打开文件 OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "压缩文件 (*.zip)|*.zip"; DialogResult dialogResult = openFileDialog.ShowDialog(); if (dialogResult == DialogResult.Cancel) { return; } //打开文件 string fileName = openFileDialog.FileName; //创建流 FileStream fsUpload = File.OpenRead(fileName); //设定大小 modelDevUpgraderecord.F_ATTATCHMENT = new byte[fsUpload.Length]; //读出数据 fsUpload.Read(modelDevUpgraderecord.F_ATTATCHMENT, 0, modelDevUpgraderecord.F_ATTATCHMENT.Length); fsUpload.Close(); bool status = _bllDevUpgraderecord.Upload(modelDevUpgraderecord); if (status) { XtraMessageBox.Show("附件已上传。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("没有数据被更新,操作中断。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { Log.Error(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }
/// <summary> /// 更新信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelDEV_UPGRADERECORD modelDevUpgraderecord = PrepareModelSubordinateHis(); //判断此数据是否已经存在 bool isDataExist = _bllDevUpgraderecord.Exists(modelDevUpgraderecord.F_DEV_TYPE, modelDevUpgraderecord.F_DEV_ID, modelDevUpgraderecord.F_HARDWARE_VERSION, modelDevUpgraderecord.F_SOFTWARE_VERSION); if (isDataExist) { //已经存在判断是否更新 DialogResult dialogResult = XtraMessageBox.Show("当前数据已存在,是否更新?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } //更新数据 bool status = _bllDevUpgraderecord.Update(modelDevUpgraderecord); //获得当前rowhandle int rowhandle = gvList.FocusedRowHandle; //绑定数据 BindGridview(); //设置焦点行 gvList.FocusedRowHandle = rowhandle; if (status) { XtraMessageBox.Show("此数据已更新。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("没有数据被更新,操作中断。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { _bllDevUpgraderecord.Add(modelDevUpgraderecord); //获得当前rowhandle int rowhandle = gvList.FocusedRowHandle; //绑定数据 BindGridview(); //设置焦点行 gvList.FocusedRowHandle = rowhandle + 1; XtraMessageBox.Show("此数据已增加。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Log.Error(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }