コード例 #1
0
        private void calculate_mileage()
        {
            //make sure data is commited
            updateLineItems();
            //loop through each
            double mileageValue = 0;
            //foreach (DataGridViewRow row in dgvItems.Rows)
            //{

            calculations calculations = new calculations();

            calculations.mileage(/*Convert.ToInt32(rowdgvItems.Rows[0].Cells[0].Value),*/ quoteNumber); //i dont need to loop through this i think...
            mileageValue = mileageValue + calculations._mileageTotal;

            //}


            //use this figure to update total
            string sql = "UPDATE dbo.slimline_install_quote SET mileage_cost = " + mileageValue.ToString() + "WHERE id = " + quoteNumber.ToString();

            using (SqlConnection conn = new SqlConnection(CONNECT.ConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                    cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
コード例 #2
0
        private void updateLineItems()  //look at all of the variables and update based on this
        {
            string sql = "UPDATE dbo.slimline_install_quote SET site_address_1 = '" + txtSiteAddress1.Text + "', site_address_2 = '" + txtSiteAddress2.Text + "'," +
                         "site_address_3 = '" + txtSiteAddress3.Text + "',post_code = '" + txtPostCode.Text + "',county = '" + txtCounty.Text + "' WHERE id = " + quoteNumber;

            using (SqlConnection conn = new SqlConnection(CONNECT.ConnectionString))
            {
                conn.Open();

                using (SqlCommand cmd = new SqlCommand(sql, conn))
                    cmd.ExecuteNonQuery();
                // ^^^^^^^^^^ updates the site address
                if (buttonPressed == -1)
                {
                    buttonString();  //generate the string
                    sql = "Update dbo.slimline_install_quote SET " + sqlButton + " WHERE id = " + quoteNumber;
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                        cmd.ExecuteNonQuery();
                    // MessageBox.Show(sqlButton);
                }
                if (updateMiles == -1)
                {
                    sql = "UPDATE dbo.slimline_install_quote SET mileage_one_way = '" + txtMiles.Text + "', site_visits = '" + txtVisits.Text + "',total_mileage = '" + txtTotalMiles.Text + "', london = " + Convert.ToInt32(chkLondon.Checked).ToString() + " WHERE id = " + quoteNumber.ToString();
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                        cmd.ExecuteNonQuery();
                    updateMiles = -1;
                }
                ////now update every line item
                if (buttonPressed == -1)
                {
                    sql = "UPDATE dbo.slimline_install_door SET " + sqlButton + " WHERE quote_id = " + quoteNumber;
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                        cmd.ExecuteNonQuery();
                    //MessageBox.Show(sqlButton);
                    buttonPressed = 0;
                }
                loaddgv(); //also need to recalculate the maths on this..

                for (int i = 0; i < dgvItems.Rows.Count; i++)
                {
                    calculations calculations = new calculations();
                    calculations.getValue(Convert.ToInt32(dgvItems.Rows[i].Cells[0].Value));
                    double temp = Convert.ToDouble(calculations._totalValue.ToString());
                    // * this by the qty
                    temp = temp * Convert.ToDouble(dgvItems.Rows[i].Cells[13].Value.ToString());
                    sql  = "UPDATE dbo.slimline_install_door SET total_value = " + temp + " WHERE id = " + dgvItems.Rows[i].Cells[0].Value.ToString();
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                        cmd.ExecuteNonQuery();
                }

                // i think a loaddgv here will stop it from not adding correct value
                loaddgv();


                //i think we also need to update the sumTotal of quote while we are here...
                double sumTotal = 0;
                for (int i = 0; i < dgvItems.Rows.Count; i++)
                {
                    if (Convert.ToString(dgvItems.Rows[i].Cells[15].Value) != "")
                    {
                        string temp = Convert.ToString(dgvItems.Rows[i].Cells[15].Value);
                        temp     = temp.Substring(1, temp.Length - 1);
                        sumTotal = sumTotal + Convert.ToDouble(temp);
                    }
                }
                if (sumTotal > 0)
                {
                    sql = "UPDATE dbo.slimline_install_quote SET sumTotal = " + sumTotal + "WHERE id = " + quoteNumber;
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }

                conn.Close();
                loaddgv();
            }
        }