网格视图计算,下拉列表和文本框。 [英] Grid View Calculation, Drop Down List & Text box.

查看:105
本文介绍了网格视图计算,下拉列表和文本框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计,

我几乎完成了我的项目,只需添加最后一件事。

I've nearly got my project finished and just need to add one final thing.

我有一个带有折旧率的下拉列表,然后是一个文本框,我输入项目的值。

I have a drop down list with the Depreciation Rate and then a Text Box where I enter in the value of the item.

这是报名表,忽略保修和购买日期

Here's the entry form, ignore the warranty and Date of Purchase

我想知道如何进行计算以获得0.75%的折旧率500,将答案放入 

I was wondering how I'd go about doing the calculation to get the 0.75% DEPRECIATION RATE of 500, put that answer into 

总计 折旧 然后在NET BOOK VALUE中从成本价格中获取全部折扣?

TOTAL DEPRECIATION and then in NET BOOK VALUE take the TOTAL DEPRECIATION from the COST PRICE ?

希望这是有道理的,寻找一些一般性的想法,也许还有一些伪代码来帮助我解决这个问题。

Hope this makes sense, looking for some general ideas and maybe some pseudo code to help get my head around it all.

感谢你!

马克。




推荐答案

看到没有人在这里回复是我的C#代码。

Seeing as nobody is replying here is my C# code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web.UI.Adapters;

public partial class ShowEquipment : System.Web.UI.Page
{
    //Connection String taken from my Web.Config File
    string con = ConfigurationManager.ConnectionStrings["MarksDatabaseConnectionString"].ConnectionString;
    SqlConnection sqlcon;

    public void Page_Load(object sender, EventArgs e)
    {
        
        if (!this.IsPostBack)
        {
            
            showgrid();
        }
    }



