Ejemplo n.º 1
0
        public static int GetMasterClassDefaultFlag()
        {
            try
            {
                using (var conn = new MySqlConnection(Globals.CONN_STR))
                {
                    conn.Open();
                    var sb = new StringBuilder();
                    sb.Append("select class_id from master_class");
                    sb.Append(" where default_flag = 1 order by class_id limit 1 ");

                    var cmd = new MySqlCommand(sb.ToString(), conn);
                    var da  = new MySqlDataAdapter(cmd);

                    var ds = new DataSet();
                    da.Fill(ds);

                    var masterClass = new MasterClass();
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        return(Convert.ToInt32(ds.Tables[0].Rows[0]["class_id"]));
                    }
                    else
                    {
                        return(1);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
 public static bool Insert(MasterClass masterClass)
 {
     try
     {
         using (var conn = new MySqlConnection(Globals.CONN_STR))
         {
             conn.Open();
             var sql = @"INSERT INTO master_class
                         (class_id,
                         class_name,
                         default_flag,
                         active,
                         create_by)
                         VALUES(@class_id,
                         @class_name,
                         @default_flag,
                         @active,
                         @create_by)";
             var cmd = new MySqlCommand(sql, conn);
             cmd.Parameters.AddWithValue("class_id", masterClass.ClassId);
             cmd.Parameters.AddWithValue("class_name", masterClass.ClassName);
             cmd.Parameters.AddWithValue("default_flag", masterClass.DefaultFlag);
             cmd.Parameters.AddWithValue("active", masterClass.Active);
             cmd.Parameters.AddWithValue("create_by", masterClass.CreateBy);
             var affRow = cmd.ExecuteNonQuery();
         }
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 3
0
 public static bool Update(MasterClass masterClass)
 {
     try
     {
         using (var conn = new MySqlConnection(Globals.CONN_STR))
         {
             conn.Open();
             var sql = @"UPDATE master_class
                         SET class_name=@class_name,
                         active=@active,
                         modified_at=CURRENT_TIMESTAMP,
                         modified_by=@modified_by
                         WHERE class_id=@class_id";
             var cmd = new MySqlCommand(sql, conn);
             cmd.Parameters.AddWithValue("class_id", masterClass.ClassId);
             cmd.Parameters.AddWithValue("class_name", masterClass.ClassName);
             cmd.Parameters.AddWithValue("active", masterClass.Active);
             cmd.Parameters.AddWithValue("modified_by", masterClass.ModifiedBy);
             var affRow = cmd.ExecuteNonQuery();
         }
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 4
0
        public static MasterClass GetMasterClass(int class_id)
        {
            try
            {
                using (var conn = new MySqlConnection(Globals.CONN_STR))
                {
                    conn.Open();
                    var sb = new StringBuilder();
                    sb.Append("select * from master_class");
                    sb.Append(" where class_id = @class_id");

                    var cmd = new MySqlCommand(sb.ToString(), conn);
                    cmd.Parameters.AddWithValue("class_id", class_id);
                    var da = new MySqlDataAdapter(cmd);

                    var ds = new DataSet();
                    da.Fill(ds);

                    var masterClass = new MasterClass();
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        return(new MasterClass
                        {
                            ClassId = (int)ds.Tables[0].Rows[0]["class_id"],
                            ClassName = ds.Tables[0].Rows[0]["class_name"].ToString(),
                            DefaultFlag = (bool)ds.Tables[0].Rows[0]["default_flag"],
                            Active = (bool)ds.Tables[0].Rows[0]["active"],
                            CreateAt = (DateTime)ds.Tables[0].Rows[0]["create_at"],
                        });
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }