Exemplo n.º 1
0
        public static ProductGroup GetProductGroup(string product_group_code)
        {
            try
            {
                using (var conn = new MySqlConnection(Globals.CONN_STR))
                {
                    conn.Open();
                    var sb = new StringBuilder();
                    sb.Append("select * from product_group");
                    sb.Append(" where product_group_code = @product_group_code");

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

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

                    var farm = new ProductGroup();
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        return(new ProductGroup
                        {
                            ProductGroupCode = (int)ds.Tables[0].Rows[0]["product_group_code"],
                            ProductGroupName = ds.Tables[0].Rows[0]["product_group_name"].ToString(),
                            Active = (bool)ds.Tables[0].Rows[0]["active"],
                            CreateAt = (DateTime)ds.Tables[0].Rows[0]["create_at"],
                        });
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }