Пример #1
0
        /// <summary>
        /// 批量进行保存
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <returns>影响行数</returns>
        public override int BatchSave(DataTable dataTable)
        {
            int returnValue = 0;
            BaseItemDetailsEntity itemDetailsEntity = new BaseItemDetailsEntity();

            foreach (DataRow dataRow in dataTable.Rows)
            {
                // 删除状态
                if (dataRow.RowState == DataRowState.Deleted)
                {
                    string id = dataRow[BaseItemDetailsEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        if (itemDetailsEntity.AllowDelete == 1)
                        {
                            returnValue += this.Delete(id);
                        }
                    }
                }
                // 被修改过
                if (dataRow.RowState == DataRowState.Modified)
                {
                    string id = dataRow[BaseItemDetailsEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        itemDetailsEntity.GetFrom(dataRow);
                        // 判断是否允许编辑
                        if (itemDetailsEntity.AllowEdit == 1)
                        {
                            returnValue += this.UpdateEntity(itemDetailsEntity);
                        }
                        else
                        {
                            // 不允许编辑,但是排序还是允许的
                            returnValue += this.SetProperty(id, new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldSortCode, itemDetailsEntity.SortCode));
                        }
                    }
                }
                // 添加状态
                if (dataRow.RowState == DataRowState.Added)
                {
                    itemDetailsEntity.GetFrom(dataRow);
                    returnValue += this.AddEntity(itemDetailsEntity).Length > 0 ? 1 : 0;
                }
                if (dataRow.RowState == DataRowState.Unchanged)
                {
                    continue;
                }
                if (dataRow.RowState == DataRowState.Detached)
                {
                    continue;
                }
            }
            return(returnValue);
        }
Пример #2
0
        private void grdItemDetails_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            // 当前记录是否允许被删除
            BaseItemDetailsEntity ItemDetailsEntity = new BaseItemDetailsEntity();
            DataRow dataRow = BaseBusinessLogic.GetDataRow(this.DTItemDetails, this.EntityId);

            ItemDetailsEntity.GetFrom(dataRow);
            // 判断是否允许删除
            if (ItemDetailsEntity.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.ItemDetailsService.Delete(UserInfo, this.TargetTable, this.EntityId);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>数据表</returns>
        public BaseItemDetailsEntity GetEntityByCode(BaseUserInfo userInfo, string tableName, string code)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            BaseItemDetailsEntity itemDetailsEntity = new BaseItemDetailsEntity();
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                    DataTable datatable = itemDetailsManager.GetDataTable(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldItemCode, code), BaseItemDetailsEntity.FieldSortCode);
                    if ((datatable != null) && (datatable.Rows.Count > 0))
                    {
                        itemDetailsEntity = itemDetailsEntity.GetFrom(datatable.Rows[0]);
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemDetailsService_GetEntity, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(itemDetailsEntity);
        }
Пример #4
0
        /// <summary>
        /// 检查批量删除的输入的有效性
        /// </summary>
        /// <returns>允许批量删除</returns>
        private bool CheckInputBatchDelete()
        {
            bool returnValue   = false;
            int  selectedCount = 0;
            BaseItemDetailsEntity itemDetailsEntity = new BaseItemDetailsEntity();

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

            //foreach (DataRowView dataRowView in this.DTItemDetails.DefaultView)
            //{
            //    DataRow dataRow = dataRowView.Row;
            //    if (dataRow.RowState != DataRowState.Deleted)
            //    {
            //        if (dataRow["colSelected"].ToString() == true.ToString())
            //        {
            //            // 是否允许删除
            //            itemDetailsEntity.GetFrom(dataRow);
            //            if (itemDetailsEntity.AllowDelete == 0)
            //            {
            //                returnValue = false;
            //                MessageBox.Show(AppMessage.Format(AppMessage.MSG0018, itemDetailsEntity.ItemName), 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);
        }