public static bool updateCrop(CropFarmer c)
        {
            bool status = false;

            try
            {
                using (MySqlConnection con = new MySqlConnection(connString)) //DI via Constructor
                {
                    if (con.State == ConnectionState.Closed)                  //if connection is closed?
                    {
                        con.Open();
                    }
                    string       query = "Update cropfarmerxref set qty_left = '" + c.qty_left + "',added_on='" + c.added_on + "' Where  cropid='" + c.cid + "'";
                    MySqlCommand cmd   = new MySqlCommand(query, con);
                    //cmd.Parameters.Add(new MySqlParameter("@default", default));
                    cmd.ExecuteNonQuery();
                    con.Close();
                    status = true;
                }
            }
            catch (MySqlException exp)
            {
                string message = exp.Message;
            }
            return(status);
        }
Exemplo n.º 2
0
        public ActionResult Update(int cid, string crop_name, int quantity, int unit_price)
        {
            if (Session["UserData"] != null)
            {
                int id = int.Parse(Session["UserData"].ToString());

                CropFarmer c = new CropFarmer
                {
                    fid      = id,
                    cid      = cid,
                    added_on = DateTime.Now,
                    qty_left = quantity
                };
                crops c1            = BusinessManager.getcrop(cid);
                int   totalquantity = c1.quantity + c.qty_left;
                c.qty_left = totalquantity;
                BusinessManager.updateCrop(c);
                bool status = BusinessManager.updateCropquantity(cid, totalquantity);
                if (status)
                {
                    return(RedirectToAction("displayAllCrops", "crops"));
                }
                else
                {
                    return(View());
                }
            }
            return(RedirectToAction("loginfarmerdis", "farmers"));
        }
Exemplo n.º 3
0
        public ActionResult RegisterCrops(int cid, int quantity, int unit_price)
        {
            if (Session["UserData"] != null)
            {
                int id = int.Parse(Session["UserData"].ToString());

                //            bool status = BusinessManager.AddCrop(c);
                DateTime          date          = DateTime.Now;
                int               totalquantity = 0;
                crops             c             = new crops();
                List <CropFarmer> cf            = BusinessManager.getcropfarmerByID(id);
                foreach (CropFarmer i in cf)
                {
                    if (i.cid == cid)
                    {
                        c             = BusinessManager.getcrop(cid);
                        totalquantity = c.quantity + i.qty_left;
                        i.qty_left    = totalquantity;
                        i.added_on    = DateTime.Now;
                        BusinessManager.updateCrop(i);
                        BusinessManager.updateCropquantity(cid, totalquantity);
                    }
                }
                BusinessManager.AddCrop_xref(id, cid, date, quantity);
                c = BusinessManager.getcrop(cid);
                CropFarmer cf1 = BusinessManager.getcropFarmer(cid);
                totalquantity = c.quantity + cf1.qty_left;
                BusinessManager.updateCropquantity(cid, totalquantity);//main crop table
                return(RedirectToAction("displayAllCrops", "crops"));
            }
            return(RedirectToAction("loginfarmer", "farmers"));
        }
        public static List <CropFarmer> getcropFarmerBYFarmerID(int id)
        {
            List <CropFarmer> listcrop = new List <CropFarmer>();

            IDbConnection conn = new MySqlConnection();

            conn.ConnectionString = connString;
            string     query = "Select * from cropfarmerxref WHERE farmerID=" + id;
            IDbCommand cmd   = new MySqlCommand();

            cmd.CommandText = query;
            cmd.Connection  = conn;
            MySqlDataAdapter da = new MySqlDataAdapter(cmd as MySqlCommand);
            DataSet          ds = new DataSet();

            try
            {
                //cropID, crop_name, added_on, category, description, quantity, unit_price, image

                da.Fill(ds);
                DataRowCollection rows = ds.Tables[0].Rows;
                foreach (DataRow row in rows)
                {
                    CropFarmer thecrops = new CropFarmer();
                    thecrops.cid      = int.Parse(row["cropID"].ToString());
                    thecrops.fid      = int.Parse(row["farmerID"].ToString());
                    thecrops.added_on = DateTime.Parse(row["added_on"].ToString());
                    thecrops.qty_left = int.Parse(row["qty_left"].ToString());
                    listcrop.Add(thecrops);
                }
            }
            catch (MySqlException e)
            {
                string message = e.Message;
            }
            // implementation
            return(listcrop);
        }
 public static bool updateCrop(CropFarmer c)
 {
     return(DBManager.updateCrop(c));
 }