Ejemplo n.º 1
0
        private DbCommand GetFileCommand(XVStandFilesInfo fileInfo)
        {
            string fileDesc = string.Empty;

            string fileName = fileInfo.FileFullName;

            FileInfo fi = new FileInfo(fileName);

            double fileSize = 0;

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

            byte[] bData = XHelper.GetFileBytes(fileName);

            string fileId = fileInfo.RID;

            string sql = "DELETE FROM FileAttachment WHERE FileId='" + fileId + "';";

            sql += "INSERT INTO FileAttachment (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.CommandText = sql;

            DbParameter parameterId = this.m_DataAccess.GetParameter("@RId", Guid.NewGuid().ToString());

            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", fileInfo.UpdateUserId);

            cmd.Parameters.Add(parameterUser);

            return(cmd);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 填充实体信息
        /// </summary>
        protected override void FillModelInfo()
        {
            XVStandFilesCheckRecordInfo info = this.m_CurrentModel as XVStandFilesCheckRecordInfo;

            if (this.m_EditStatus == XEditStatus.AddNew || this.m_EditStatus == XEditStatus.AddContinue)
            {
                info.RID = this.GetNewId();
            }

            info.StandFileId = this.txtStandFileId.ValueMember;
            info.FileName    = this.txtStandFileId.DisplayMember;
            if (this.txtStandFileId.SelectedModel != null)
            {
                XVStandFilesInfo fileInfos = this.txtStandFileId.SelectedModel as XVStandFilesInfo;

                info.StandName = fileInfos.StandName;
                info.StandId   = fileInfos.MainId;
            }
            info.CheckUserName = this.txtCheckUserName.Text;
            info.CheckDesc     = this.txtCheckDesc.Text;
            info.CheckDate     = XHelper.GetFormatedDate(this.dtCheckDate.Value);
            info.NextCheckDate = XHelper.GetFormatedDate(this.dtNextCheckDate.Value);
            info.Remark        = this.txtRemark.Text;

            base.FillModelInfo();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 设置修改时的默认值
        /// </summary>
        protected override void SetDefaultValue()
        {
            XVStandFilesInfo info = this.m_CurrentModel as XVStandFilesInfo;

            if (info.MainId != string.Empty)
            {
                this.txtMainId.Text          = info.StandName;
                this.txtMainId.DisplayMember = info.StandName;
                this.txtMainId.ValueMember   = info.MainId;
            }
            this.txtFileName.Text        = info.FileName;
            this.txtFileNo.Text          = info.FileNo;
            this.txtFileDesc.Text        = info.FileDesc;
            this.txtRemark.Text          = info.Remark;
            this.chkIsMaxVersion.Checked = info.IsMaxVersion;
            this.chkIsNeedCheck.Checked  = info.IsNeedCheck;
            this.dtNextCheckDate.Value   = XHelper.GetDateTime(info.NextCheckDate);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 填充实体信息
        /// </summary>
        protected override void FillModelInfo()
        {
            XVStandFilesInfo info = this.m_CurrentModel as XVStandFilesInfo;

            if (this.m_EditStatus == XEditStatus.AddNew)
            {
                info.RID = this.GetNewId();
            }

            info.MainId       = this.txtMainId.ValueMember;
            info.StandName    = this.txtMainId.DisplayMember;
            info.FileName     = this.txtFileName.Text;
            info.FileNo       = this.txtFileNo.Text;
            info.FileDesc     = this.txtFileDesc.Text;
            info.Remark       = this.txtRemark.Text;
            info.IsMaxVersion = this.chkIsMaxVersion.Checked;

            info.FileFullName  = this.txtFilePath.Text.Trim();
            info.IsNeedCheck   = this.chkIsNeedCheck.Checked;
            info.NextCheckDate = XHelper.GetFormatedDate(this.dtNextCheckDate.Value);

            base.FillModelInfo();
        }
Ejemplo n.º 5
0
        protected override void FillRowViewInfos(XModelBase model, System.Data.DataRow modelRow)
        {
            XVStandFilesInfo standInfo = model as XVStandFilesInfo;

            standInfo.StandName = XHelper.GetString(modelRow["StandName"]);
        }
Ejemplo n.º 6
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);
        }