//模糊查询物料名称
    protected void SelectMatBasicData(object sender, EventArgs e)
    {
        try
        {
            Label_BasicData_Source.Text = "模糊查询数据源";
            string condition = GetCondition();
            BindGridView_MatBasicData_Serarch(condition);
            if (DropDownList1.SelectedValue != "")
            {
                Label17.Text = Gridview_MatType.Rows[0].Cells[1].Text.ToString();
                Gridview_MatType.DataSource = mat.Select_MaterialTypeCondition("and IMMt_MaterialTypeID='" + DropDownList1.SelectedValue.ToString() + "'");
                Gridview_MatType.DataBind();
                UpdatePanel_MatType.Update();
            }
            else
            {
                Label17.Text = "检索的";
                UpdatePanel_MatType.Update();
            }

            Panel_MaterBasicData.Visible = true;
            UpdatePanel_MaterBasicData.Update();
            //this.MatName.Text = "";
            //this.Model.Text = "";
            //this.SafeStock.Text = "";
            //this.StockDay.Text = "";
        }
        catch (Exception)
        {
            //throw;
            ScriptManager.RegisterClientScriptBlock(UpdatePanel_Search, GetType(), "alert", "alert('you make some mistakes')", true);
        }
    }
 //检索物料类别
 protected void SelectMaterialType(object sender, EventArgs e)
 {
     label_Mattypesource.Text = "search";
     BindGridView_MatType();
     UpdatePanel_MatType.Update();
     Panel_Search.Visible = false;
     UpdatePanel_Search.Update();
     Panel_MaterBasicData.Visible = false;
     UpdatePanel_MaterBasicData.Update();
 }
    //Gridview编辑物料类型
    protected void Gridview_MatType_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Guid   mattypeid   = new Guid(Gridview_MatType.DataKeys[e.RowIndex].Value.ToString());
        string mattypename = Convert.ToString(((TextBox)(Gridview_MatType.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim().ToString());
        string comment     = Convert.ToString(((TextBox)(Gridview_MatType.Rows[e.RowIndex].Cells[2].Controls[0])).Text.Trim().ToString());

        //BindGridView_MatType();
        mat.Update_MaterialType(mattypeid, mattypename, comment);
        Gridview_MatType.EditIndex = -1;
        BindGridView_MatType();
        UpdatePanel_MatType.Update();
        Panel_MatTypeNew.Visible = false;
        UpdatePanel_MatTypeNew.Update();
    }
    //新建物料类型-确认
    protected void ConfirmMatTypeNew(object sender, EventArgs e)
    {
        //try
        //{
        string mattypename = TextBox_NewTypeName.Text.ToString();
        string comment     = TextArea1.InnerText.ToString();

        if (TextBox_NewTypeName.Text.ToString() == "")
        {
            ScriptManager.RegisterClientScriptBlock(UpdatePanel_MatTypeNew, GetType(), "alert", "alert('必须填写物料名称')", true);
            return;
        }
        int temp = mat.Select_IMMaterialTypeRepeat(mattypename);

        if (temp != 0)
        {
            ScriptManager.RegisterClientScriptBlock(UpdatePanel_MatTypeNew, GetType(), "alert", "alert('物料类型名称重复,不可以添加!')", true);
            return;
        }
        mat.Insert_MaterialType(mattypename, comment);
        BindGridView_MatType();
        UpdatePanel_MatType.Update();
        TextBox_NewTypeName.Text = "";
        TextArea1.InnerText      = "";
        Panel_MatTypeNew.Visible = false;
        UpdatePanel_MatTypeNew.Update();
        BindDropDownList1();
        BindDropDownList2();
        UpdatePanel_Search.Update();
        UpdatePanel_MatBasicDataNew.Update();
        ScriptManager.RegisterClientScriptBlock(UpdatePanel_MatTypeNew, GetType(), "alert", "alert('提交成功!')", true);
        //}
        //catch (Exception)
        //{
        //    Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('you make some mistakes ');</script>");
        //}
    }
    //根据条件控制gridview每列的显示
    protected void Gridview_MatType_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Look1")                                                         //点击查看物料名称
        {
            GridViewRow gvr = ((GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent)); //first parent :rows,second parent:gridview;

            label_mattypeid.Text        = Convert.ToString(gvr.RowIndex);
            label_mattypeid.Text        = Convert.ToString(e.CommandArgument);
            Label_BasicData_Source.Text = "Gridview数据源";
            string iid = e.CommandArgument.ToString();
            Panel_MaterBasicData.Visible = true;
            BindGridView_MatBasicData_Gridview(iid);
            Label17.Text = Gridview_MatType.Rows[gvr.RowIndex].Cells[1].Text.ToString() + "的";
            Panel_MaterBasicData.Visible = true;
            UpdatePanel_MaterBasicData.Update();
        }
        if (e.CommandName == "Delete1")
        {
            Guid mattypeid = new Guid(Convert.ToString(e.CommandArgument));
            mat.Delete_MaterialType(mattypeid);
            BindGridView_MatType();
            UpdatePanel_MatType.Update();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.Items.Insert(0, new ListItem("选择物料类别", "选择物料类别"));
            BindDropDownList1();
            DropDownList2.Items.Insert(0, new ListItem("选择物料类别", "选择物料类别"));
            BindDropDownList2();
            UpdatePanel_MatType.Visible = true;
            BindGridView_MatType();
            UpdatePanel_MatType.Update();
            UpdatePanel_MaterBasicData.Update();
            BindDropdownList();
        }

        #region 权限

        try
        {
            if (!((Session["UserRole"].ToString().Contains("物料基础数据维护")) || (Session["UserRole"].ToString().Contains("物料基础数据查看"))))
            {
                Response.Redirect("~/Default.aspx");
            }
        }
        catch (Exception)
        {
            ScriptManager.RegisterStartupScript(Page, typeof(Page), "alert", "alert('可能您没有权限操作和查看本页面,请退出选择其他账号登陆,或联系管理员!')", true);
            Response.Redirect("~/Default.aspx");
        }

        //if (Session["UserRole"].ToString().Contains("物料基础数据查看"))

        if (Request.QueryString["status"] == "IMMaterialBasicSearch")
        {
            {
                Title = "物料基础数据查看";
                Gridview_MatType.Columns[4].Visible = false;
                Gridview_MatType.Columns[5].Visible = false;
                Button2.Visible = false;
                GridView_MaterialBasicData.Columns[11].Visible = false;
                GridView_MaterialBasicData.Columns[12].Visible = false;
                Button8.Visible = false;
                UpdatePanel_Search.Update();
                UpdatePanel_MatType.Update();
                UpdatePanel_MaterBasicData.Update();
                Button12.Visible = false;
                UpdatePanel1.Update();
            }
            //if (Session["UserRole"].ToString().Contains("物料基础数据维护"))
            if (Request.QueryString["status"] == "IMMaterialBasicEdit")
            {
                Title = "物料基础数据维护";
                Gridview_MatType.Columns[4].Visible = true;
                Gridview_MatType.Columns[5].Visible = true;
                Button2.Visible = true;
                GridView_MaterialBasicData.Columns[11].Visible = true;
                GridView_MaterialBasicData.Columns[12].Visible = true;
                Button8.Visible = true;
                UpdatePanel_Search.Update();
                UpdatePanel_MatType.Update();
                UpdatePanel_MaterBasicData.Update();
                Button12.Visible = true;
                UpdatePanel1.Update();
            }
            #endregion
        }
    }