    public void showgrid()
    {
       //Link to StoredProcedure
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MarksDatabaseConnectionString"].ConnectionString);
        SqlCommand cmd = new SqlCommand("spGetEquipment", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "Equipment");
        GridView1.DataSource = ds;
        GridView1.DataBind(); 

    }

         

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
           GridView1.EditIndex = -1;
           showgrid();
        }
       protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
           GridView1.EditIndex = e.NewEditIndex;
           showgrid();
        }
       protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
       {
           DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1");
           DropDownList ddl1 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList2");
           DropDownList ddl2 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList3");
           DropDownList ddl3 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList4");
           DropDownList ddl5 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList5");
           DropDownList ddl6 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList6");
           DropDownList ddl7 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList7");
           Calendar dt = (Calendar)GridView1.Rows[e.RowIndex].FindControl("DopBox");
           Label lab = (Label)GridView1.Rows[e.RowIndex].FindControl("ID");
           TextBox SerialNumber1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("SerialNumberBox");
           TextBox CostPrice1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("CostBox");
           TextBox TotalDep = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TDBox");
           TextBox NetBV = (TextBox)GridView1.Rows[e.RowIndex].FindControl("NBBox");



           sqlcon = new SqlConnection(con);
           sqlcon.Open();
           string sql = "update Equipment set DeviceType=@DeviceType, Model=@Model, Manufacturer = @Manufacturer, SerialNumber=@SerialNumber , Warrenty = @Warrenty , AssetTag = @AssetTag, DateOfPurchase = @DateOfPurchase, CostPrice = @CostPrice, DepreciationType = @DepreciationType, DepreciationRate = @DepreciationRate , TotalDepreciation = @TotalDepreciation, NetBookValue = @NetBookValue WHERE ID=@ID";

           SqlCommand cmd = new SqlCommand(sql);
           cmd.CommandType = CommandType.Text;
           cmd.Parameters.AddWithValue("@ID", lab.Text);
           cmd.Parameters.AddWithValue("@DeviceType", ddl.SelectedValue.ToString());
           cmd.Parameters.AddWithValue("@Model", ddl1.SelectedValue.ToString());
           cmd.Parameters.AddWithValue("@Manufacturer", ddl2.SelectedValue.ToString());
           cmd.Parameters.AddWithValue("@SerialNumber", SerialNumber1.Text);
           cmd.Parameters.AddWithValue("@Warrenty", ddl3.SelectedValue.ToString());
           cmd.Parameters.AddWithValue("@AssetTag", ddl5.SelectedValue.ToString());
           cmd.Parameters.AddWithValue("@DateOfPurchase", dt.SelectedDate.ToLongDateString());
           cmd.Parameters.AddWithValue("@CostPrice", CostPrice1.Text);
           cmd.Parameters.AddWithValue("@DepreciationType", ddl6.SelectedValue.ToString());
           cmd.Parameters.AddWithValue("@DepreciationRate", ddl7.SelectedValue.ToString());
           cmd.Parameters.AddWithValue("@TotalDepreciation", TotalDep.Text);
           cmd.Parameters.AddWithValue("@NetBookValue", NetBV.Text);
           cmd.Connection = sqlcon;
           cmd.ExecuteNonQuery ();
           GridView1.EditIndex = -1;
          
           showgrid ();
       }

       public DataTable load_devicetype()
       {
          DataTable dt = new DataTable();
          sqlcon = new SqlConnection(con);
          sqlcon.Open();
          string sql = "select * from DeviceType";
          SqlCommand cmd = new SqlCommand(sql);
          cmd.CommandType = CommandType.Text;
          cmd.Connection = sqlcon;
          SqlDataAdapter sd = new SqlDataAdapter(cmd);
          sd.Fill(dt);
          return dt;
       }

       public DataTable load_DOP()
       {
           DataTable dt = new DataTable();
           sqlcon = new SqlConnection(con);
           sqlcon.Open();
           string sql = "select * from DateOfPurchase";
           SqlCommand cmd = new SqlCommand(sql);
           cmd.CommandType = CommandType.Text;
           cmd.Connection = sqlcon;
           SqlDataAdapter sd = new SqlDataAdapter(cmd);
           sd.Fill(dt);
           return dt;
       }
       public DataTable load_totalDep()
       {
           DataTable dt = new DataTable();
           sqlcon = new SqlConnection(con);
           sqlcon.Open();
           string sql = "select * from TotalDepreciation";
           SqlCommand cmd = new SqlCommand(sql);
           cmd.CommandType = CommandType.Text;
           cmd.Connection = sqlcon;
           SqlDataAdapter sd = new SqlDataAdapter(cmd);
           sd.Fill(dt);
           return dt;
       }



       public DataTable load_NBV()
       {
           DataTable dt = new DataTable();
           sqlcon = new SqlConnection(con);
           sqlcon.Open();
           string sql = "select * from NetBookValue";
           SqlCommand cmd = new SqlCommand(sql);
           cmd.CommandType = CommandType.Text;
           cmd.Connection = sqlcon;
           SqlDataAdapter sd = new SqlDataAdapter(cmd);
           sd.Fill(dt);
           return dt;
       }

       public DataTable load_depR()
       {
           DataTable dt = new DataTable();
           sqlcon = new SqlConnection(con);
           sqlcon.Open();
           string sql = "select * from DepriciationRate";
           SqlCommand cmd = new SqlCommand(sql);
           cmd.CommandType = CommandType.Text;
           cmd.Connection = sqlcon;
           SqlDataAdapter sd = new SqlDataAdapter(cmd);
           sd.Fill(dt);
           return dt;
       }

       

       public DataTable load_assetTag()
       {
           DataTable dt = new DataTable();
           sqlcon = new SqlConnection(con);
           sqlcon.Open();
           string sql = "select * from AssetTag";
           SqlCommand cmd = new SqlCommand(sql);
           cmd.CommandType = CommandType.Text;
           cmd.Connection = sqlcon;
           SqlDataAdapter sd = new SqlDataAdapter(cmd);
           sd.Fill(dt);
           return dt;
       }

       public DataTable load_warrenty()
       {
           DataTable dt = new DataTable();
           sqlcon = new SqlConnection(con);
           sqlcon.Open();
           string sql = "select * from Warranty";
           SqlCommand cmd = new SqlCommand(sql);
           cmd.CommandType = CommandType.Text;
           cmd.Connection = sqlcon;
           SqlDataAdapter sd = new SqlDataAdapter(cmd);
           sd.Fill(dt);
           return dt;
       }

        public DataTable load_Serial()
        {
            DataTable dt = new DataTable();
            sqlcon = new SqlConnection(con);
            sqlcon.Open();
            string sql = "SELECT SerialNumber FROM Equipment";
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlcon;
            SqlDataAdapter sd = new SqlDataAdapter(cmd);
            sd.Fill(dt);
            return dt;
        }

        public DataTable load_Cost()
        {
            DataTable dt = new DataTable();
            sqlcon = new SqlConnection(con);
            sqlcon.Open();
            string sql = "SELECT CostPrice FROM Equipment";
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlcon;
            SqlDataAdapter sd = new SqlDataAdapter(cmd);
            sd.Fill(dt);
            return dt;
        }

        public DataTable load_DepT()
        {
            DataTable dt = new DataTable();
            sqlcon = new SqlConnection(con);
            sqlcon.Open();
            string sql = "SELECT * FROM DepreciationType";
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlcon;
            SqlDataAdapter sd = new SqlDataAdapter(cmd);
            sd.Fill(dt);
            return dt;
        }

        public DataTable load_Manufacturer()
        {
            DataTable dt = new DataTable();
            sqlcon = new SqlConnection(con);
            sqlcon.Open();
            string sql = "select * from Manufacturer";
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlcon;
            SqlDataAdapter sd = new SqlDataAdapter(cmd);
            sd.Fill(dt);
            return dt;

        }

    public DataTable load_id()
    {
        DataTable dt = new DataTable();
        sqlcon = new SqlConnection(con);
        sqlcon.Open();
        string sql = "select * from ID";
        SqlCommand cmd = new SqlCommand(sql);
        cmd.CommandType = CommandType.Text;
        cmd.Connection = sqlcon;
        SqlDataAdapter sd = new SqlDataAdapter(cmd);
        sd.Fill(dt);
        return dt;

    }

    public DataTable load_devicemodel()
    {
        DataTable dt = new DataTable();
        sqlcon = new SqlConnection(con);
        sqlcon.Open();
        string sql = "select * from DeviceModel";
        SqlCommand cmd = new SqlCommand(sql);
        cmd.CommandType = CommandType.Text;
        cmd.Connection = sqlcon;
        SqlDataAdapter sd = new SqlDataAdapter(cmd);
        sd.Fill(dt);
        return dt;
    }



    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {

       
          DataRowView drv = e.Row.DataItem as DataRowView;
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if ((e.Row.RowState & DataControlRowState.Edit) > 0)
              {
                  DropDownList dp = (DropDownList)e.Row.FindControl("DropDownList1");
                  DataTable dt = load_devicetype();
                  dp.DataSource = dt;
                  dp.DataTextField = "Description";
                  dp.DataValueField = "ID";
                  dp.DataBind();
                  dp.Items.Add(new ListItem("No selected", "0"));
                  dp.SelectedValue = drv[3].ToString();
            
              }
          }
          
       
            
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if ((e.Row.RowState & DataControlRowState.Edit) > 0)
              {
                  DropDownList dp1 = (DropDownList)e.Row.FindControl("DropDownList2");
                  DataTable dt1 = load_devicemodel();
                  dp1.DataSource = dt1;
                  dp1.DataTextField = "Description";
                  dp1.DataValueField = "ID";
                  dp1.DataBind();
                  dp1.Items.Add(new ListItem("No selected", "0"));
                  dp1.SelectedValue = drv[3].ToString();

              }
          }

          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if ((e.Row.RowState & DataControlRowState.Edit) > 0)
              {
                  DropDownList dp1 = (DropDownList)e.Row.FindControl("DropDownList5");
                  DataTable dt1 = load_assetTag();
                  dp1.DataSource = dt1;
                  dp1.DataTextField = "AssetNumber";
                  dp1.DataValueField = "ID";
                  dp1.DataBind();
                  dp1.Items.Add(new ListItem("No selected", "0"));
                  dp1.SelectedValue = drv[3].ToString();

              }
          }

          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if ((e.Row.RowState & DataControlRowState.Edit) > 0)
              {
                  DropDownList dp1 = (DropDownList)e.Row.FindControl("DropDownList7");
                  DataTable dt1 = load_depR();
                  dp1.DataSource = dt1;
                  dp1.DataTextField = "Description";
                  dp1.DataValueField = "ID";
                  dp1.DataBind();
                  dp1.Items.Add(new ListItem("No selected", "0"));
                  dp1.SelectedValue = drv[3].ToString();

              }
          }

          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if ((e.Row.RowState & DataControlRowState.Edit) > 0)
              {
                  DropDownList dp = (DropDownList)e.Row.FindControl("DropDownList3");
                  DataTable dt = load_Manufacturer();
                  dp.DataSource = dt;
                  dp.DataTextField = "Name";
                  dp.DataValueField = "ID";
                  dp.DataBind();
                  dp.Items.Add(new ListItem("No selected", "0"));
                  dp.SelectedValue = drv[3].ToString();

              }
          }

          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if ((e.Row.RowState & DataControlRowState.Edit) > 0)
              {
                  DropDownList dp = (DropDownList)e.Row.FindControl("DropDownList4");
                  DataTable dt = load_warrenty();
                  dp.DataSource = dt;
                  dp.DataTextField = "YearEnding";
                  dp.DataValueField = "ID";
                  dp.DataBind();
                  dp.Items.Add(new ListItem("No selected", "0"));
                  dp.SelectedValue = drv[3].ToString();

              }
          }

          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if ((e.Row.RowState & DataControlRowState.Edit) > 0)
              {
                  DropDownList dp = (DropDownList)e.Row.FindControl("DropDownList6");
                  DataTable dt = load_DepT();
                  dp.DataSource = dt;
                  dp.DataTextField = "DepriciationType";
                  dp.DataValueField = "ID";
                  dp.DataBind();
                  dp.Items.Add(new ListItem("No selected", "0"));
                  dp.SelectedValue = drv[3].ToString();

              }
          }
       
     }
}
  

请不要只发布链接。 

And please don't just post links. 



  1. 我需要进行计算,以便在选择折旧率时它会花费成本价格,计算它,

  2. 然后将该计算放入TOTAL折旧。

  3. 然后Net Book Value将是Cost Price - Total Depreciation

我对如何做到这一点很困惑。

I'm just confused on how to do it.

谢谢。





这篇关于网格视图计算,下拉列表和文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