/// <summary>
 /// 添加
 /// </summary>
 /// <param name="itemsEntity">实体</param>
 /// <param name="statusCode">返回状态码</param>
 /// <returns>主键</returns>
 public string Add(BaseItemsEntity itemsEntity, out string statusCode)
 {
     string returnValue = string.Empty;
     // 检查编号是否重复
     if (this.Exists(new KeyValuePair<string, object>(BaseItemsEntity.FieldParentId, itemsEntity.ParentId), new KeyValuePair<string, object>(BaseItemsEntity.FieldCode, itemsEntity.Code)))
     {
         // 编号已重复
         statusCode = StatusCode.ErrorCodeExist.ToString();
     }
     else
     {
         // 检查名称是否重复
         if (this.Exists(new KeyValuePair<string, object>(BaseItemsEntity.FieldParentId, itemsEntity.ParentId), new KeyValuePair<string, object>(BaseItemsEntity.FieldFullName, itemsEntity.FullName)))
         {
             // 名称已重复
             statusCode = StatusCode.ErrorNameExist.ToString();
         }
         else
         {
             returnValue = this.AddEntity(itemsEntity);
             // 运行成功
             statusCode = StatusCode.OKAdd.ToString();
         }
     }
     return returnValue;
 }
Beispiel #2
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="itemsEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>数据表</returns>
        public string Add(BaseUserInfo userInfo, BaseItemsEntity itemsEntity, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
                LogOnService.UserIsLogOn(userInfo);
            #endif

            string returnValue = string.Empty;
            statusCode = string.Empty;
            statusMessage = string.Empty;

            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    string tableName = BaseItemsEntity.TableName;
                    if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                    {
                        tableName = BaseSystemInfo.SystemCode + "Items";
                    }
                    BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo, tableName);
                    // 调用方法,并且返回运行结果
                    returnValue = itemsManager.Add(itemsEntity, out statusCode);
                    statusMessage = itemsManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemsService_Add, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
                BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return returnValue;
        }
Beispiel #3
0
 private void btnDetails_Click(object sender, EventArgs e)
 {
     DataRow dataRow = BaseInterfaceLogic.GetDataGridViewEntity(this.grdItems_);
     BaseItemsEntity itemsEntity = new BaseItemsEntity(dataRow);
     FrmItemDetailsAdmin frmItemDetailsAdmin = new FrmItemDetailsAdmin(itemsEntity.TargetTable);
     // 窗口的弹出位置进行友善化
     if (this.WindowState == FormWindowState.Normal)
     {
         // frmItemsAdmin.Left = this.Left;
         // frmItemsAdmin.Top = this.Top;
         // frmItemsAdmin.Height = this.Height + 40;
     }
     frmItemDetailsAdmin.AllowDetails = false;
     // frmItemDetailsAdmin.AllowSelectItems = false;
     // if (!String.IsNullOrEmpty(itemsEntity.TargetTable))
     // {
         //frmItemsAdmin.TargetTableName = itemsEntity.TargetTable;
     // }
     frmItemDetailsAdmin.ShowDialog(this);
 }
        private void btnCopy_Click(object sender, EventArgs e)
        {
            // 读取数据
            List<BaseItemsEntity> itemsEntites = new List<BaseItemsEntity>();

            foreach (DataGridViewRow dgvRow in grdTargetResource.Rows)
            {
                if ((System.Boolean)(dgvRow.Cells["colSelected"].Value??false))
                {
                    BaseItemsEntity itemsEntity = new BaseItemsEntity();
                    itemsEntity.Id = int.Parse((dgvRow.DataBoundItem as DataRowView).Row["id"].ToString());
                    itemsEntites.Add(itemsEntity);
                }
            }

            //for (int i = 0; i < this.DTTargetResource.Rows.Count; i++)
            //{
            //    if (this.DTTargetResource.Rows[i][BaseBusinessLogic.SelectedColumn].ToString() == true.ToString())
            //    {
            //        BaseItemsEntity itemsEntity = new BaseItemsEntity();
            //        itemsEntity.Id = int.Parse(this.DTTargetResource.Rows[i]["Id"].ToString());
            //        itemsEntites.Add(itemsEntity);
            //    }
            //}
            // 复制到剪切板
            Clipboard.SetData("itemsEntites", itemsEntites);
            this.btnPaste.Enabled = true;
        }
        public DataTable GetDataTableByCode(IDbHelper dbHelper, BaseUserInfo userInfo, string code)
        {
            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
                LogOnService.UserIsLogOn(userInfo);
            #endif

            DataTable dataTable = new DataTable(BaseItemDetailsEntity.TableName);
            BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo);
            // 检查有其他目标数据库表存储了数据
            BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo);
            BaseItemsEntity itemsEntity = new BaseItemsEntity(itemsManager.GetDataTable(new KeyValuePair<string, object>(BaseItemsEntity.FieldCode, code)));
            if (!String.IsNullOrEmpty(itemsEntity.TargetTable))
            {
                itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, itemsEntity.TargetTable);
            }
            // 这里只要有效的,没被删除的
            List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
            parameters.Add(new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldEnabled, 1));
            parameters.Add(new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0));

            dataTable = itemDetailsManager.GetDataTable(parameters, BaseItemDetailsEntity.FieldSortCode);
            dataTable.TableName = itemsEntity.TargetTable;
            return dataTable;
        }
