Ejemplo n.º 1
0
    protected void GridViewCycle_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name);
        if (e.CommandName == "EditCycle")
        {
            int RowIndex = Convert.ToInt32((e.CommandArgument).ToString());

            List <dbo_OrderAndDeliveryCycleClass> item1 = dbo_OrderAndDeliveryCycleDataClass.SelectAll();

            if (item1.Count < GridViewCycle.Rows.Count && RowIndex > int.Parse(ViewState["current_index"].ToString()))
            {
                RowIndex--;
            }

            current_index = RowIndex;

            ViewState["current_index"] = current_index;

            LinkButton currbtn = (LinkButton)GridViewCycle.Rows[RowIndex].FindControl("lnkB_SetOrder_Cycle_Name");

            //Label cycle_id = (Label)GridViewCycle.Rows[RowIndex].FindControl("lblOrder_Cycle_ID");
            string orderCycleID = item1[RowIndex].Order_Cycle_ID;


            if (currbtn.Text == "แก้ไขรอบสั่งรอบส่ง")
            {
                dbo_OrderAndDeliveryCycleClass cycle = new dbo_OrderAndDeliveryCycleClass()
                {
                };

                List <dbo_OrderAndDeliveryCycleClass> item = dbo_OrderAndDeliveryCycleDataClass.SelectAll();

                item.Insert(RowIndex + 1, new dbo_OrderAndDeliveryCycleClass()
                {
                });

                GridViewCycle.DataSource = item;

                GridViewCycle.DataBind();
                currbtn      = (LinkButton)GridViewCycle.Rows[RowIndex].FindControl("lnkB_SetOrder_Cycle_Name");
                currbtn.Text = "ปิด";


                //List<dbo_OrderAndDeliveryCycleValueClass> item_value = dbo_OrderAndDeliveryCycleValueDataClass.Search(cycle_id.Text);
                List <dbo_OrderAndDeliveryCycleValueClass> item_value = dbo_OrderAndDeliveryCycleValueDataClass.Search(orderCycleID);

                GridView   gv         = (GridView)GridViewCycle.Rows[RowIndex + 1].FindControl("grdNewValue");
                Button     newbutton1 = (Button)GridViewCycle.Rows[RowIndex + 1].FindControl("btnNewValue");
                LinkButton Cycle_Name = (LinkButton)GridViewCycle.Rows[RowIndex + 1].FindControl("lnkB_SetOrder_Cycle_Name");

                gv.DataSource = item_value;
                gv.DataBind();
                gv.Visible         = true;
                newbutton1.Visible = true;
                Cycle_Name.Visible = false;

                GridViewCycle.Rows[RowIndex + 1].Cells[2].ColumnSpan = 5;
                GridViewCycle.Rows[RowIndex + 1].Cells[0].Visible    = false;
                GridViewCycle.Rows[RowIndex + 1].Cells[1].Visible    = false;
                GridViewCycle.Rows[RowIndex + 1].Cells[3].Visible    = false;
                GridViewCycle.Rows[RowIndex + 1].Cells[4].Visible    = false;
                GridViewCycle.Rows[RowIndex + 1].Cells[5].Visible    = false;


                Label currlbl = (Label)GridViewCycle.Rows[RowIndex + 1].FindControl("lblOrder");
                currlbl.Visible = false;
                //
                currbtn.Visible = true;

                for (int i = RowIndex + 1; i < GridViewCycle.Rows.Count; i++)
                {
                    Label lbl_Amount = (Label)GridViewCycle.Rows[i].FindControl("lblOrder");
                    lbl_Amount.Text = i.ToString();
                }
            }
            else
            {
                List <dbo_OrderAndDeliveryCycleClass> item = dbo_OrderAndDeliveryCycleDataClass.SelectAll();
                GridViewCycle.DataSource = item.OrderBy(f => f.Order_Cycle_ID);;
                GridViewCycle.DataBind();
            }
        }
        else if (e.CommandName == "AddNew")
        {
            string _Order_Cycle_ID = GenerateID.Order_Cycle_ID();

            TextBox _Order_Cycle_Name = (TextBox)GridViewCycle.FooterRow.FindControl("txtNewOrder_Cycle_Name");
            if (_Order_Cycle_Name.Text.Trim() != string.Empty)
            {
                dbo_OrderAndDeliveryCycleClass cycle = new dbo_OrderAndDeliveryCycleClass()
                {
                    Order_Cycle_ID = _Order_Cycle_ID, Order_Cycle_Name = _Order_Cycle_Name.Text
                };

                bool   success = false;
                string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value;
                success = dbo_OrderAndDeliveryCycleDataClass.Add(cycle, User_ID);

                if (success)
                {
                    //string script = @"swal(""บันทึกสำเร็จ!"", """", ""success"")";
                    //ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAM", script, true);

                    // Show("บันทึกสำเร็จ");

                    GridViewCycle.ShowFooter = false;


                    List <dbo_OrderAndDeliveryCycleClass> item = dbo_OrderAndDeliveryCycleDataClass.SelectAll();
                    GridViewCycle.DataSource = item.OrderBy(f => f.Order_Cycle_ID);;
                    GridViewCycle.DataBind();
                }

                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
            }
            else
            {
                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                Show("กรุณากรอกข้อมูลที่จำเป็นให้ครบถ้วน");
            }
        }
    }