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

📄 check.aspx.cs

📁 asp销售管理系统
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class inventory_check : System.Web.UI.Page
{
    public enum SearchType
    {
        NotSet = -1,
        Browser = 0,
        Insert = 1
    }

    decimal priceTotal = 0;     //本次发料金额总计

    protected void Page_Load(object sender, EventArgs e)
    {
        Message.Text = "";
        if (Session["CheckTable"] == null)
        {
            DataTable myTable = new DataTable();
            myTable.Columns.Add(new DataColumn("CheckItemsID", typeof(string)));
            myTable.Columns.Add(new DataColumn("CheckItemsName", typeof(string)));
            myTable.Columns.Add(new DataColumn("CheckItemsSpecification", typeof(string)));
            myTable.Columns.Add(new DataColumn("CheckItemsUnit", typeof(string)));
            myTable.Columns.Add(new DataColumn("CheckItemsStandardPrice", typeof(decimal)));
            myTable.Columns.Add(new DataColumn("CheckItemsInventory", typeof(decimal)));
            myTable.Columns.Add(new DataColumn("CheckQuantity", typeof(decimal)));
            myTable.Columns.Add(new DataColumn("CheckItemsExtra", typeof(decimal)));
            myTable.Columns.Add(new DataColumn("CheckItemsExtraMoney", typeof(decimal)));
            myTable.Columns.Add(new DataColumn("CheckItemsReason", typeof(int)));
            Session["CheckTable"] = myTable;
        }
        if (!IsPostBack)
        {
            radioBrowser.Checked = true;

            SqlDataSource SqlDataSource2 = FormView1.FindControl("SqlDataSource2") as SqlDataSource;
            SqlDataSource2.SelectParameters["UserName"].DefaultValue = this.User.Identity.Name;

            TextBox DeliveryDateTextBox = FormView1.FindControl("CheckDateTextBox") as TextBox;
            OboutInc.Calendar.Calendar Calendar1 = FormView1.FindControl("Calendar1") as OboutInc.Calendar.Calendar;
            Calendar1.TextBoxId = DeliveryDateTextBox.ClientID;
        }
    }

    /// <summary>
    /// 删除Session中的CheckTable,避免在下一张小票中出现
    /// 注意判断IsPostBack,否则每次PostBack都删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Unload(object sender, EventArgs e)
    {
        if (!IsPostBack && Session["CheckTable"] != null)
        {
            Session["CheckTable"] = null;
        }
    }

    protected void radioButton_CheckedChanged(Object sender, System.EventArgs e)
    {
        if (radioBrowser.Checked)
        {
            MultiView1.ActiveViewIndex = (int)SearchType.Browser;
        }
        else if (radioInsert.Checked)
        {
            MultiView1.ActiveViewIndex = (int)SearchType.Insert;
            GridView3.DataBind();
        }
    }

    protected void radioButtonDetails_CheckedChanged(Object sender, System.EventArgs e)
    {
        RadioButton radioBtn = (RadioButton)sender;
        RadioButton radioBrowserDetails = radioBtn.Parent.FindControl("radioBrowserDetails") as RadioButton;
        RadioButton radioInsertDetails = radioBtn.Parent.FindControl("radioInsertDetails") as RadioButton;

        HtmlTableRow trList = radioBtn.Parent.Parent.FindControl("trList") as HtmlTableRow;
        HtmlTableRow TrNew = radioBtn.Parent.Parent.FindControl("TrNew") as HtmlTableRow;

        if (radioBrowserDetails.Checked)
        {
            GridView myGridView = (GridView)trList.FindControl("GridView1");
            GetCheckItems(myGridView);
            trList.Visible = true;
            TrNew.Visible = false;
        }
        else if (radioInsertDetails.Checked)
        {
            trList.Visible = false;
            GridView myGridView = (GridView)TrNew.FindControl("GridView2");
            GetWarehouseItems(myGridView);
            TrNew.Visible = true;
        }
        //一旦点击“新增”按钮,“仓库”下拉列表马上锁定,以防止用户先用某一仓库添加了
        //一些记录,然后换成其他仓库继续添加,导致错误数据产生。同理,其他公共数据也锁定。
        ((TextBox)TrNew.Parent.FindControl("CheckDateTextBox")).Enabled = false;
        ((OboutInc.Calendar.Calendar)TrNew.Parent.FindControl("Calendar1")).DatePickerButtonText = "";
        //((TextBox)TrNew.Parent.FindControl("CheckIDTextBox")).Enabled = false;
        ((DropDownList)TrNew.Parent.FindControl("DropDownList1")).Enabled = false;
        ((Button)TrNew.Parent.FindControl("btnAuto")).Enabled = false;
        ((LinkButton)FormView1.FindControl("InsertButton")).Enabled = true;
        ((TextBox)FormView1.FindControl("ItemIDTextBox")).Enabled = true;
        ((LinkButton)FormView1.FindControl("LinkButtonSearch")).Enabled = true;
    }

    protected void imgCalendar_Click(object sender, ImageClickEventArgs e)
    {
        Calendar myCalendar = ((ImageButton)sender).Parent.FindControl("Calendar1") as Calendar;
        TextBox txtDate = myCalendar.Parent.FindControl("CheckDateTextBox") as TextBox;
        if (myCalendar != null)
        {
            try
            {
                myCalendar.SelectedDate = DateTime.Parse(txtDate.Text);
            }
            catch (System.FormatException eFormat)
            {

            }
            myCalendar.Visible = !myCalendar.Visible;
        }
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        Calendar myCalendar = (Calendar)sender;
        if (myCalendar != null)
        {
            myCalendar.Visible = !myCalendar.Visible;
            TextBox txtDate = myCalendar.Parent.FindControl("CheckDateTextBox") as TextBox;
            if (txtDate != null)
                txtDate.Text = myCalendar.SelectedDate.ToShortDateString();
        }
    }

    ///ToDo:应该增加适当时候让Calendar消失的代码,例如用户手动改变TextBox内容的时候,
    ///但是试验表明OnTextChanged事件不起作用。
    ///另外,给Calendar控件动态赋SelectedDate显示的时候月份页面不对。

    ///获取仓库ID,以便查询该仓库可以发放的物料  
    protected void DropDownList1_DataBound(object sender, EventArgs e)
    {
        //获取默认选中的仓库ID
        hidWareHouseID.Value = ((DropDownList)sender).SelectedValue;
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        hidWareHouseID.Value = ((DropDownList)sender).SelectedValue;
    }

    /// <summary>
    /// 从Items和Inventory表中查出特定仓库中的所有记录,
    /// 然后和GridView2绑定
    /// ToDo:后面加上条件查询以缩小范围。
    /// </summary>
    /// <param name="myGridView"></param>
    protected void GetWarehouseItems(GridView myGridView)
    {
        DropDownList drpFilterOption = FormView1.FindControl("drpFilterOption") as DropDownList;
        string strOption = drpFilterOption.SelectedValue;

        TextBox ItemIDTextBox = FormView1.FindControl("ItemIDTextBox") as TextBox;
        string strFilter = ItemIDTextBox.Text + "%";

        if (strOption == "ItemID")
            strFilter = "[Items].ItemID Like '" + strFilter + "'";
        else if (strOption == "Name")
            strFilter = "[Items].Name Like '%" + strFilter + "'";
        else
            strFilter = "[Items].Specification Like '%" + strFilter + "'";

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySqlProviderConnection"].ConnectionString);
        string strQuery = "";
        //得到已经增加的物资列表,不再出现
        DataTable myTable = Session["CheckTable"] as DataTable;
        string strCheckItemsID = "";
        for (int i = 0; i < myTable.Rows.Count; i++)
        {
            strCheckItemsID += "'" + myTable.Rows[i][0] + "',";
        }
        if (strCheckItemsID != "")
        {
            //去掉最后一个“,”
            strCheckItemsID = strCheckItemsID.Substring(0, strCheckItemsID.Length - 1);
            strQuery = "SELECT [Items].ItemID, [Items].Name, [Items].Specification, [Items].Unit, [Items].StandardPrice, [Inventory].Quantity" +
               " FROM [Items] Join [Inventory] ON ([Items].ItemID = [Inventory].ItemID ) Where [Inventory].WareHouseID = " +
               Convert.ToInt32(hidWareHouseID.Value) + " And " + strFilter + " And [Items].ItemID Not In (" + strCheckItemsID + ")" +
               " Order by [Items].Name, [Items].Specification";
        }
        else
        {
            strQuery = "SELECT [Items].ItemID, [Items].Name, [Items].Specification, [Items].Unit, [Items].StandardPrice, [Inventory].Quantity" +
               " FROM [Items] Join [Inventory] ON ([Items].ItemID = [Inventory].ItemID ) Where [Inventory].WareHouseID = " +
               Convert.ToInt32(hidWareHouseID.Value) + " And " + strFilter +
               " Order by [Items].Name, [Items].Specification";
        }

        SqlDataAdapter adapter = new SqlDataAdapter(strQuery, con);
        DataSet ds = new DataSet();
        adapter.Fill(ds);

        myGridView.DataSource = ds.Tables[0];
        myGridView.DataBind();
    }

    /// <summary>
    /// 对于库存量为0的物料给予警告:颜色为黄色。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // determine the value of the UnitsInStock field
            decimal unitsInStock =
             Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem,
             "Quantity"));
            if (unitsInStock == 0)
                e.Row.BackColor = System.Drawing.Color.Yellow;
            if (unitsInStock < 0)
                e.Row.BackColor = System.Drawing.Color.LightPink;
        }
    }

    /// <summary>
    /// 选中物资记录,添加该记录,暂时将发料数量设为0,切换到浏览页面,默认编辑模式
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridView myGridView = (GridView)sender;
        //AddCheck(myGridView.SelectedValue.ToString());
        AddCheck(myGridView.SelectedRow);

        RadioButton radioBrowserDetails = myGridView.Parent.Parent.FindControl("radioBrowserDetails") as RadioButton;
        RadioButton radioInsertDetails = myGridView.Parent.Parent.FindControl("radioInsertDetails") as RadioButton;
        radioBrowserDetails.Checked = true;
        radioInsertDetails.Checked = false;

        radioButtonDetails_CheckedChanged(radioBrowserDetails, new EventArgs());

        //列表GridView
        GridView myGridView1 = myGridView.Parent.Parent.FindControl("GridView1") as GridView;
        myGridView1.EditIndex = 0;

⌨️ 快捷键说明

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