partial         void SetEntityExpand(SQLBuilder sqlBuilder, BaseItemsEntity itemsEntity);
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="itemsEntity">实体</param>
 /// <param name="statusCode">返回状态码</param>
 /// <returns>影响行数</returns>
 public int Update(BaseItemsEntity itemsEntity, out string statusCode)
 {
     int returnValue = 0;
     // 检查是否已被其他人修改
     //if (DbLogic.IsModifed(DbHelper, this.CurrentTableName, itemsEntity.Id, itemsEntity.ModifiedUserId, itemsEntity.ModifiedOn))
     //{
     //    // 数据已经被修改
     //    statusCode = StatusCode.ErrorChanged.ToString();
     //}
     //else
     //{
         // 检查编号是否重复
         if (this.Exists(new KeyValuePair<string, object>(BaseItemsEntity.FieldParentId, itemsEntity.ParentId), new KeyValuePair<string, object>(BaseItemsEntity.FieldCode, itemsEntity.Code), itemsEntity.Id))
         {
             // 编号已重复
             statusCode = StatusCode.ErrorCodeExist.ToString();
         }
         else
         {
             // 检查名称是否重复
             if (this.Exists(new KeyValuePair<string, object>(BaseItemsEntity.FieldParentId, itemsEntity.ParentId), new KeyValuePair<string, object>(BaseItemsEntity.FieldFullName, itemsEntity.FullName), itemsEntity.Id))
             {
                 // 名称已重复
                 statusCode = StatusCode.ErrorNameExist.ToString();
             }
             else
             {
                 returnValue = this.UpdateEntity(itemsEntity);
                 if (returnValue == 1)
                 {
                     statusCode = StatusCode.OKUpdate.ToString();
                 }
                 else
                 {
                     statusCode = StatusCode.ErrorDeleted.ToString();
                 }
             }
         }
     //}
     return returnValue;
 }
Beispiel #8
0
 /// <summary>
 /// 转换数据
 /// </summary>
 private BaseItemsEntity GetEntity()
 {
     BaseItemsEntity itemsEntity = new BaseItemsEntity();
     itemsEntity.ParentId = null;
     itemsEntity.Code = this.txtCode.Text;
     itemsEntity.FullName = this.txtFullName.Text;
     itemsEntity.TargetTable = this.txtTargetTable.Text;
     itemsEntity.IsTree = this.chkIsTree.Checked ? 1 : 0;
     itemsEntity.UseItemCode = this.txtUseItemCode.Text;
     itemsEntity.UseItemName = this.txtUseItemName.Text;
     itemsEntity.UseItemValue = this.txtUseItemValue.Text;
     itemsEntity.Description = this.txtDescription.Text;
     itemsEntity.Enabled = this.chkEnabled.Checked ? 1 : 0;
     itemsEntity.AllowDelete = 1;
     itemsEntity.AllowEdit = 1;
     itemsEntity.DeletionStateCode = 0;
     return itemsEntity;
 }
