Exemple #1
0
        private DbCommand GetFileCommand(XVTaskAttachmentInfo taskAcctachmentInfo)
        {
            string fileDesc = string.Empty;

            string fileName = taskAcctachmentInfo.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 = taskAcctachmentInfo.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", taskAcctachmentInfo.UpdateUserId);

            cmd.Parameters.Add(parameterUser);

            return(cmd);
        }
        /// <summary>
        /// 设置修改时的默认值
        /// </summary>
        protected override void SetDefaultValue()
        {
            XVTaskAttachmentInfo info = this.m_CurrentModel as XVTaskAttachmentInfo;

            this.txtMainId.Text   = info.MainId;
            this.txtFileName.Text = info.FileName;
            this.txtFileDesc.Text = info.FileDesc;
            this.txtRemark.Text   = info.Remark;
        }
Exemple #3
0
 public override void FillDetailMainId(string key, XModelBase detailInfo, XModelBase mainInfo)
 {
     switch (key)
     {
     case "grdFiles":
         //文件集
         XVTaskAttachmentInfo taskAttachInfo = detailInfo as XVTaskAttachmentInfo;
         taskAttachInfo.MainId = mainInfo.ID;
         break;
     }
 }
        /// <summary>
        /// 填充实体信息
        /// </summary>
        protected override void FillModelInfo()
        {
            XVTaskAttachmentInfo info = this.m_CurrentModel as XVTaskAttachmentInfo;

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

            info.MainId   = this.txtMainId.Text;
            info.FileName = this.txtFileName.Text;
            info.FileDesc = this.txtFileDesc.Text;
            info.Remark   = this.txtRemark.Text;

            info.FileFullName = this.txtFilePath.Text.Trim();

            base.FillModelInfo();
        }
Exemple #5
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);
        }