示例#1
0
    protected void GVItemDetail_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            int recordId = Convert.ToInt32(e.CommandArgument);
            Session["RecordID"] = recordId;
            if (e.CommandName == "EditRecord")
            {
                SqlParameter[] arr = new SqlParameter[2];
                arr[0] = new SqlParameter("@Action", "SELECT_ByID");
                arr[1] = new SqlParameter("@ID", recordId);
                DataSet   ds = SqlHelper.ExecuteDataset(Connection.connect(), CommandType.StoredProcedure, "SP_ItemRequestMaster_CRUD", arr);
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    MVRequest.ActiveViewIndex = 1;
                    LBLReqNo.Text             = dt.Rows[0]["ReqNo"].ToString();
                    LBLTOtQut.Text            = dt.Rows[0]["TotalQty"].ToString();
                    DDLComLoc.SelectedValue   = dt.Rows[0]["ComId"].ToString();
                    BindComForRequest();
                    LBLTotVal.Text  = dt.Rows[0]["TotalValue"].ToString();
                    LBReqDate.Text  = dt.Rows[0]["ReqDate"].ToString();
                    txtDelDate.Text = dt.Rows[0]["DeliverDate"].ToString();
                    BindDDLNGO(DDLComLoc.SelectedValue);
                    DDLNgoLoc.ClearSelection();
                    DDLNgoLoc.SelectedValue = dt.Rows[0]["NgoId"].ToString();
                    DDLItemType.ClearSelection();
                    DDLItemList.ClearSelection();
                    txtRemarks.Text = dt.Rows[0]["Remark"].ToString();
                    txtTermCon.Text = dt.Rows[0]["TermAndCondition"].ToString();
                    BindDDLGodown(DDLComLoc.SelectedValue);
                    DDLDelTo.SelectedValue    = dt.Rows[0]["DeliverTo"].ToString();
                    DDLItemType.SelectedValue = dt.Rows[0]["ItemType"].ToString();
                    switch (DDLItemType.SelectedValue)
                    {
                    case "1":
                        BindItemKitTypeList();
                        break;

                    case "2":
                        BindItemFinishTypeList();
                        break;

                    default:
                        break;
                    }
                    btnSubmit.Text = "Update";
                    SqlParameter[] arrParam2 = new SqlParameter[2];
                    arrParam2[0] = new SqlParameter("@Action", "Select_ByReqId");
                    arrParam2[1] = new SqlParameter("@ReqId", recordId);
                    DataSet DSInner = SqlHelper.ExecuteDataset(Connection.connect(), CommandType.StoredProcedure, "SP_ItemRequestDetail_CRUD", arrParam2);
                    // Bind Table
                    CreateDTTable();
                    TempDT = ViewState["DTTable"] as DataTable;
                    for (int i = 0; i < DSInner.Tables[0].Rows.Count; i++)
                    {
                        string    SelQuery = "SELECT * FROM KitMaterial Where ID='" + DSInner.Tables[0].Rows[i]["ItemId"] + "'";
                        DataTable DTProduct = clsConnectionSql.filldt(SelQuery);
                        double    ItemPrice, Quantity, GTotal;
                        Quantity  = Convert.ToDouble(DSInner.Tables[0].Rows[i]["Qty"].ToString());
                        ItemPrice = Convert.ToDouble(DTProduct.Rows[0]["TotalValue"].ToString());
                        GTotal    = ItemPrice * Quantity;
                        TempDT.Rows.Add(DTProduct.Rows[0]["ID"],
                                        DTProduct.Rows[0]["Image"].ToString(),
                                        DTProduct.Rows[0]["Name"].ToString(),
                                        DTProduct.Rows[0]["ProductCode"].ToString(),
                                        DTProduct.Rows[0]["HSNCode"].ToString(),
                                        DTProduct.Rows[0]["BarCode"].ToString(),
                                        DTProduct.Rows[0]["UOM"].ToString(),
                                        Quantity.ToString("0.00"),
                                        ItemPrice.ToString("0.00"),
                                        GTotal.ToString("0.00"));
                    }
                    GVInner.DataSource = TempDT;
                    GVInner.DataBind();
                    ViewState["DTTable"] = TempDT;
                }
                BindInnerGV();
            }
            else if (e.CommandName == "DeleteRecord")
            {
                SqlParameter[] arr = new SqlParameter[2];
                arr[0] = new SqlParameter("@Action", "DELETE");
                arr[1] = new SqlParameter("@ID", recordId);
                DataSet ds = SqlHelper.ExecuteDataset(Connection.connect(), CommandType.StoredProcedure, "SP_ItemRequestMaster_CRUD", arr);
            }

            if (e.CommandName == "CheckStatus")
            {
                SqlParameter[] arr = new SqlParameter[2];
                arr[0] = new SqlParameter("@Action", "SELECT_ByID");
                arr[1] = new SqlParameter("@ID", recordId);
                DataSet   ds = SqlHelper.ExecuteDataset(Connection.connect(), CommandType.StoredProcedure, "SP_ItemRequestMaster_CRUD", arr);
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["ReqStatus"].ToString() == "True")
                    {
                        SqlParameter[] arr1 = new SqlParameter[3];
                        arr1[0] = new SqlParameter("@Action", "UPDATE_Status");
                        arr1[1] = new SqlParameter("@ReqStatus", false);
                        arr1[2] = new SqlParameter("@ID", recordId);
                        int result = SqlHelper.ExecuteNonQuery(Connection.connect(), CommandType.StoredProcedure, "SP_ItemRequestMaster_CRUD", arr1);
                    }
                    if (dt.Rows[0]["ReqStatus"].ToString() == "False")
                    {
                        SqlParameter[] arr1 = new SqlParameter[3];
                        arr1[0] = new SqlParameter("@Action", "UPDATE_Status");
                        arr1[1] = new SqlParameter("@ReqStatus", true);
                        arr1[2] = new SqlParameter("@ID", recordId);
                        int result = SqlHelper.ExecuteNonQuery(Connection.connect(), CommandType.StoredProcedure, "SP_ItemRequestMaster_CRUD", arr1);
                    }
                }
            }

            BindGVDetail();
        }
        catch (Exception ex)
        {
            ShowMessage(ex.Message, MessageType.Error);
        }
    }