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

📄 directinbound.aspx.cs

📁 asp销售管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
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 inbound_directInbound : System.Web.UI.Page
{
    public enum SearchType
    {
        NotSet = -1,
        Browser = 1,
        Insert = 0
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Message.Text = "";
        if (Session["ReceiptTable"] == null)
        {
            DataTable myTable = new DataTable();
            myTable.Columns.Add(new DataColumn("ReceiptItemsID", typeof(string)));
            myTable.Columns.Add(new DataColumn("ReceiptItemsName", typeof(string)));
            myTable.Columns.Add(new DataColumn("ReceiptItemsSpecification", typeof(string)));
            myTable.Columns.Add(new DataColumn("ReceiptItemsUnit", typeof(string)));
            myTable.Columns.Add(new DataColumn("ReceiptItemsStandardPrice", typeof(decimal)));
            myTable.Columns.Add(new DataColumn("ReceiptItemsExpectedQuantity", typeof(int)));
            myTable.Columns.Add(new DataColumn("ReceiptItemsPrice", typeof(decimal)));
            myTable.Columns.Add(new DataColumn("ReceiptItemsQuantity", typeof(int)));
            Session["ReceiptTable"] = myTable;
        }
        if (!IsPostBack)
        {
            radioInsert.Checked = true;

            DropDownList DropChecker = ((DropDownList)FormView1.FindControl("DropChecker"));
            MembershipUserCollection users = Membership.GetAllUsers();
            DropChecker.DataSource = users;
            DropChecker.DataBind();

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

            TextBox ReceiptDateTextBox = FormView1.FindControl("ReceiptDateTextBox") as TextBox;
            OboutInc.Calendar.Calendar CalendarReceiptDate = FormView1.FindControl("CalendarReceiptDate") as OboutInc.Calendar.Calendar;
            CalendarReceiptDate.TextBoxId = ReceiptDateTextBox.ClientID;
        }
    }

    protected void Page_Unload(object sender, EventArgs e)
    {
        if (!IsPostBack && Session["ReceiptTable"] != null)
        {
            Session["ReceiptTable"] = null;
        }
    }

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

    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;

        TextBox ReceivingCodeTextBox = FormView1.FindControl("ReceivingCodeTextBox") as TextBox;

        ClientScriptManager cs = Page.ClientScript;
        Type cstype = this.GetType();
        String csname = "PopupScript";

        if (ReceivingCodeTextBox.Text == "")
        {
            String cstext = "alert('请填写料单号!');";
            cs.RegisterStartupScript(cstype, csname, cstext, true);
            radioInsertDetails.Checked = false;
            radioBrowserDetails.Checked = true;
            return;
        }

        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");
            GetReceiptItems(myGridView);
            trList.Visible = true;
            TrNew.Visible = false;
        }
        else if (radioInsertDetails.Checked)
        {
            trList.Visible = false;
            GridView myGridView = (GridView)TrNew.FindControl("GridView2");
            GetReceiptPlanItems(myGridView);
            TrNew.Visible = true;
        }
        ((TextBox)TrNew.Parent.FindControl("ReceiptDateTextBox")).Enabled = false;
        ((OboutInc.Calendar.Calendar)TrNew.Parent.FindControl("CalendarReceiptDate")).DatePickerButtonText = "";
        ((DropDownList)TrNew.Parent.FindControl("DropDownList1")).Enabled = false;
        ((DropDownList)TrNew.Parent.FindControl("DropChecker")).Enabled = false;
        ((DropDownList)TrNew.Parent.FindControl("DrpSupplier")).Enabled = false;
        ((TextBox)TrNew.Parent.FindControl("ContractIDTextBox")).Enabled = false;
        ((TextBox)FormView1.FindControl("ReceivingCodeTextBox")).Enabled = false;
        ((TextBox)FormView1.FindControl("FreightTextBox")).Enabled = false;
        ((TextBox)FormView1.FindControl("DescriptionTextBox")).Enabled = false;
        ((LinkButton)FormView1.FindControl("InsertButton")).Enabled = true;
        ((TextBox)FormView1.FindControl("ItemIDTextBox")).Enabled = true;
        ((LinkButton)FormView1.FindControl("LinkButtonSearch")).Enabled = true;
    }

    protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        TextBox ReceiptDateTextBox = FormView1.FindControl("ReceiptDateTextBox") as TextBox;
        DateTime ReceiptDate;
        try
        {
            ReceiptDate = DateTime.Parse(ReceiptDateTextBox.Text);
        }
        catch (System.FormatException eFormat)
        {
            ReceiptDate = DateTime.Now;
        }
        SqlDataSource1.InsertParameters["ArriveDate"].DefaultValue = ReceiptDate.ToShortDateString();


        DropDownList DropChecker = FormView1.FindControl("DropChecker") as DropDownList;
        DropDownList DrpSupplier = FormView1.FindControl("DrpSupplier") as DropDownList;
        DropDownList DropDownList1 = FormView1.FindControl("DropDownList1") as DropDownList;
        TextBox ReceivingCodeTextBox = FormView1.FindControl("ReceivingCodeTextBox") as TextBox;
        TextBox FreightTextBox = FormView1.FindControl("FreightTextBox") as TextBox;
        TextBox DescriptionTextBox = FormView1.FindControl("DescriptionTextBox") as TextBox;

        SqlDataSource1.InsertParameters["ReceiverID"].DefaultValue = this.User.Identity.Name;
        SqlDataSource1.InsertParameters["CheckerID"].DefaultValue = DropChecker.SelectedValue;
        SqlDataSource1.InsertParameters["SupplierID"].DefaultValue = DrpSupplier.SelectedValue;
        SqlDataSource1.InsertParameters["WareHouseID"].DefaultValue = DropDownList1.SelectedValue;
        SqlDataSource1.InsertParameters["Freight"].DefaultValue = FreightTextBox.Text;
        SqlDataSource1.InsertParameters["Description"].DefaultValue = DescriptionTextBox.Text;
        SqlDataSource1.InsertParameters["ReceivingCode"].DefaultValue = ReceivingCodeTextBox.Text;

        //得到已经增加的物资列表
        DataTable myTable = Session["ReceiptTable"] as DataTable;
        string strReceiptItemsID = "";
        string strReceiptItemsPrice = "";
        string strReceiptItemsQuantity = "";
        for (int i = 0; i < myTable.Rows.Count; i++)
        {
            strReceiptItemsID += myTable.Rows[i][0] + ",";
            strReceiptItemsPrice += myTable.Rows[i][6] + ",";
            strReceiptItemsQuantity += myTable.Rows[i][7] + ",";
        }
        if (strReceiptItemsID != "")
        {
            //去掉最后一个“,”
            strReceiptItemsID = strReceiptItemsID.Substring(0, strReceiptItemsID.Length - 1);
            strReceiptItemsPrice = strReceiptItemsPrice.Substring(0, strReceiptItemsPrice.Length - 1);
            strReceiptItemsQuantity = strReceiptItemsQuantity.Substring(0, strReceiptItemsQuantity.Length - 1);
        }

        SqlDataSource1.InsertParameters["ItemsIDList"].DefaultValue = strReceiptItemsID;
        SqlDataSource1.InsertParameters["PriceList"].DefaultValue = strReceiptItemsPrice;
        SqlDataSource1.InsertParameters["QuantityList"].DefaultValue = strReceiptItemsQuantity;
    }

    protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        if (e.Exception == null)
        {
            if (Session["ReceiptTable"] != null)
            {
                Session["ReceiptTable"] = null;
            }

            // Get a ClientScriptManager reference from the Page class.
            ClientScriptManager cs = Page.ClientScript;
            Type cstype = this.GetType();
            String csname = "PopupScriptSuccess";

            // Check to see if the startup script is already registered.
            if (!cs.IsStartupScriptRegistered(cstype, csname))
            {
                String cstext = "alert('成功添加记录。');window.location.href=window.location.href";
                cs.RegisterStartupScript(cstype, csname, cstext, true);
            }
        }
        else
        {
            // Get a ClientScriptManager reference from the Page class.
            ClientScriptManager cs = Page.ClientScript;
            Type cstype = this.GetType();
            String csname = "PopupScript";

            // Check to see if the startup script is already registered.
            if (!cs.IsStartupScriptRegistered(cstype, csname))
            {
                String cstext = "alert('在往数据库增加记录时出错,请重新编辑保存。');window.location.href=window.location.href";
                cs.RegisterStartupScript(cstype, csname, cstext, true);
            }

            Message.Text = "在往数据库增加记录时出错。";
            //e.ExceptionHandled = true;
        }


    }

    protected void InsertCancelButton_Click(object sender, EventArgs e)
    {
        if (Session["ReceiptTable"] != null)
        {
            Session["ReceiptTable"] = null;
        }
        Response.Redirect("directInbound.aspx");
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView myGridView = (GridView)sender;
        GetReceiptItems(myGridView);
        myGridView.PageIndex = e.NewPageIndex;
        myGridView.DataBind();
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView myGridView = (GridView)sender;
        GetReceiptItems(myGridView);
        myGridView.EditIndex = e.NewEditIndex;
        myGridView.DataBind();

        //光标,后面想想怎么默认全部选中
        GridViewRow editRow = myGridView.Rows[e.NewEditIndex];
        Page.SetFocus((TextBox)editRow.FindControl("txtReceiptItemsPrice"));
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        DataTable myTable = Session["ReceiptTable"] as DataTable;
        GridView myGridView = (GridView)sender;
        GridViewRow delRow = myGridView.Rows[e.RowIndex];

        //由于可能在后面加入sorting的功能,所以不能简单地用GridView的e.RowIndex代表Session中DispatchTable的index
        for (int i = 0; i < myTable.Rows.Count; i++)
        {
            string strTemp = myTable.Rows[i][0].ToString();
            if (strTemp == ((Label)delRow.Cells[1].FindControl("lblReceiptItemsID")).Text)
            {
                myTable.Rows[i].Delete();
                break;

⌨️ 快捷键说明

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