Beispiel #9
0
 private void grdItems_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 {
     // 当前记录是否允许被删除
     BaseItemsEntity ItemsEntity = new BaseItemsEntity();
     DataRow dataRow = BaseBusinessLogic.GetDataRow(this.DTItems, this.EntityId);
     ItemsEntity.GetFrom(dataRow);
     // 判断是否允许删除
     if (ItemsEntity.AllowDelete == 0)
     {
         MessageBox.Show(AppMessage.MSG0017, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Question);
         e.Cancel = true;
     }
     else
     {
         if (MessageBox.Show(AppMessage.MSG0015, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
         {
             e.Cancel = true;
         }
         else
         {
             // 删除数据
             DotNetService.Instance.ItemsService.Delete(UserInfo, this.TargetTableName, this.EntityId);
         }
     }
 }
 /// <summary>
 /// 获取实体
 /// </summary>
 /// <param name="id">主键</param>
 public BaseItemsEntity GetEntity(string id)
 {
     BaseItemsEntity itemsEntity = new BaseItemsEntity(this.GetDataTable(new KeyValuePair<string, object>(BaseItemsEntity.FieldId, id)));
     return itemsEntity;
 }
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="itemsEntity">实体</param>
 public string AddEntity(BaseItemsEntity itemsEntity)
 {
     string sequence = string.Empty;
     if (itemsEntity.SortCode == 0)
     {
         BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
         sequence = sequenceManager.GetSequence(this.CurrentTableName);
         itemsEntity.SortCode = int.Parse(sequence);
     }
     SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);
     sqlBuilder.BeginInsert(this.CurrentTableName, BaseItemsEntity.FieldId);
     if (!this.Identity)
     {
         sqlBuilder.SetValue(BaseItemsEntity.FieldId, itemsEntity.Id);
     }
     else
     {
         if (!this.ReturnId && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2))
         {
             if (DbHelper.CurrentDbType == DbTypes.Oracle)
             {
                 sqlBuilder.SetFormula(BaseItemsEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
             }
             if (DbHelper.CurrentDbType == DbTypes.DB2)
             {
                 sqlBuilder.SetFormula(BaseItemsEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
             }
         }
         else
         {
             if (this.Identity && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2))
             {
                 if (string.IsNullOrEmpty(sequence))
                 {
                     BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                     sequence = sequenceManager.GetSequence(this.CurrentTableName);
                 }
                 itemsEntity.Id = int.Parse(sequence);
                 sqlBuilder.SetValue(BaseItemsEntity.FieldId, itemsEntity.Id);
             }
         }
     }
     this.SetEntity(sqlBuilder, itemsEntity);
     if (UserInfo != null)
     {
         sqlBuilder.SetValue(BaseItemsEntity.FieldCreateUserId, UserInfo.Id);
         sqlBuilder.SetValue(BaseItemsEntity.FieldCreateBy, UserInfo.RealName);
     }
     sqlBuilder.SetDBNow(BaseItemsEntity.FieldCreateOn);
     if (UserInfo != null)
     {
         sqlBuilder.SetValue(BaseItemsEntity.FieldModifiedUserId, UserInfo.Id);
         sqlBuilder.SetValue(BaseItemsEntity.FieldModifiedBy, UserInfo.RealName);
     }
     sqlBuilder.SetDBNow(BaseItemsEntity.FieldModifiedOn);
     if (DbHelper.CurrentDbType == DbTypes.SqlServer && this.Identity)
     {
         sequence = sqlBuilder.EndInsert().ToString();
     }
     else
     {
         sqlBuilder.EndInsert();
     }
     return sequence;
 }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="itemsEntity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主鍵</param>
 /// <returns>主键</returns>
 public string Add(BaseItemsEntity itemsEntity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return this.AddEntity(itemsEntity);
 }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="itemsEntity">实体</param>
 /// <returns>主键</returns>
 public string Add(BaseItemsEntity itemsEntity)
 {
     return this.AddEntity(itemsEntity);
 }
Beispiel #14
0
 /// <summary>
 /// 批量进行保存
 /// </summary>
 /// <param name="dataTable">数据表</param>
 /// <returns>影响行数</returns>
 public override int BatchSave(DataTable dataTable)
 {
     int returnValue = 0;
     BaseItemsEntity itemsEntity = new BaseItemsEntity();
     foreach (DataRow dataRow in dataTable.Rows)
     {
         // 删除状态
         if (dataRow.RowState == DataRowState.Deleted)
         {
             string id = dataRow[BaseItemsEntity.FieldId, DataRowVersion.Original].ToString();
             if (id.Length > 0)
             {
                 if (itemsEntity.AllowDelete == 1)
                 {
                     returnValue += this.Delete(id);
                 }
             }
         }
         // 被修改过
         if (dataRow.RowState == DataRowState.Modified)
         {
             string id = dataRow[BaseItemsEntity.FieldId, DataRowVersion.Original].ToString();
             if (id.Length > 0)
             {
                 itemsEntity.GetFrom(dataRow);
                 // 判断是否允许编辑
                 if (itemsEntity.AllowEdit == 1)
                 {
                     returnValue += this.UpdateEntity(itemsEntity);
                 }
                 else
                 {
                     // 不允许编辑,但是排序还是允许的
                     returnValue += this.SetProperty(itemsEntity.Id, new KeyValuePair<string, object>(BaseItemsEntity.FieldSortCode, itemsEntity.SortCode));
                 }
             }
         }
         // 添加状态
         if (dataRow.RowState == DataRowState.Added)
         {
             itemsEntity.GetFrom(dataRow);
             returnValue += this.AddEntity(itemsEntity).Length > 0 ? 1 : 0;
         }
         if (dataRow.RowState == DataRowState.Unchanged)
         {
             continue;
         }
         if (dataRow.RowState == DataRowState.Detached)
         {
             continue;
         }
     }
     return returnValue;
 }
Beispiel #15
0
        /// <summary>
        /// 检查批量删除的输入的有效性
        /// </summary>
        /// <returns>允许批量删除</returns>
        private bool CheckInputBatchDelete()
        {
            bool returnValue = false;
            int selectedCount = 0;
            BaseItemsEntity itemsEntity = new BaseItemsEntity();

            foreach (DataGridViewRow dgvRow in grdItems_.Rows)
            {
                DataRow dataRow = (dgvRow.DataBoundItem as DataRowView).Row;
                if (dataRow.RowState != DataRowState.Deleted)
                {
                    if ((System.Boolean)(dgvRow.Cells["colSelected"].Value??false))
                    {
                        // 是否允许删除
                        itemsEntity.GetFrom(dataRow);
                        if (itemsEntity.AllowDelete == 0)
                        {
                            returnValue = false;
                            MessageBox.Show(AppMessage.Format(AppMessage.MSG0018, itemsEntity.FullName), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            // 这里需要直接返回了,不再进行输入交验了。
                            return returnValue;
                        }
                        else
                        {
                            selectedCount++;
                        }
                    }
                }
            }

            //foreach (DataRowView dataRowView in this.DTItems.DefaultView)
            //{
            //    DataRow dataRow = dataRowView.Row;
            //    if (dataRow.RowState != DataRowState.Deleted)
            //    {
            //        if (dataRow["colSelected"].ToString() == true.ToString())
            //        {
            //            // 是否允许删除
            //            itemsEntity.GetFrom(dataRow);
            //            if (itemsEntity.AllowDelete == 0)
            //            {
            //                returnValue = false;
            //                MessageBox.Show(AppMessage.Format(AppMessage.MSG0018, itemsEntity.FullName), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //                // 这里需要直接返回了,不再进行输入交验了。
            //                return returnValue;
            //            }
            //            else
            //            {
            //                selectedCount++;
            //            }
            //        }
            //    }
            //}
            // 有记录被选中了
            returnValue = selectedCount > 0;
            if (!returnValue)
            {
                MessageBox.Show(AppMessage.MSG0024, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return returnValue;
        }
Beispiel #16
0
 /// <summary>
 /// 检查批量输入的有效性
 /// </summary>
 /// <returns>有效</returns>
 private bool CheckInputBatchSave()
 {
     int selectedCount = 0;
     bool returnValue = false;
     foreach (DataRow dataRow in this.DTItems.Rows)
     {
         // 这里判断数据的各种状态
         if (dataRow.RowState == DataRowState.Modified)
         {
             BaseItemsEntity items = new BaseItemsEntity(dataRow);
             if (items.AllowEdit == 0)
             {
                 if ((dataRow[BaseItemsEntity.FieldCode, DataRowVersion.Original] != dataRow[BaseItemsEntity.FieldCode, DataRowVersion.Current]) || (dataRow[BaseItemsEntity.FieldFullName, DataRowVersion.Original]) != dataRow[BaseItemsEntity.FieldFullName, DataRowVersion.Current] || (dataRow[BaseItemsEntity.FieldDescription, DataRowVersion.Original] != dataRow[BaseItemsEntity.FieldDescription, DataRowVersion.Current]))
                 {
                     returnValue = false;
                     MessageBox.Show(AppMessage.Format(AppMessage.MSG0020, AppMessage.MSG9978), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                     // 这里需要直接返回了,不再进行输入交验了。
                     return returnValue;
                 }
             }
             selectedCount++;
         }
         if (dataRow.RowState == DataRowState.Deleted)
         {
             selectedCount++;
         }
     }
     // 有记录被选中了
     returnValue = selectedCount > 0;
     if (!returnValue)
     {
         MessageBox.Show(AppMessage.MSG0004, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     return returnValue;
 }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="itemsEntity">实体</param>
 public int Update(BaseItemsEntity itemsEntity)
 {
     return this.UpdateEntity(itemsEntity);
 }
 /// <summary>
 /// 更新实体
 /// </summary>
 /// <param name="itemsEntity">实体</param>
 public int UpdateEntity(BaseItemsEntity itemsEntity)
 {
     SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);
     sqlBuilder.BeginUpdate(this.CurrentTableName);
     this.SetEntity(sqlBuilder, itemsEntity);
     if (UserInfo != null)
     {
         sqlBuilder.SetValue(BaseItemsEntity.FieldModifiedUserId, UserInfo.Id);
         sqlBuilder.SetValue(BaseItemsEntity.FieldModifiedBy, UserInfo.RealName);
     }
     sqlBuilder.SetDBNow(BaseItemsEntity.FieldModifiedOn);
     sqlBuilder.SetWhere(BaseItemsEntity.FieldId, itemsEntity.Id);
     return sqlBuilder.EndUpdate();
 }
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="itemsEntity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, BaseItemsEntity itemsEntity)
 {
     sqlBuilder.SetValue(BaseItemsEntity.FieldParentId, itemsEntity.ParentId);
     sqlBuilder.SetValue(BaseItemsEntity.FieldCode, itemsEntity.Code);
     sqlBuilder.SetValue(BaseItemsEntity.FieldFullName, itemsEntity.FullName);
     sqlBuilder.SetValue(BaseItemsEntity.FieldTargetTable, itemsEntity.TargetTable);
     sqlBuilder.SetValue(BaseItemsEntity.FieldIsTree, itemsEntity.IsTree);
     sqlBuilder.SetValue(BaseItemsEntity.FieldUseItemCode, itemsEntity.UseItemCode);
     sqlBuilder.SetValue(BaseItemsEntity.FieldUseItemName, itemsEntity.UseItemName);
     sqlBuilder.SetValue(BaseItemsEntity.FieldUseItemValue, itemsEntity.UseItemValue);
     sqlBuilder.SetValue(BaseItemsEntity.FieldAllowEdit, itemsEntity.AllowEdit);
     sqlBuilder.SetValue(BaseItemsEntity.FieldAllowDelete, itemsEntity.AllowDelete);
     sqlBuilder.SetValue(BaseItemsEntity.FieldDeletionStateCode, itemsEntity.DeletionStateCode);
     sqlBuilder.SetValue(BaseItemsEntity.FieldDescription, itemsEntity.Description);
     sqlBuilder.SetValue(BaseItemsEntity.FieldEnabled, itemsEntity.Enabled);
     sqlBuilder.SetValue(BaseItemsEntity.FieldSortCode, itemsEntity.SortCode);
     SetEntityExpand(sqlBuilder, itemsEntity);
 }
Beispiel #20
0
 public FrmItemsAdd(BaseItemsEntity entity)
     : this()
 {
     this.itemsEntity = entity;
 }
Beispiel #21
0
 /// <summary>
 /// 加载窗体
 /// </summary>
 public override void FormOnLoad()
 {
     this.itemsEntity = DotNetService.Instance.ItemsService.GetEntity(UserInfo, this.EntityId);
     // 显示内容
     this.ShowEntity();
     // 设置焦点
     this.ActiveControl = this.txtCode;
     this.txtCode.Focus();
     this.SetControlState();
 }