コード例 #1
0
        //protected void gvServer_RowUpdating(object sender, GridViewUpdateEventArgs e)
        //{
        //    try
        //    {
        //        Label lblServerID = (Label)gvServer.Rows[e.RowIndex].FindControl("lblServerID");
        //        int ServerID = Convert.ToInt16(lblServerID.Text.ToString());
        //        TextBox txtServerName = (TextBox)gvServer.Rows[e.RowIndex].FindControl("txtServerName");
        //        string strServerName = txtServerName.Text.ToString();
        //        if (strServerName != "")
        //        {
        //            bool flag = CheckIFDBServerExists(strServerName);
        //            if (flag == false)
        //            {

        //                objclsBALApplication = new clsBALApplication();
        //                objclsBALApplication.UpdateDBServer(ServerID, strServerName);
        //                gvServer.EditIndex = -1;
        //                PopulateGrid();
        //                if (ViewState["SortExpression"] != null && ViewState["sortDirection"] != null)
        //                {
        //                    SortGridView(ViewState["SortExpression"].ToString(), ViewState["sortDirection"].ToString());
        //                }
        //                lblSuccess.Text = "Database server updated successfully.";

        //            }
        //            else
        //            {
        //                if (Session["serverName"].ToString() == strServerName)
        //                {

        //                    lblError.Text = "There is no change in server name.";
        //                    // gvServer.EditIndex = -1;
        //                }
        //                else
        //                {
        //                    lblError.Text = "Database server already exists.";
        //                    // gvServer.EditIndex = -1;
        //                }
        //            }
        //        }
        //        else
        //        {
        //            lblError.Text = "Please fill database server name.";
        //        }
        //    }
        //    catch (NullReferenceException)
        //    {
        //        Response.Redirect("wfrmErrorPage.aspx", true);
        //    }
        //    catch (Exception ex)
        //    {
        //        HttpContext context = HttpContext.Current;
        //        LogException objclsLogException = new LogException();
        //        objclsLogException.LogErrorInDataBase(ex, context);
        //        Response.Redirect("wfrmErrorPage.aspx", true);

        //    }
        //}

        protected void gvServer_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                Label        lblServerID     = (Label)gvServer.Rows[e.RowIndex].FindControl("lblServerID");
                int          ServerID        = Convert.ToInt16(lblServerID.Text.ToString());
                TextBox      txtServerName   = (TextBox)gvServer.Rows[e.RowIndex].FindControl("txtServerName");
                string       strServerName   = txtServerName.Text.ToString();
                DropDownList ddlDBServerType = (DropDownList)gvServer.Rows[e.RowIndex].FindControl("ddlGridServerType");
                if (ddlDBServerType.SelectedValue.ToString().Trim() != "0")
                {
                    int ServerType_ID = int.Parse(ddlDBServerType.SelectedValue.ToString());
                    if (strServerName != "")
                    {
                        //bool flag = CheckIFDBServerExists(strServerName);
                        bool flag = false;
                        if (flag == false)
                        {
                            objclsBALApplication = new clsBALApplication();
                            objclsBALApplication.UpdateDBServer(ServerID, strServerName, ServerType_ID);
                            gvServer.EditIndex = -1;
                            PopulateGrid();
                            if (ViewState["SortExpression"] != null && ViewState["sortDirection"] != null)
                            {
                                SortGridView(ViewState["SortExpression"].ToString(), ViewState["sortDirection"].ToString());
                            }
                            lblSuccess.Text = "Database server updated successfully.";
                        }
                        else
                        {
                            if (Session["serverName"].ToString() == strServerName)
                            {
                                lblError.Text = "There is no change in server name.";
                                // gvServer.EditIndex = -1;
                            }
                            else
                            {
                                lblError.Text = "Database server already exists.";
                                // gvServer.EditIndex = -1;
                            }
                        }
                    }
                    else
                    {
                        lblError.Text = "Please fill database server name.";
                    }
                }
            }
            catch (NullReferenceException)
            {
                Response.Redirect("wfrmErrorPage.aspx", true);
            }
            catch (Exception ex)
            {
                HttpContext  context            = HttpContext.Current;
                LogException objclsLogException = new LogException();
                objclsLogException.LogErrorInDataBase(ex, context);
                Response.Redirect("wfrmErrorPage.aspx", true);
            }
        }