⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editprice_direct.aspx.cs

📁 简单的Web平台。能够读取Excel文件
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Drawing;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class EditPrice_Direct : System.Web.UI.Page
{
    #region 事件处理函数
    protected void Page_Load(object sender, EventArgs e)
    {
        if ( !Page.IsPostBack )
        {
            hidVersion.Value = Request.QueryString["version"];
            hidModels.Value = Request.QueryString["models"];
            
            string strSQL_PriceInfo = "SELECT * FROM priceInfo INNER JOIN level ON priceInfo.价格层次=level.级别层次 WHERE 价格版本号 LIKE '" + hidVersion.Value + "'";
            DBConnector dbConn = new DBConnector();
            DataSet dsPriceInfo = dbConn.Query(strSQL_PriceInfo);
            /*
            txtPriceName.Text = dsPriceInfo.Tables[0].Rows[0]["价格名称"].ToString();

            txtLevel.Text = dsPriceInfo.Tables[0].Rows[0]["级别名称"].ToString();

            int iStatus = Convert.ToInt32(dsPriceInfo.Tables[0].Rows[0]["状态"].ToString());
            if (1 == iStatus)
                txtStatus.Text = "制作中";
            else if (2 == iStatus)
                txtStatus.Text = "已完成";
            else if (3 == iStatus)
                txtStatus.Text = "已发布";
            else
                txtStatus.Text = "已废弃";

            txtImpUpper.Text = dsPriceInfo.Tables[0].Rows[0]["导入上限"].ToString();
            txtImpLower.Text = dsPriceInfo.Tables[0].Rows[0]["导入下限"].ToString();

            txtPrcUpper.Text = dsPriceInfo.Tables[0].Rows[0]["波动上限"].ToString();
            txtPrcLower.Text = dsPriceInfo.Tables[0].Rows[0]["波动下限"].ToString();

            txtRemark.Text = dsPriceInfo.Tables[0].Rows[0]["备注"].ToString();
            */
            hidTableName.Value = dsPriceInfo.Tables[0].Rows[0]["数据表名称"].ToString();
            
            GridDataBind();
        }
    }

    /// <summary>
    /// 查询价格
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        GridDataBind();        
    }

    /// <summary>
    /// 编辑价格
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvPrice_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvPrice.EditIndex = e.NewEditIndex;
        GridDataBind();
    }
    
    /// <summary>
    /// 取消价格编辑
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvPrice_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvPrice.EditIndex = -1;
        GridDataBind();
    }

    /// <summary>
    /// 数据列的更新
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvPrice_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string id = gvPrice.DataKeys[e.RowIndex].Values[0].ToString();
        string strPrice = ((TextBox)gvPrice.Rows[e.RowIndex].FindControl("txtEditPrice")).Text;
        string strSQL_Update = "UPDATE " +hidTableName.Value+ " SET 单价=" +strPrice+ ",匹配标记=4 WHERE ID=" + id;

        DBConnector dbConn = new DBConnector();
        dbConn.Execute( strSQL_Update );

        gvPrice.EditIndex = -1;
        GridDataBind();
    }

    /// <summary>
    /// 数据列的更新
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvPrice_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {

    }

    /// <summary>
    /// GridView分页操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvPrice_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        /*
        GridView theGrid = sender as GridView; // refer to the GridView
        int newPageIndex = 0;
        if (-2 == e.NewPageIndex)
        {   // when click the "GO" Button
            TextBox txtNewPageIndex = null;
            //GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
            GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
            //updated at 2006年月日:15:33
            if (null != pagerRow)
            {
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;   // refer to the TextBox with the NewPageIndex value
            }

            if (null != txtNewPageIndex)
            {
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
            }
        }
        else
        {   // when click the first, last, previous and next Button
            newPageIndex = e.NewPageIndex;
        }
        // check to prevent form the NewPageIndex out of the range
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
        // specify the NewPageIndex
        theGrid.PageIndex = newPageIndex;
        theGrid.DataBind();
        // rebind the control
        // in this case of retrieving the data using the xxxDataSoucr control,
        // just do nothing, because the asp.net engine binds the data automatically
        */

        GridView theGrid = this.gvPrice;
        int newPageIndex = 0;
        if (-2 == e.NewPageIndex)
        {  
            TextBox txtNewPageIndex = null;            
            GridViewRow pagerRow = theGrid.BottomPagerRow;            
            if (null != pagerRow)
            {
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;   // refer to the TextBox with the NewPageIndex value
            }

            if (null != txtNewPageIndex)
            {
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
            }
        }
        else
        {
            newPageIndex = e.NewPageIndex;
        }
        
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
        
        theGrid.PageIndex = newPageIndex;
        
        GridDataBind();
    }

    #endregion
   
    #region 用户定义函数

    /// <summary>
    /// GridView数据的绑定
    /// </summary>
    private void GridDataBind()
    {
        string strModels = hidModels.Value;         // 所属车系
        string[] aryModels = strModels.Split(',');
        string strQueryCondition = "(";
        for (int i = 0; i < aryModels.Length; i++)
        {
            aryModels[i] = "'" + aryModels[i] + "',";
            strQueryCondition += aryModels[i];
        }
        strQueryCondition = strQueryCondition.Remove(strQueryCondition.Length - 1, 1);
        strQueryCondition += ")";

        string strSQL_Price = "SELECT ID,零件编号,单价,MakeName,ModelName,p.备注,p.导入标记,p.匹配标记 FROM " + hidTableName.Value + " p " +
                                " INNER JOIN Make ON p.厂牌编号=Make.MakeCode " +
                                " INNER JOIN Model ON p.所属车系=Model.ModelCode " +
                                " WHERE p.所属车系 IN " + strQueryCondition;

        if ( "0" == ddlQueryRange.SelectedValue )
        {
            strSQL_Price += " AND 导入标记=1";
        }
        else if ("1" == ddlQueryRange.SelectedValue)
        {
            strSQL_Price += " AND 导入标记=0";
        }

        if ( "0" == ddlEdit.SelectedValue )
        {
            strSQL_Price += " AND 匹配标记=4";
        }
        else if ( "1" == ddlEdit.SelectedValue )
        {
            strSQL_Price += " AND 匹配标记=0";
        }

        string strPartNum = txtPartCode.Text;
        strPartNum = strPartNum.Trim();
        if ( string.Empty != strPartNum )
        {
            if ( ckbBlur.Checked )
            {
                strPartNum = "%" + strPartNum + "%";
            }

            strSQL_Price += " AND 零件编号 LIKE '" + strPartNum + "'";
        }

        DBConnector dbConn = new DBConnector();
        DataSet dsPrice = dbConn.Query(strSQL_Price);
        gvPrice.DataSource = dsPrice;
        gvPrice.DataBind();
    }

    #endregion

    protected void gvPrice_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int iImportFlag = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "导入标记"));
            if (1 == iImportFlag)
            {
                e.Row.BackColor = Color.Yellow;
            }

            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                if ("-1" == e.Row.Cells[i].Text)
                {
                    e.Row.Cells[i].Text = "无";
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -