Exemplo n.º 1
0
        public ReturnInfo Create(SmartDB dbInstance, ref Model.MeterType info)
        {
            IInfo info2 = _dal.Insert(dbInstance, info);

            info.IsNew   = false;
            info.IsDirty = true;
            return(new ReturnInfo(info2.Code, info2.Message));
        }
Exemplo n.º 2
0
        public override IInfo GetRecord(SmartDB dbInstance, object Id)
        {
            string sQL_GET = this.SQL_GET;

            SqlParameter[] array = new SqlParameter[]
            {
                new SqlParameter(this.PARM_ID, SqlDbType.NVarChar)
            };
            array[0].Value = Id;
            Model.MeterType bizObject = null;
            IInfo           result;

            try
            {
                bool          transactionControl = dbInstance.TransactionControl;
                SqlDataReader sqlDataReader;
                if (transactionControl)
                {
                    sqlDataReader = SqlHelper.ExecuteReader(dbInstance.Transaction, CommandType.StoredProcedure, sQL_GET, array);
                }
                else
                {
                    sqlDataReader = SqlHelper.ExecuteReader(SqlHelper.MyConnectionString, CommandType.StoredProcedure, sQL_GET, array);
                }
                bool hasRows = sqlDataReader.HasRows;
                if (hasRows)
                {
                    sqlDataReader.Read();
                    this.SetInfo(out bizObject, sqlDataReader);
                    result = new ReturnInfo
                    {
                        BizObject = bizObject,
                        Code      = ErrorEnum.NoError
                    };
                }
                else
                {
                    result = new ReturnInfo(ErrorEnum.NoRecord, string.Format("No record found for ID: {0}", Id));
                }
            }
            catch (Exception ex)
            {
                result = new ReturnInfo(ErrorEnum.DataException, ex.Message);
            }
            return(result);
        }
Exemplo n.º 3
0
 protected void SetInfo(out Model.MeterType info, SqlDataReader reader)
 {
     try
     {
         info             = new Model.MeterType();
         info.Id          = CastDBNull.To <int>(reader["Id"], 0);
         info.Description = CastDBNull.To <string>(reader["Description"], "");
         info.CreatedBy   = CastDBNull.To <string>(reader["Createdby"], "");
         info.EditedBy    = CastDBNull.To <string>(reader["Editedby"], "");
         info.DocDate     = CastDBNull.To <DateTime>(reader["DocDate"], DateTime.Now);
         info.Show        = CastDBNull.To <int>(reader["Show"], 1);
         info.IsNew       = false;
         info.IsDirty     = true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 4
0
        public ReturnInfo Update(SmartDB dbInstance, Model.MeterType info)
        {
            IInfo      info2 = _dal.GetRecord(dbInstance, info.Id);
            bool       flag  = info2.Code == ErrorEnum.NoError;
            ReturnInfo result;

            if (flag)
            {
                bool flag2 = (info2.BizObject as Model.MeterType).LockCount == info.LockCount;
                if (!flag2)
                {
                    result = new ReturnInfo(ErrorEnum.ColumnReference, "Record has been changed.");
                    return(result);
                }
                info.LockCount++;
                info2 = _dal.Update(dbInstance, info);
            }
            result = new ReturnInfo(info2.Code, info2.Message, info2.RowsAffected);
            return(result);
        }
Exemplo n.º 5
0
        public ReturnInfo IsValid(Model.MeterType info)
        {
            bool       flag = info.Id == 0 ? false : true;
            ReturnInfo result;

            if (flag)
            {
                result = new ReturnInfo
                {
                    Code      = ErrorEnum.InvalidInput,
                    Message   = "Name cannot be blank.",
                    BizObject = "Name"
                };
            }
            else
            {
                result = new ReturnInfo(ErrorEnum.NoError, "");
            }
            return(result);
        }