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

📄 check.aspx.cs

📁 asp销售管理系统
💻 CS
📖 第 1 页 / 共 3 页
字号:
            priceTotal += (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "RealQuantity")) - Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "InventoryQuantity"))) * Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "StandardPrice"));
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[7].Text = "金额总计:";
            // for the Footer, display the running totals
            e.Row.Cells[8].Text = priceTotal.ToString("c");

            for (int i = 2; i < 9; i++)
                e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Font.Bold = true;

            priceTotal = 0;
        }

    }

    /// <summary>
    /// 取消之前先清空Session的CheckTable表
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void InsertCancelButton_Click(object sender, EventArgs e)
    {
        if (Session["CheckTable"] != null)
        {
            Session["CheckTable"] = null;
        }
        Response.Redirect("check.aspx");
    }

    /// <summary>
    /// 保存发料记录
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        TextBox CheckDateTextBox = FormView1.FindControl("CheckDateTextBox") as TextBox;
        DateTime CheckDate;
        try
        {
            CheckDate = DateTime.Parse(CheckDateTextBox.Text);
        }
        catch (System.FormatException eFormat)
        {
            CheckDate = DateTime.Now;
        }
        SqlDataSource1.InsertParameters["CheckDate"].DefaultValue = CheckDate.ToShortDateString();

        DropDownList drpWareHouseID = FormView1.FindControl("DropDownList1") as DropDownList;
        TextBox DescriptionTextBox = FormView1.FindControl("DescriptionTextBox") as TextBox;

        SqlDataSource1.InsertParameters["WareHouseID"].DefaultValue = drpWareHouseID.SelectedValue;
        SqlDataSource1.InsertParameters["UserName"].DefaultValue = this.User.Identity.Name;
        SqlDataSource1.InsertParameters["Description"].DefaultValue = DescriptionTextBox.Text;

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

        SqlDataSource1.InsertParameters["ItemsIDList"].DefaultValue = strCheckItemsID;
        SqlDataSource1.InsertParameters["InventoryList"].DefaultValue = strCheckItemsInventory;
        SqlDataSource1.InsertParameters["QuantityList"].DefaultValue = strCheckItemsQuantity;
        SqlDataSource1.InsertParameters["ReasonList"].DefaultValue = strCheckItemsReason;
    }

    protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        if (e.Exception == null)
        {
            Message.Text = "成功添加记录。";
            if (Session["CheckTable"] != null)
            {
                Session["CheckTable"] = null;
            }
        }
        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('在往数据库增加记录时出错,请重新编辑保存。');";
                cs.RegisterStartupScript(cstype, csname, cstext, true);
            }

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

    }

    protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        SqlDataSource4.UpdateParameters["ReviewerName"].DefaultValue = this.User.Identity.Name;
    }

    protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView rowView = (DataRowView)e.Row.DataItem;
            bool state = Convert.ToBoolean(rowView["IsReviewed"]);
            ((LinkButton)e.Row.FindControl("btnReview")).Visible = !state;
            ((LinkButton)e.Row.FindControl("btnDelete")).Visible = !state;
        }

    }

    protected void GridView3_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        GridView3.SelectedIndex = -1;
    }

    protected void LinkButtonEditAdd_Click(object sender, EventArgs e)
    {
        DropDownList drpItem = (DropDownList)GridView4.FooterRow.FindControl("drpItem");
        string ItemID = drpItem.SelectedValue;
        string strDeliveryID = GridView3.SelectedValue.ToString();

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySqlProviderConnection"].ConnectionString);
        string strQuery = "";

        strQuery = "sp_insertEditCheckDetail";
        SqlCommand command = new SqlCommand(strQuery, con);
        command.CommandType = CommandType.StoredProcedure;
        SqlParameter parameter = command.Parameters.Add("@InventoryCheckID", SqlDbType.Int);
        parameter.Value = strDeliveryID;

        parameter = command.Parameters.Add("@ItemID", SqlDbType.VarChar, 20);
        parameter.Value = ItemID;

        con.Open();
        command.ExecuteNonQuery();

        //列表GridView
        GridView4.EditIndex = 0;
        GridView4.DataBind();

        //光标
        GridViewRow editRow = GridView4.Rows[GridView4.EditIndex];
        Page.SetFocus((TextBox)editRow.FindControl("txtQuantity"));

    }
    protected void GridView3_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        GridView4.DataBind();
    }

    /// <summary>
    /// 根据当日车辆和维修定额,显示在发料明细表中
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAuto_Click(object sender, EventArgs e)
    {
        DropDownList DropDownList1 = FormView1.FindControl("DropDownList1") as DropDownList;
        int WareHouseID = Convert.ToInt32(DropDownList1.SelectedValue);

        TextBox CheckDateTextBox = FormView1.FindControl("CheckDateTextBox") as TextBox;
        DateTime CheckDate;
        try
        {
            CheckDate = DateTime.Parse(CheckDateTextBox.Text);
        }
        catch (System.FormatException eFormat)
        {
            CheckDate = DateTime.Now;
        }

        DataTable myTable = Session["CheckTable"] as DataTable;
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySqlProviderConnection"].ConnectionString);
        string 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=" + WareHouseID;
        SqlCommand command = new SqlCommand(strQuery, con);

        con.Open();
        SqlDataReader reader = command.ExecuteReader();

        try
        {
            while (reader.Read())
            {
                DataRow dr = myTable.NewRow();
                for (int i = 0; i < 6; i++)
                {
                    dr[i] = reader[i];
                }
                dr[6] = dr[5];
                dr[7] = Convert.ToDecimal(dr[6]) - Convert.ToDecimal(dr[5]);
                dr[8] = Convert.ToDecimal(dr[4]) * Convert.ToDecimal(dr[7]);
                //刚开始无原因
                dr[9] = "0";
                myTable.Rows.InsertAt(dr,0);
            }
        }
        finally
        {
            reader.Close();
        }

        Session["CheckTable"] = myTable;

        GetCheckItems((GridView)FormView1.FindControl("GridView1"));

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

        radioButtonDetails_CheckedChanged(radioBrowserDetails, new EventArgs());
    }

    protected void GridView4_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridView myGridView = (GridView)sender;
        GridViewRow updateRow = myGridView.Rows[e.RowIndex];

        SqlDataSource5.UpdateParameters["InventoryReasonID"].DefaultValue = ((DropDownList)updateRow.FindControl("drpCheckItemsReason")).SelectedValue;
    }

    protected void LinkButtonSearch_Click(object sender, EventArgs e)
    {
        RadioButton radioInsertDetails = FormView1.FindControl("radioInsertDetails") as RadioButton;
        RadioButton radioBrowserDetails = FormView1.FindControl("radioBrowserDetails") as RadioButton;
        radioBrowserDetails.Checked = false;
        radioInsertDetails.Checked = true;
        radioButtonDetails_CheckedChanged(radioInsertDetails, new EventArgs());
    }
}

⌨️ 快捷键说明

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