Ejemplo n.º 1
0
 protected virtual void DeleteDetail()
 {
     if (this.IsDetailSelectedRowByCheckBox() && this.ValidateDeleteDetail())
     {
         if (this.ConfimDelete() == false)
         {
             return;
         }
         bool isDeleteSuccess = false;
         try
         {
             isDeleteSuccess  = this.DeleteDetailOperate();
             this.m_ErrorInfo = string.Empty;
         }
         catch (Exception ex)
         {
             this.m_ErrorInfo = ex.ToString();
             XErrorLogTool.WriteLog(ex.ToString());
         }
         if (isDeleteSuccess)
         {
             //删除成功
             this.DeleteDetailRowsFromMemory();
             if (this.m_IsShowDeleteSuccessMessage)
             {
                 this.ShowDeleteMessage(true);
             }
         }
         else
         {
             //删除失败
             this.ShowDeleteMessage(false);
         }
     }
 }
Ejemplo n.º 2
0
 private void btnExport_Click(object sender, EventArgs e)
 {
     try
     {
         SaveFileDialog sfd = new SaveFileDialog();
         sfd.Filter = "Excel文件(*.xls)|*.xls";
         if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             this.grdExporter.SheetName = this.Text;
             //this.grdData.RootTable.Columns["select"].Visible = false;
             System.IO.Stream stream = new System.IO.FileStream(sfd.FileName, System.IO.FileMode.CreateNew);
             this.grdExporter.Export(stream);
             stream.Close();
             //this.grdData.RootTable.Columns["select"].Visible = true;
             XMessageBox.ShowRemindMessage("导出完成!");
         }
     }
     catch (Exception ex)
     {
         XErrorLogTool.WriteLog(ex.ToString());
         XMessageBox.ShowError("导出失败!");
     }
     finally
     {
         //this.grdData.RootTable.Columns["select"].Visible = true;
     }
 }
