Exemplo n.º 1
0
        private static fooditem readerDatafooditem(MySqlDataReader reader)
        {
            fooditem objfooditem = new fooditem();

            objfooditem.ITEMID          = Utility.IsValidInt(reader["ITEMID"]);
            objfooditem.ITEMNAME        = Utility.IsValidString(reader["ITEMNAME"]);
            objfooditem.PRICE           = Utility.IsValidInt(reader["PRICE"]);
            objfooditem.ITEMDESCRIPTION = Utility.IsValidString(reader["ITEMDESCRIPTION"]);
            objfooditem.ITEMCATEGORY    = Utility.IsValidString(reader["ITEMCATEGORY"]);

            objfooditem.ITEMSTATUS = Utility.IsValidString(reader["ITEMSTATUS"]);


            return(objfooditem);
        }
Exemplo n.º 2
0
        public static List <fooditem> Getfooditem(string WhereClause, MySqlConnection conn = null)
        {
            fooditem        objfooditem = null;
            List <fooditem> lstfooditem = new List <fooditem>();

            try
            {
                bool            isConnArgNull = (conn != null) ? false : true;
                MySqlConnection connection    = (conn != null) ? conn : PrimaryConnection();
                //MySqlConnection connection = new MySqlConnection("server=132.148.68.125;user id = testusr; password=Testusr123!@#; database=testdatabase");
                tryOpenConnection(connection);
                string sql = "select * from fooditem ";
                if (!string.IsNullOrEmpty(WhereClause))
                {
                    sql += "where " + WhereClause;
                }
                using (MySqlCommand command = new MySqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = sql;
                    using (MySqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                objfooditem = readerDatafooditem(reader);
                                lstfooditem.Add(objfooditem);
                            }
                        }
                        else
                        {
                        }
                    }
                }
                if (isConnArgNull == true)
                {
                    connection.Dispose();
                }
            }
            catch (Exception ex)
            {
            }

            return(lstfooditem);
        }
Exemplo n.º 3
0
        public static string Savefooditem(fooditem objfooditem, MySqlConnection conn = null, MySqlTransaction trans = null)
        {
            string returnMessage = "";
            string sITEMID       = "";

            sITEMID = objfooditem.ITEMID.ToString();
            var templstfooditem = Getfooditem("ITEMID='" + sITEMID + "'", conn);

            try
            {
                bool            isConnArgNull = (conn != null) ? false : true;
                MySqlConnection connection    = (conn != null) ? conn : PrimaryConnection();
                //MySqlConnection connection = new MySqlConnection("server=132.148.68.125;user id = testusr; password=Testusr123!@#; database=testdatabase");
                tryOpenConnection(connection);
                using (MySqlCommand command = new MySqlCommand())
                {
                    string sql;
                    bool   isEdit = true;
                    if (templstfooditem.Count <= 0)
                    {
                        isEdit = false;
                        sql    = @"INSERT INTO fooditem(
                                    ITEMNAME,PRICE,ITEMDESCRIPTION,ITEMSTATUS,ITEMCATEGORY) VALUES(@ITEMNAME,@PRICE,@ITEMDESCRIPTION,@ITEMSTATUS,@ITEMCATEGORY)";
                    }
                    else
                    {
                        sql = @"UPDATE fooditem set ITEMID=@ITEMID,ITEMNAME=@ITEMNAME, PRICE=@PRICE,ITEMDESCRIPTION=@ITEMDESCRIPTION,ITEMCATEGORY=@ITEMCATEGORY,ITEMSTATUS=@ITEMSTATUS WHERE ITEMID=@ITEMID";
                    }
                    if (trans != null)
                    {
                        command.Transaction = trans;
                    }
                    command.Connection  = connection;
                    command.CommandType = CommandType.Text;
                    command.CommandText = sql;
                    if (isEdit)
                    {
                        command.Parameters.AddWithValue("@ITEMID", objfooditem.ITEMID);
                    }
                    command.Parameters.AddWithValue("@ITEMNAME", objfooditem.ITEMNAME);
                    command.Parameters.AddWithValue("@PRICE", objfooditem.PRICE);
                    command.Parameters.AddWithValue("@ITEMDESCRIPTION", objfooditem.ITEMDESCRIPTION);
                    //command.Parameters.AddWithValue("@CATEGORYID", objfooditem.CATEGORYID);
                    command.Parameters.AddWithValue("@ITEMCATEGORY", objfooditem.ITEMCATEGORY);
                    command.Parameters.AddWithValue("@ITEMSTATUS", objfooditem.ITEMSTATUS);
                    int affectedRows = command.ExecuteNonQuery();
                    var lastInsertID = command.LastInsertedId;
                    if (affectedRows > 0)
                    {
                        returnMessage = "OK";
                    }
                    else
                    {
                        returnMessage = Shared.Constants.MSG_ERR_DBSAVE.Text;
                    }
                }

                if (isConnArgNull == true)
                {
                    connection.Dispose();
                }
            }
            catch (Exception ex)
            {
            }

            return(returnMessage);
        }