Esempio n. 1
0
 public ActionResult Edit(SubformModel subformModel, int id)
 {
     OrderId = "2";
     try
     {
         using (SqlConnection sqlCon = new SqlConnection(connectionString))
         {
             sqlCon.Open();
             string     query  = "UPDATE [NEWTEMPDB].[dbo].[Subform] SET OrderID = @OrderID,ProductCode=@ProductCode,ProductImage=@ProductImage,Unit=@Unit,Rate=@Rate,Quantity=@Quantity,Amount=@Amount Where SubformID = @SubformId";
             SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
             sqlCmd.Parameters.AddWithValue("@SubformID", id);
             sqlCmd.Parameters.AddWithValue("@OrderID", OrderId);
             sqlCmd.Parameters.AddWithValue("@ProductCode", subformModel.ProductCode);
             sqlCmd.Parameters.AddWithValue("@ProductImage", subformModel.ProductImage);
             sqlCmd.Parameters.AddWithValue("@Unit", subformModel.Unit);
             sqlCmd.Parameters.AddWithValue("@Rate", subformModel.Rate);
             sqlCmd.Parameters.AddWithValue("@Quantity", subformModel.Quantity);
             sqlCmd.Parameters.AddWithValue("@Amount", subformModel.Amount);
             sqlCmd.ExecuteNonQuery();
         }
         return(RedirectToAction("SubformGridview/" + OrderId));
     }
     catch (Exception ex)
     {
         ex.ToString();
         return(RedirectToAction("SubformGridview/" + OrderId));
     }
 }
Esempio n. 2
0
        public ActionResult Create(SubformModel subformModel)
        {
            string aOrderId = OrderId;

            aOrderId = "2";
            try
            {
                using (SqlConnection sqlCon = new SqlConnection(connectionString))
                {
                    sqlCon.Open();
                    string     query  = "INSERT INTO [NEWTEMPDB].[dbo].[Subform] VALUES(@OrderID,@ProductCode,@ProductImage,@Unit,@Rate,@Quantity,@Amount)";
                    SqlCommand sqlCmd = new SqlCommand(query, sqlCon);



                    ///viewbag code start
                    ///
                    DataTable      dtblSubform = new DataTable();
                    SqlDataAdapter sqlDaa      = new SqlDataAdapter("SELECT [ProductCode] FROM [NEWTEMPDB].[dbo].[Product]", sqlCon);
                    sqlDaa.Fill(dtblSubform);
                    List <int> ProductCodeList = new List <int>();
                    foreach (DataRow dr in dtblSubform.Rows)
                    {
                        int item1 = dr.Field <int>("ProductCode");
                        ProductCodeList.Add(item1);
                        SelectList list = new SelectList(ProductCodeList, "", "");
                        ViewBag.ProductCodeList = list;
                    }
                    //viewbag code end
                    sqlCmd.Parameters.AddWithValue("@SubformID", subformModel.SubformID);
                    sqlCmd.Parameters.AddWithValue("@OrderID", aOrderId);
                    //sqlCmd.Parameters.AddWithValue("@OrderID", subformModel.OrderID);
                    sqlCmd.Parameters.AddWithValue("@ProductCode", subformModel.ProductCode);
                    sqlCmd.Parameters.AddWithValue("@ProductImage", subformModel.ProductImage);
                    sqlCmd.Parameters.AddWithValue("@Unit", subformModel.Unit);
                    sqlCmd.Parameters.AddWithValue("@Rate", subformModel.Rate);
                    sqlCmd.Parameters.AddWithValue("@Quantity", subformModel.Quantity);
                    sqlCmd.Parameters.AddWithValue("@Amount", subformModel.Amount);
                    sqlCmd.ExecuteNonQuery();
                }
                return(RedirectToAction("SubformGridview/" + OrderId));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Esempio n. 3
0
        public ActionResult Edit(int id)
        {
            SubformModel subformModel = new SubformModel();
            DataTable    dtblSubform  = new DataTable();

            using (SqlConnection sqlCon = new SqlConnection(connectionString))
            {
                sqlCon.Open();


                //viewbag code start
                DataTable      dtblProductCode = new DataTable();
                SqlDataAdapter sqlDaa          = new SqlDataAdapter("SELECT [ProductCode] FROM [NEWTEMPDB].[dbo].[Product]", sqlCon);
                sqlDaa.Fill(dtblProductCode);
                List <int> ProductCodeList = new List <int>();
                foreach (DataRow dr in dtblProductCode.Rows)
                {
                    int item1 = dr.Field <int>("ProductCode");
                    ProductCodeList.Add(item1);
                    SelectList list = new SelectList(ProductCodeList, "", "");
                    ViewBag.ProductCodeList = list;
                }
                //viewbag code end

                string         query = " SELECT * FROM [NEWTEMPDB].[dbo].[Subform] Where SubformID = " + id + "";
                SqlDataAdapter sqlDa = new SqlDataAdapter(query, sqlCon);
                sqlDa.SelectCommand.Parameters.AddWithValue("@SubformID ", id);
                sqlDa.Fill(dtblSubform);
            }
            if (dtblSubform.Rows.Count == 1)
            {
                subformModel.OrderID      = dtblSubform.Rows[0][1].ToString();
                subformModel.ProductCode  = Convert.ToInt32(dtblSubform.Rows[0][2].ToString());
                subformModel.ProductImage = Convert.ToInt32(dtblSubform.Rows[0][3].ToString());
                subformModel.Unit         = Convert.ToInt32(dtblSubform.Rows[0][4].ToString());
                subformModel.Rate         = Convert.ToInt32(dtblSubform.Rows[0][5].ToString());
                subformModel.Quantity     = Convert.ToInt32(dtblSubform.Rows[0][6].ToString());
                subformModel.Amount       = Convert.ToInt32(dtblSubform.Rows[0][7].ToString());
                return(View(subformModel));
            }
            else
            {
                return(RedirectToAction("SubformGridview/" + OrderId));
            }
        }