Ejemplo n.º 3
0
        protected override void FillGridBefore()
        {
            IList <string> colors = new List <string>();

            foreach (XModelBase model in this.m_CurrentList)
            {
                XCodeEquipmentStateInfo stateInfo = model as XCodeEquipmentStateInfo;

                GridEXFormatCondition condition = new GridEXFormatCondition();
                if (!colors.Contains(stateInfo.ColorRGB) && stateInfo.ColorRGB != "0,0,0")
                {
                    try
                    {
                        Color color = XColorHelper.GetColorFormStringRgb(stateInfo.ColorRGB);
                        condition.FormatStyle.BackColor = color;
                        condition.Column = this.grdData.RootTable.Columns["ColorRGB"];
                        condition.Value1 = stateInfo.ColorRGB;
                        this.grdData.RootTable.FormatConditions.Add(condition);

                        colors.Add(stateInfo.ColorRGB);
                    }
                    catch (Exception ex)
                    {
                        XErrorLogTool.WriteLog(ex.ToString());
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 菜单单击事件
 /// </summary>
 /// <param name="menuInfo"></param>
 /// <param name="e"></param>
 protected virtual void menuFolderTool_MenuClickEvent(XMenuInfo menuInfo, EventArgs e)
 {
     try
     {
         frmBase frm = Assembly.Load(menuInfo.NameSpace).CreateInstance(menuInfo.FullAssembleName) as frmBase;
         if (frm == null)
         {
             XMessageBox.ShowError("该功能未实现或者实现的接口不正确!");
             return;
         }
         if (menuInfo.IsDialogModel)
         {
             frm.StartPosition = FormStartPosition.CenterParent;
             frm.ShowDialog();
         }
         else
         {
             this.ShowTabbedMdi(frm);
         }
     }
     catch (Exception ex)
     {
         XMessageBox.ShowError(ex.Message);
         XErrorLogTool.WriteLog(ex.ToString());
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 执行Sql语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns>执行失败则返回0或者-1</returns>
        public virtual int ExecuteNonQueryByTrans(string sql)
        {
            DbTransaction trans = null;

            try
            {
                if (this.m_Connection.State == ConnectionState.Closed)
                {
                    this.m_Connection.Open();
                }
                trans = this.m_Connection.BeginTransaction();
                DbCommand command = this.GetDbCommand();
                command.Transaction = trans;
                command.CommandText = sql;
                command.Connection  = this.m_Connection;
                int result = command.ExecuteNonQuery();
                trans.Commit();
                return(result);
            }
            catch (Exception ex)
            {
                XMessageBox.ShowError(ex.ToString());
                XErrorLogTool.WriteLog(ex.ToString());
                trans.Rollback();
                return(-1);
            }
            finally
            {
                if (this.m_Connection.State == ConnectionState.Open)
                {
                    this.m_Connection.Close();
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 获取查询表
 /// </summary>
 /// <param name="sql"></param>
 /// <returns></returns>
 public virtual DataTable GetDataTable(string sql)
 {
     if (sql.Trim() == string.Empty)
     {
         return(null);
     }
     else
     {
         try
         {
             if (this.m_Connection.State == ConnectionState.Closed)
             {
                 this.m_Connection.Open();
             }
             DbDataAdapter adp        = this.GetDbDataAdapter(this.m_Connection, sql);
             DataTable     queryTable = new DataTable();
             adp.Fill(queryTable);
             return(queryTable);
         }
         catch (Exception ex)
         {
             XErrorLogTool.WriteLog(ex.ToString());
             return(null);
         }
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 获得执行结果第一行第一列的值
 /// </summary>
 /// <param name="sql"></param>
 /// <returns></returns>
 public virtual object ExecuteScalar(string sql)
 {
     try
     {
         if (this.m_Connection.State == ConnectionState.Closed)
         {
             this.m_Connection.Open();
         }
         DbCommand command = this.GetDbCommand();
         command.Connection  = this.m_Connection;
         command.CommandText = sql;
         return(command.ExecuteScalar());
     }
     catch (Exception ex)
     {
         XMessageBox.ShowError(ex.Message);
         XErrorLogTool.WriteLog(ex.ToString());
         return(null);
     }
     finally
     {
         if (this.m_Connection != null && this.m_Connection.State == ConnectionState.Closed)
         {
             this.m_Connection.Close();
         }
     }
 }
Ejemplo n.º 8
0
        public bool InsertCustom(XModelBase model)
        {
            DbConnection  sqlConn = this.m_DataAccess.Connection;
            DbTransaction trans   = null;

            try
            {
                if (sqlConn.State == ConnectionState.Closed)
                {
                    sqlConn.Open();
                }

                trans = sqlConn.BeginTransaction();

                string sql = this.GetInsertSql(model) + ";";

                XVTaskFilesInfo taskFilesInfo = model as XVTaskFilesInfo;

                //更新任务状态为结束
                sql += "UPDATE Task SET TaskStatus='结束' WHERE RID='" + taskFilesInfo.MainId + "';";

                if (taskFilesInfo.FileFullName != string.Empty)
                {
                    //上传附件
                    DbCommand fileCommand = this.GetFileCommand(taskFilesInfo);
                    fileCommand.Connection  = sqlConn;
                    fileCommand.Transaction = trans;
                    DbDataReader reader = fileCommand.ExecuteReader();
                    reader.Close();
                }

                DbCommand cmd = this.m_DataAccess.GetDbCommand();
                cmd.Connection  = sqlConn;
                cmd.CommandText = sql;
                cmd.Transaction = trans;
                bool isSuccess = cmd.ExecuteNonQuery() > 0;
                trans.Commit();

                return(isSuccess);
            }
            catch (Exception ex)
            {
                XMessageBox.ShowError(ex.Message);
                XErrorLogTool.WriteLog(ex.ToString());
                trans.Rollback();
            }
            finally
            {
                if (sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                }
            }

            return(false);
        }
Ejemplo n.º 9
0
        public static bool Preview(string fileId)
        {
            string where = " and FileId='" + fileId + "'";

            IList <XModelBase> fileAttachInfos = m_FileAttachBusiness.QueryByWhere(where);

            if (fileAttachInfos.Count == 0)
            {
                XMessageBox.ShowError("未找到附件,无法预览!");
                return(false);
            }

            XFileAttachmentInfo fileInfo = fileAttachInfos[0] as XFileAttachmentInfo;

            string[] imageTypes  = new string[] { ".png", ".jpg", ".jpeg" };
            string[] officeTypes = new string[] { ".doc", ".docx", ".xls", ".xlsx" };

            if (!imageTypes.Contains(fileInfo.AtchType) &&
                !officeTypes.Contains(fileInfo.AtchType))
            {
                XMessageBox.ShowError("不支持预览格式为[" + fileInfo.AtchType + "]的文件!");
                return(false);
            }

            string path     = XCommon.TempPath;
            string fileName = Guid.NewGuid().ToString();

            fileName = m_FileAttachBusiness.DownLoadFile(fileId, path, fileName);

            if (imageTypes.Contains(fileInfo.AtchType))
            {
                //如果是图片
                frmImagePreview frm = new frmImagePreview(fileName);
                frm.ShowDialog();
            }
            else
            {
                frmOfficeFilePreview frm = new frmOfficeFilePreview(fileName);
                frm.ShowDialog();
            }

            if (File.Exists(fileName))
            {
                try
                {
                    File.Delete(fileName);
                }
                catch (Exception ex)
                {
                    XErrorLogTool.WriteLog(ex.ToString());
                }
            }

            return(true);
        }
Ejemplo n.º 10
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                XUsersBusiness usersBusiness = new XUsersBusiness();
                //if (usersBusiness.GetServerTime() >= new DateTime(2014, 2, 28))
                //{
                //    XMessageBox.ShowError("出现异常,无法登录!");
                //    return;
                //}

                if (this.ValidateLogin())
                {
                    this.m_UserInfo = this.GetLoginUsersInfo();
                    if (this.m_UserInfo == null)
                    {
                        XMessageBox.ShowError("用户名或者密码错误!");
                        return;
                    }

                    if (this.m_UserInfo.IsUsed == false)
                    {
                        XMessageBox.ShowError("该用户不可用!");
                        return;
                    }

                    XCommon.LoginUsersInfo = this.m_UserInfo.Clone() as XUsersInfo;
                    if (this.m_UserInfo != null)
                    {
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                        try
                        {
                            this.LoginLog();
                        }
                        catch (Exception ex)
                        {
                            XErrorLogTool.WriteLog(ex.ToString());
                        }
                    }
                    this.RememberLoginUser();
                }
            }
            catch (Exception ex)
            {
                XMessageBox.ShowError(ex.Message);
                XErrorLogTool.WriteLog(ex.ToString());
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 11
0
 private void Preview()
 {
     try
     {
         this.fcWord.Open(m_FileName);
     }
     catch (Exception ex)
     {
         XMessageBox.ShowError(ex.Message);
         XErrorLogTool.WriteLog(ex.ToString());
     }
 }
Ejemplo n.º 12
0
 private void Preview()
 {
     try
     {
         Image image = Image.FromFile(this.m_FileName);
         this.picFile.BackgroundImage = image;
     }
     catch (Exception ex)
     {
         XMessageBox.ShowError(ex.Message);
         XErrorLogTool.WriteLog(ex.ToString());
     }
 }
Ejemplo n.º 13
0
 private void Exit()
 {
     try
     {
         XLoginLogBusiness business = new XLoginLogBusiness();
         business.Exit(XCommon.LoginId);
     }
     catch (Exception ex)
     {
         XErrorLogTool.WriteLog(ex.ToString());
     }
     this.Dispose();
     Environment.Exit(0);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 获取查询表
 /// </summary>
 /// <param name="sql"></param>
 /// <returns></returns>
 public virtual DataTable GetDataTable(string sql)
 {
     try
     {
         DataTable     dt      = new DataTable();
         DbDataAdapter adapter = this.GetDbDataAdapter(this.m_Connection, sql);
         adapter.Fill(dt);
         return(dt);
     }
     catch (Exception ex)
     {
         XMessageBox.ShowError(ex.Message);
         XErrorLogTool.WriteLog(ex.ToString());
         return(null);
     }
 }
Ejemplo n.º 15
0
 protected override void DownloadAfter(string fileName, Model.XModelBase model)
 {
     try
     {
         this.Cursor = Cursors.WaitCursor;
         XEquipmentReceiveWordTool.FillWordValue(fileName, model as Model.XVEquipmentReceiveInfo);
     }
     catch (Exception ex)
     {
         XMessageBox.ShowError(ex.Message);
         XErrorLogTool.WriteLog(ex.ToString());
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }
Ejemplo n.º 16
0
        protected virtual XOperateSingleResultInfo ImportSingleRow(DataRow excelRow)
        {
            XOperateSingleResultInfo singleResult = new XOperateSingleResultInfo();
            XModelBase model = null;

            try
            {
                singleResult.Key = this.GetRowKey(excelRow);

                string validateResult = this.ValidateSingleRow(excelRow);

                if (validateResult != string.Empty)
                {
                    //如果校验未通过
                    singleResult.IsSuccess = false;
                    singleResult.ErrorInfo = validateResult;
                }
                else
                {
                    model = this.DataRow2Model(excelRow);
                    if (model == null)
                    {
                        singleResult.IsSuccess = false;
                        singleResult.ErrorInfo = "导入数据的模板可能不正确!";
                    }
                    else
                    {
                        //singleResult.IsSuccess = this.m_Business.Insert(model);
                        singleResult.IsSuccess = this.ImportSingleOperate(model);
                    }
                }
            }
            catch (Exception ex)
            {
                XErrorLogTool.WriteLog(ex.ToString());
                singleResult.ErrorInfo = "发生异常,导入模板或数据列格式可能不正确,具体错误信息为" + ex.Message;
                //if (XMessageBox.ShowQuestion("发生异常,导入模板或数据列格式可能不正确,具体错误信息为:\r\n" +
                //    ex.Message + ",\r\n是否继续?") == System.Windows.Forms.DialogResult.No)
                //{
                //    break;
                //}
            }

            return(singleResult);
        }
Ejemplo n.º 17
0
        private void Init()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                string path = XCommon.TempPath;
                this.m_FileName = Guid.NewGuid().ToString();

                m_FileName = this.m_FileAttachmentBusiness.DownLoadFile(m_EquipmentReceiveInfo.ID,
                                                                        path, m_FileName);

                if (m_FileName != string.Empty)
                {
                    XEquipmentReceiveWordTool.FillWordValue(m_FileName, m_EquipmentReceiveInfo);
                    this.fcWord.Open(m_FileName, true, null, null, null);

                    Word.Document dct = this.fcWord.ActiveDocument as Word.Document;

                    if (dct.ProtectionType == Word.WdProtectionType.wdAllowOnlyComments)
                    {
                        dct.Unprotect();
                    }

                    if (dct.ProtectionType == Word.WdProtectionType.wdNoProtection)
                    {
                        dct.Protect(Word.WdProtectionType.wdAllowOnlyComments);
                    }
                }
                else
                {
                    XMessageBox.ShowError("未找到要打印的报告文档!");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                XErrorLogTool.WriteLog(ex.ToString());
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 通过事务执行Sql语句
        /// </summary>
        /// <param name="sqlList">sql语句集合</param>
        /// <returns></returns>
        public virtual bool ExecuteNonQuery(IList <string> sqlList)
        {
            string sqls = string.Empty;

            foreach (string sql in sqlList)
            {
                sqls += sql + ";";
            }
            try
            {
                return(this.ExecuteNonQueryByTrans(sqls) > 0);
            }
            catch (Exception ex)
            {
                XMessageBox.ShowError(ex.Message);
                XErrorLogTool.WriteLog(ex.ToString());
                return(false);
            }
        }
Ejemplo n.º 19
0
 private void frmPrintPreview_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         Word.Document dct = this.fcWord.ActiveDocument as Word.Document;
         if (dct != null)
         {
             dct.Close();
             dct.Application.Quit();
             this.fcWord.Close();
             if (File.Exists(m_FileName))
             {
                 File.Delete(m_FileName);
             }
         }
     }
     catch (Exception ex)
     {
         XErrorLogTool.WriteLog(ex.ToString());
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// 通过事务执行Sql语句
        /// </summary>
        /// <param name="sqlList">sql语句集合</param>
        /// <returns></returns>
        public virtual bool ExecuteNonQuery(IList <string> sqlList)
        {
            DbTransaction trans = null;

            try
            {
                if (this.m_Connection.State == ConnectionState.Closed)
                {
                    this.m_Connection.Open();
                }
                trans = this.m_Connection.BeginTransaction();
                DbCommand cmd = this.GetDbCommand();
                cmd.Connection  = this.m_Connection;
                cmd.Transaction = trans;
                foreach (string sql in sqlList)
                {
                    cmd.CommandText = sql;
                    cmd.ExecuteNonQuery();
                }
                trans.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                if (trans != null)
                {
                    trans.Rollback();
                }
                XErrorLogTool.WriteLog(ex.ToString());
                return(false);
            }
            finally
            {
                if (trans != null)
                {
                    trans.Dispose();
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 执行Sql语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns>执行失败则返回0或者-1</returns>
        public virtual int ExecuteNonQueryByTrans(string sql)
        {
            DbTransaction trans = null;

            try
            {
                if (this.m_Connection.State == ConnectionState.Closed)
                {
                    this.m_Connection.Open();
                }
                trans = this.m_Connection.BeginTransaction();
                DbCommand cmd = this.GetDbCommand();
                if (cmd == null || this.m_Connection == null)
                {
                    return(-1);
                }
                cmd.Connection  = this.m_Connection;
                cmd.CommandText = sql;
                cmd.Transaction = trans;
                int count = cmd.ExecuteNonQuery();

                trans.Commit();
                return(count);
            }
            catch (Exception ex)
            {
                trans.Rollback();
                XErrorLogTool.WriteLog(ex.ToString());
                return(-1);
            }
            finally
            {
                if (trans != null)
                {
                    trans.Dispose();
                }
            }
        }
Ejemplo n.º 22
0
        void cmdPdf_Click(object sender, Janus.Windows.UI.CommandBars.CommandEventArgs e)
        {
            if (this.grdData.CurrentRow != null &&
                this.grdData.CurrentRow.RowType == Janus.Windows.GridEX.RowType.Record)
            {
                XVEquipmentReceiveInfo receiveInfo = this.grdData.CurrentRow.DataRow as XVEquipmentReceiveInfo;

                if (!this.m_PdfAttachBusiness.IsFileExist(receiveInfo.RID))
                {
                    XMessageBox.ShowError("未找到要打印的PDF文档,请确认是否已上传PDF报告!");
                    return;
                }

                string path         = XCommon.TempPath;
                string tempFileName = Guid.NewGuid().ToString();

                tempFileName = this.m_PdfAttachBusiness.DownLoadFile(receiveInfo.ID,
                                                                     path, tempFileName);

                if (tempFileName != string.Empty)
                {
                    try
                    {
                        Process.Start(tempFileName);
                    }
                    catch (Exception ex)
                    {
                        XMessageBox.ShowError(ex.Message);
                        XErrorLogTool.WriteLog(ex.ToString());
                    }
                }
                else
                {
                    XMessageBox.ShowError("未找到要打印的PDF报告文档!");
                    this.Close();
                }
            }
        }
Ejemplo n.º 23
0
        public bool SaveConfigInfo(XSystemConfigInfo configInfo)
        {
            XmlDocument dct = new XmlDocument();

            dct.Load(m_ConfigFileName);

            XmlNode signNode = dct.SelectSingleNode("SystemConfigs/SignConfig");

            signNode.Attributes["SignWidth"].Value      = configInfo.SignWidht.ToString();
            signNode.Attributes["SignHeight"].Value     = configInfo.SignHeight.ToString();
            signNode.Attributes["RefreshMinutes"].Value = configInfo.RefreshMinutes.ToString();
            try
            {
                dct.Save(m_ConfigFileName);
                return(true);
            }
            catch (Exception ex)
            {
                XMessageBox.ShowError(ex.Message);
                XErrorLogTool.WriteLog(ex.ToString());
                return(false);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 获得执行结果第一行第一列的值
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public virtual object ExecuteScalar(string sql)
        {
            DbCommand cmd = this.GetDbCommand();

            if (cmd == null || this.m_Connection == null)
            {
                return(null);
            }
            try
            {
                if (this.m_Connection.State == ConnectionState.Closed)
                {
                    this.m_Connection.Open();
                }
                cmd.Connection  = this.m_Connection;
                cmd.CommandText = sql;
                return(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                XErrorLogTool.WriteLog(ex.ToString());
                return(null);
            }
        }
Ejemplo n.º 25
0
        public override bool Update(XModelBase modelInfo, IDictionary <string, IList <XModelBase> > detailDict, IDictionary <string, IList <XModelBase> > deleteDict)
        {
            DbConnection  sqlConn = this.m_DataAccess.Connection;
            DbTransaction trans   = null;

            try
            {
                if (sqlConn.State == ConnectionState.Closed)
                {
                    sqlConn.Open();
                }

                trans = sqlConn.BeginTransaction();

                string sql = string.Empty;

                //更新语句
                sql += this.GetUpdateSql(modelInfo) + ";";

                //获取删除语句
                foreach (KeyValuePair <string, IList <XModelBase> > keyValue in deleteDict)
                {
                    string             key          = keyValue.Key;
                    IList <XModelBase> detailModels = keyValue.Value;
                    foreach (XModelBase detailInfo in detailModels)
                    {
                        sql += this.GetDetailDeleteSql(key, detailInfo);
                    }
                }

                //获取新增和修改明细
                foreach (KeyValuePair <string, IList <XModelBase> > keyValue in detailDict)
                {
                    string             key          = keyValue.Key;
                    IList <XModelBase> detailModels = keyValue.Value;
                    foreach (XModelBase detailInfo in detailModels)
                    {
                        if (detailInfo.ModelStatus == XModelStatus.Add)
                        {
                            //新增
                            this.FillDetailMainId(key, detailInfo, modelInfo);
                            sql += this.GetDetailInsertSql(key, detailInfo);
                            if (key == "grdFiles")
                            {
                                //如果是文件集,则需要存储附件
                                XVTaskAttachmentInfo fileInfo = detailInfo as XVTaskAttachmentInfo;
                                if (fileInfo.FileFullName != string.Empty)
                                {
                                    DbCommand fileCommand = this.GetFileCommand(fileInfo);
                                    fileCommand.Connection  = sqlConn;
                                    fileCommand.Transaction = trans;
                                    DbDataReader reader = fileCommand.ExecuteReader();
                                    reader.Close();
                                }
                            }
                        }
                        else if (detailInfo.ModelStatus == XModelStatus.Modify)
                        {
                            //修改
                            sql += this.GetDetailUpdateSql(key, detailInfo);
                            if (key == "grdFiles")
                            {
                                //修改的时候有可能修改文件如果是文件集,则需要存储附件
                                XVTaskAttachmentInfo fileInfo = detailInfo as XVTaskAttachmentInfo;
                                if (fileInfo.FileFullName != string.Empty)
                                {
                                    DbCommand fileCommand = this.GetFileCommand(fileInfo);
                                    fileCommand.Connection  = sqlConn;
                                    fileCommand.Transaction = trans;
                                    DbDataReader reader = fileCommand.ExecuteReader();
                                    reader.Close();
                                }
                            }
                        }
                    }
                }

                DbCommand cmd = this.m_DataAccess.GetDbCommand();
                cmd.Connection  = sqlConn;
                cmd.Transaction = trans;
                cmd.CommandText = sql;
                bool isSuccess = cmd.ExecuteNonQuery() > 0;
                trans.Commit();

                return(isSuccess);
            }
            catch (Exception ex)
            {
                XMessageBox.ShowError(ex.Message);
                XErrorLogTool.WriteLog(ex.ToString());
                trans.Rollback();
            }
            finally
            {
                if (sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                }
            }

            return(false);
        }
Ejemplo n.º 26
0
        public override bool Insert(XModelBase modelInfo, IDictionary <string, IList <XModelBase> > detailDict)
        {
            DbConnection  sqlConn = this.m_DataAccess.Connection;
            DbTransaction trans   = null;

            try
            {
                if (sqlConn.State == ConnectionState.Closed)
                {
                    sqlConn.Open();
                }

                trans = sqlConn.BeginTransaction();

                string sql = string.Empty;

                //插入主表
                string sqlMain = this.GetInsertSql(modelInfo);
                sql += sqlMain;

                //插入子表
                foreach (KeyValuePair <string, IList <XModelBase> > keyValue in detailDict)
                {
                    string             key          = keyValue.Key;
                    IList <XModelBase> detailModels = keyValue.Value;

                    foreach (XModelBase detailInfo in detailModels)
                    {
                        //填充子表
                        this.FillDetailMainId(key, detailInfo, modelInfo);
                        sql += this.GetDetailInsertSql(key, detailInfo) + ";";
                        if (key == "grdFiles")
                        {
                            //如果是文件集,则需要存储附件
                            XVStandFilesInfo fileInfo = detailInfo as XVStandFilesInfo;
                            if (fileInfo.FileFullName != string.Empty)
                            {
                                DbCommand fileCommand = this.GetFileCommand(fileInfo);
                                fileCommand.Connection  = sqlConn;
                                fileCommand.Transaction = trans;
                                DbDataReader reader = fileCommand.ExecuteReader();
                                reader.Close();
                            }
                        }
                    }
                }

                //插入语句后执行
                sql += this.GetInsertAfterSql(modelInfo);

                DbCommand cmd = this.m_DataAccess.GetDbCommand();
                cmd.Connection  = sqlConn;
                cmd.CommandText = sql;
                cmd.Transaction = trans;
                bool isSuccess = cmd.ExecuteNonQuery() > 0;
                trans.Commit();

                return(isSuccess);
            }
            catch (Exception ex)
            {
                XMessageBox.ShowError(ex.Message);
                XErrorLogTool.WriteLog(ex.ToString());
                trans.Rollback();
            }
            finally
            {
                if (sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                }
            }

            return(false);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 检定
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Checked(XModelBase model, string userId)
        {
            DbConnection  sqlConn = this.m_DataAccess.Connection;
            DbTransaction trans   = null;

            try
            {
                if (sqlConn.State == ConnectionState.Closed)
                {
                    sqlConn.Open();
                }

                trans = sqlConn.BeginTransaction();

                string sql = string.Empty;

                XVEquipmentReceiveInfo receiveInfo = model as XVEquipmentReceiveInfo;

                //更新检定信息
                sql = "UPDATE " + this.TableName + " SET VerifyUserId='" + receiveInfo.VerifyUserId +
                      "',CheckedReport='" + receiveInfo.CheckedReport + "',CheckedUserId='" + userId + "'," +
                      "CheckedDate='" + receiveInfo.CheckedDate + "',CheckedDesc='" + receiveInfo.CheckedDesc + "', " +
                      "CurrentStatus='" + receiveInfo.CurrentStatus + "',FlowStatus='" + receiveInfo.FlowStatus + "', " +
                      "FlowUserId='" + receiveInfo.VerifyUserId + "', " +
                      "IsBack=0,BackUserId=NULL,BackDate=null,BackReason=NULL,StandId='" + receiveInfo.StandId + "' " +
                      "WHERE RID='" + receiveInfo.RID + "';";

                if (receiveInfo.ReportFileFullName != string.Empty)
                {
                    //上传附件
                    DbCommand fileCommand = this.GetFileCommand(receiveInfo);
                    fileCommand.Connection  = sqlConn;
                    fileCommand.Transaction = trans;
                    DbDataReader reader = fileCommand.ExecuteReader();
                    reader.Close();
                }

                DbCommand cmd = this.m_DataAccess.GetDbCommand();
                cmd.Connection  = sqlConn;
                cmd.CommandText = sql;
                cmd.Transaction = trans;
                bool isSuccess = cmd.ExecuteNonQuery() > 0;
                trans.Commit();

                return(isSuccess);
            }
            catch (Exception ex)
            {
                XMessageBox.ShowError(ex.Message);
                XErrorLogTool.WriteLog(ex.ToString());
                trans.Rollback();
            }
            finally
            {
                if (sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                }
            }

            return(false);
        }
Ejemplo n.º 28
0
        public new bool InsertFile(string id, string fileId, string fileName, string userId)
        {
            FileInfo fi = new FileInfo(fileName);

            if (fi.Exists == false)
            {
                return(false);
                //直接返回失败
            }

            double fileSize = 0;

            fileSize = Math.Round(XHelper.GetDouble(fi.Length) / XHelper.GetDouble(1024), 2);

            string fileDesc = string.Empty;

            byte[] bData = null;
            using (FileStream fs = fi.OpenRead())
            {
                bData = new byte[fi.Length];
                fs.Read(bData, 0, Convert.ToInt32(fi.Length));
            }

            string sql = "DELETE FROM " + this.TableName + " WHERE FileId='" + fileId + "';";

            sql += "INSERT INTO " + this.TableName + "(RID,FileId,AtchName,AtchDesc,AtchType," +
                   "AtchSize,AtchPath,AtchShotGifPath,AtchImag,InputUserId,InputTime)values" +
                   "(@RId,@FileId,@AtchName,@AtchDesc,@AtchType,@AtchSize,@AtchPath,@AtchShotGifPath," +
                   "@AtchImag,@UserId,getdate())";
            DbConnection conn = this.m_DataAccess.Connection;
            DbCommand    cmd  = this.m_DataAccess.GetDbCommand();

            cmd.Connection  = conn;
            cmd.CommandText = sql;

            DbParameter parameterId = this.m_DataAccess.GetParameter("@RId", id);

            cmd.Parameters.Add(parameterId);
            DbParameter parameterMainId = this.m_DataAccess.GetParameter("@FileId", fileId);

            cmd.Parameters.Add(parameterMainId);
            DbParameter parameterFileName = this.m_DataAccess.GetParameter("@AtchName", fi.Name);

            cmd.Parameters.Add(parameterFileName);
            DbParameter parameterAtchDesc = this.m_DataAccess.GetParameter("@AtchDesc", fileDesc);

            cmd.Parameters.Add(parameterAtchDesc);
            DbParameter parameterAtchType = this.m_DataAccess.GetParameter("@AtchType", fi.Extension);

            cmd.Parameters.Add(parameterAtchType);
            DbParameter parameterAtchSize = this.m_DataAccess.GetParameter("@AtchSize", fileSize);

            cmd.Parameters.Add(parameterAtchSize);
            DbParameter parameterAtchPath = this.m_DataAccess.GetParameter("@AtchPath", fi.FullName);

            cmd.Parameters.Add(parameterAtchPath);
            DbParameter parameterAtchShotGifPath = this.m_DataAccess.GetParameter("@AtchShotGifPath", "");

            cmd.Parameters.Add(parameterAtchShotGifPath);
            DbParameter parameterFile = this.m_DataAccess.GetParameter("@AtchImag", bData);

            cmd.Parameters.Add(parameterFile);
            DbParameter parameterUser = this.m_DataAccess.GetParameter("@UserId", userId);

            cmd.Parameters.Add(parameterUser);

            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                cmd.ExecuteReader();
                return(true);
            }
            catch (Exception ex)
            {
                XErrorLogTool.WriteLog(ex.ToString());
                return(false);
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 29
0
        public bool Checked(XModelBase model, string userId)
        {
            DbConnection  sqlConn = this.m_DataAccess.Connection;
            DbTransaction trans   = null;

            try
            {
                if (sqlConn.State == ConnectionState.Closed)
                {
                    sqlConn.Open();
                }

                trans = sqlConn.BeginTransaction();

                string sql = string.Empty;

                XEquipmentCheckInfo info = model as XEquipmentCheckInfo;
                sql = "Insert Into " + this.TableName + "(RID,EquipmentType,EquipmentCustId,EquipmentName,FactoryNo,Spec,Model,FactoryName,SourceTime,UseTime,SourceCustId,SourceTypeId,EquipmentStatusId,SignStatus,Quanlity,LinkMan,Tel,Email,CheckAccord,LastCheckDate,CheckResult,ValidDate,CertNo,EquipmentDesc,Remark,InputUserId,InputTime,UpdateUserId,UpdateTime,EquipmentNo,BillNo)Values('{0}','{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}')";
                sql = String.Format(sql, info.RID, info.EquipmentType, info.EquipmentCustId, info.EquipmentName, info.FactoryNo, info.Spec, info.Model, info.FactoryName, info.SourceTime, info.UseTime, info.SourceCustId, info.SourceTypeId, info.EquipmentStatusId, info.SignStatus, info.Quanlity, info.LinkMan, info.Tel, info.Email, info.CheckAccord, info.LastCheckDate, info.CheckResult, info.ValidDate, info.CertNo, info.EquipmentDesc, info.Remark, info.InputUserId, this.GetServerTimeFuncion(), info.UpdateUserId, this.GetServerTimeFuncion(), info.EquipmentNo, info.BillNo);


                //if (receiveInfo.ReportFileFullName != string.Empty)
                //{
                //    //上传附件
                //    DbCommand fileCommand = this.GetFileCommand(receiveInfo);
                //    fileCommand.Connection = sqlConn;
                //    fileCommand.Transaction = trans;
                //    DbDataReader reader = fileCommand.ExecuteReader();
                //    reader.Close();
                //}

                sql += ";";

                //XEquipmentReceiveInfo inforev = modelrev as XEquipmentReceiveInfo;
                XVEquipmentReceiveInfo inforev = FillEquipmentReceiveInfo4Add(model as XVEquipmentCheckInfo, userId);
                string sql2 = GetInsertSql4rev(inforev);

                sql = sql + sql2;


                DbCommand cmd = this.m_DataAccess.GetDbCommand();
                cmd.Connection  = sqlConn;
                cmd.CommandText = sql;
                cmd.Transaction = trans;
                bool isSuccess = cmd.ExecuteNonQuery() > 0;
                trans.Commit();

                return(isSuccess);
            }
            catch (Exception ex)
            {
                XMessageBox.ShowError(ex.Message);
                XErrorLogTool.WriteLog(ex.ToString());
                trans.Rollback();
            }
            finally
            {
                if (sqlConn.State == ConnectionState.Open)
                {
                    sqlConn.Close();
                }
            }

            return(false);
        }
Ejemplo n.º 30
0
        public string DownLoadFile(string fileId, string filePath, string fileName)
        {
            string        sql  = "SELECT AtchImag,AtchName,AtchType FROM " + this.TableName + " WHERE FileId = '" + fileId + "'";
            DbConnection  conn = this.m_DataAccess.Connection;
            DbDataAdapter adp  = this.m_DataAccess.GetDbDataAdapter(conn, sql);
            DataTable     dt   = new DataTable();

            byte[] bData = null;
            string fName = fileName;

            try
            {
                //从服务器获取文件
                adp.Fill(dt);
                DataRow dr = null;
                if (dt.Rows.Count > 0)
                {
                    dr = dt.Rows[0];
                    if (((!object.ReferenceEquals(dr["AtchImag"], DBNull.Value))))
                    {
                        bData = (byte[])dr["AtchImag"];
                    }
                    if (fName == string.Empty)
                    {
                        fName = XHelper.GetString(dr["AtchName"]);
                    }
                    else
                    {
                        fName += XHelper.GetString(dr["AtchType"]);
                    }
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                XErrorLogTool.WriteLog(ex.ToString());
                return(string.Empty);
            }
            finally
            {
                adp.Dispose();
            }

            //存文件
            if (((bData != null)))
            {
                if (filePath == System.Windows.Forms.Application.StartupPath + "\\WssTemp")
                {
                    if (Directory.Exists(filePath))
                    {
                        string[] fileNames = Directory.GetFiles(filePath);
                        foreach (string deleteFileName in fileNames)
                        {
                            try
                            {
                                File.Delete(deleteFileName);
                            }
                            catch (Exception ex)
                            {
                                XErrorLogTool.WriteLog(ex.ToString());
                            }
                        }
                    }
                }

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }

                fName = filePath + "\\" + fName;
                FileInfo fi = new FileInfo(fName);
                //不存在
                if (!fi.Exists)
                {
                    using (FileStream fs = fi.Create())
                    {
                        fs.Write(bData, 0, bData.Length);
                    }
                }
                else
                {
                    XMessageBox.ShowError("要下载的文件:[" + fi.Name + "]在目录:\r\n" + filePath + "已存在!");
                    return(string.Empty);
                }
            }
            return(fName);
        }