public int Insert(COAGroup cOAGroup)
        {
            InsertCommand.Parameters["@AccountCategoryName"].Value = cOAGroup.AccountCategoryName;
            InsertCommand.Parameters["@AccountCategoryID"].Value   = cOAGroup.AccountCategoryID;
            InsertCommand.Parameters["@IsExpense"].Value           = cOAGroup.IsExpense;
            InsertCommand.Parameters["@GroupName"].Value           = cOAGroup.GroupName;
            InsertCommand.Parameters["@Code"].Value            = cOAGroup.Code;
            InsertCommand.Parameters["@ParentGroupID"].Value   = cOAGroup.ParentGroupID;
            InsertCommand.Parameters["@ParentGroupName"].Value = cOAGroup.ParentGroupName;
            InsertCommand.Parameters["@Status"].Value          = cOAGroup.Status;


            int returnValue = -1;

            try
            {
                InsertCommand.Connection.Open();
                returnValue = (int)InsertCommand.ExecuteScalar();
            }
            catch (SqlException ex)
            {
                Logger.Write(ex);
            }
            finally
            {
                InsertCommand.Connection.Close();
            }
            return(returnValue);
        }
        public int Update(COAGroup cOAGroup)
        {
            UpdateCommand.Parameters["@ID"].Value = cOAGroup.ID;
            UpdateCommand.Parameters["@AccountCategoryName"].Value = cOAGroup.AccountCategoryName;
            UpdateCommand.Parameters["@AccountCategoryID"].Value   = cOAGroup.AccountCategoryID;
            UpdateCommand.Parameters["@IsExpense"].Value           = cOAGroup.IsExpense;
            UpdateCommand.Parameters["@GroupName"].Value           = cOAGroup.GroupName;
            UpdateCommand.Parameters["@Code"].Value            = cOAGroup.Code;
            UpdateCommand.Parameters["@ParentGroupID"].Value   = cOAGroup.ParentGroupID;
            UpdateCommand.Parameters["@ParentGroupName"].Value = cOAGroup.ParentGroupName;
            UpdateCommand.Parameters["@Status"].Value          = cOAGroup.Status;

            int returnValue = -1;

            try
            {
                UpdateCommand.Connection.Open();
                returnValue = UpdateCommand.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                Logger.Write(ex);
            }
            finally
            {
                UpdateCommand.Connection.Close();
            }
            return(returnValue);
        }
Exemple #3
0
        public static List <COAGroup> GetCOAGroup()
        {
            var dbUtil = new DatabaseManager();
            var groups = new List <COAGroup>();

            using (var conn = new SqlConnection(dbUtil.getSQLConnectionString("MainDB")))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandType    = CommandType.StoredProcedure;
                    cmd.CommandText    = "spGetCOAGroup";
                    cmd.CommandTimeout = 180;

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var group = new COAGroup
                            {
                                GroupID     = ReferenceEquals(reader["intGroupID"], DBNull.Value) ? 0 : (int)reader["intGroupID"],
                                Description = ReferenceEquals(reader["strDescription"], DBNull.Value) ? String.Empty : (string)reader["strDescription"]
                            };

                            groups.Add(group);
                        }

                        return(groups);
                    }
                }
            }
        }
        private COAGroup DataTableToEntity(DataTable dt)
        {
            COAGroup cOAGroup = new COAGroup();

            if (Null.IsNotNull(dt) == true && dt.Rows.Count > 0)
            {
                if (Null.IsNotNull(dt.Rows[0]))
                {
                    DataRow dr = dt.Rows[0];
                    if (Null.IsNotNull(dr["ID"]))
                    {
                        cOAGroup.ID = Convert.ToInt32(dr["ID"]);
                    }
                    else
                    {
                        cOAGroup.ID = 0;
                    }
                    if (Null.IsNotNull(dr["AccountCategoryName"]))
                    {
                        cOAGroup.AccountCategoryName = Convert.ToString(dr["AccountCategoryName"]);
                    }
                    else
                    {
                        cOAGroup.AccountCategoryName = string.Empty;
                    }
                    if (Null.IsNotNull(dr["AccountCategoryID"]))
                    {
                        cOAGroup.AccountCategoryID = Convert.ToInt32(dr["AccountCategoryID"]);
                    }
                    else
                    {
                        cOAGroup.AccountCategoryID = 0;
                    }
                    if (Null.IsNotNull(dr["IsExpense"]))
                    {
                        cOAGroup.IsExpense = Convert.ToString(dr["IsExpense"]);
                    }
                    else
                    {
                        cOAGroup.IsExpense = string.Empty;
                    }
                    if (Null.IsNotNull(dr["GroupName"]))
                    {
                        cOAGroup.GroupName = Convert.ToString(dr["GroupName"]);
                    }
                    else
                    {
                        cOAGroup.GroupName = string.Empty;
                    }
                    if (Null.IsNotNull(dr["Code"]))
                    {
                        cOAGroup.Code = Convert.ToString(dr["Code"]);
                    }
                    else
                    {
                        cOAGroup.Code = string.Empty;
                    }
                    if (Null.IsNotNull(dr["ParentGroupID"]))
                    {
                        cOAGroup.ParentGroupID = Convert.ToInt32(dr["ParentGroupID"]);
                    }
                    else
                    {
                        cOAGroup.ParentGroupID = 0;
                    }
                    if (Null.IsNotNull(dr["ParentGroupName"]))
                    {
                        cOAGroup.ParentGroupName = Convert.ToString(dr["ParentGroupName"]);
                    }
                    else
                    {
                        cOAGroup.ParentGroupName = string.Empty;
                    }
                    if (Null.IsNotNull(dr["Status"]))
                    {
                        cOAGroup.Status = Convert.ToString(dr["Status"]);
                    }
                    else
                    {
                        cOAGroup.Status = string.Empty;
                    }
                }
            }
            return(cOAGroup);
        }