Exemple #1
0
    protected void RadGrid1_DeleteCommand(object source, Telerik.WebControls.GridCommandEventArgs e)  
    {  
        //Get the GridDataItem of the RadGrid    
        GridDataItem item = (GridDataItem)e.Item;  
        //Get the primary key value using the DataKeyValue.    
        string EmployeeID = item.OwnerTableView.DataKeyValues[item.ItemIndex]["EmployeeID"].ToString();  
        try  
        {  
            //Open the SqlConnection    
            SqlConnection.Open();  
            string deleteQuery = "DELETE from Employees where EmployeeID='" + EmployeeID + "'";  
            SqlCommand.CommandText = deleteQuery;  
            SqlCommand.Connection = SqlConnection;  
            SqlCommand.ExecuteNonQuery();  
            //Close the SqlConnection    
            SqlConnection.Close();  
 
        }  
        catch (Exception ex)  
        {  
            RadGrid1.Controls.Add(new LiteralControl("Unable to delete Employee. Reason: " + ex.Message));  
            e.Canceled = true;  
        }    
 
    }  
Exemple #2
0
    protected void RadGrid1_UpdateCommand(object source, Telerik.WebControls.GridCommandEventArgs e)  
    {  
        //Get the GridEditableItem of the RadGrid    
        GridEditableItem eeditedItem = e.Item as GridEditableItem;  
        //Get the primary key value using the DataKeyValue.    
        string EmployeeID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["EmployeeID"].ToString();  
        //Access the textbox from the edit form template and store the values in string variables.    
        string LastName = (editedItem["LastName"].Controls[0] as TextBox).Text;  
        string FirstName = (editedItem["FirstName"].Controls[0] as TextBox).Text;  
        string Title = (editedItem["Title"].Controls[0] as TextBox).Text;  
        string Address = (editedItem["Address"].Controls[0] as TextBox).Text;  
        string City = (editedItem["City"].Controls[0] as TextBox).Text;  
 
        try  
        {  
            //Open the SqlConnection    
            SqlConnection.Open();  
            //Update Query to update the Datatable     
            string updateQuery = "UPDATE Employees set LastName='" + LastName + "',FirstName='" + FirstName + "',Title='" + Title + "',Address='" + Address + "',City='" + City + "' where EmployeeID='" + EmployeeID + "'";  
            SqlCommand.CommandText = updateQuery;  
            SqlCommand.Connection = SqlConnection;  
            SqlCommand.ExecuteNonQuery();  
            //Close the SqlConnection    
            SqlConnection.Close();  
 
 
        }  
        catch (Exception ex)  
        {  
            RadGrid1.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));  
            e.Canceled = true;  
        }    
 
    }  
Exemple #3
0
    protected void RadGrid1_InsertCommand(object source, Telerik.WebControls.GridCommandEventArgs e)  
    {  
        //Get the GridEditFormInsertItem of the RadGrid    
        GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;  
 
        //string EmployeeID = (insertedItem["EmployeeID"].Controls[0] as TextBox).Text;  
 
        string LastName = (insertedItem["LastName"].Controls[0] as TextBox).Text;  
        string FirstName = (insertedItem["FirstName"].Controls[0] as TextBox).Text;  
        string Title = (insertedItem["Title"].Controls[0] as TextBox).Text;  
        string Address = (insertedItem["Address"].Controls[0] as TextBox).Text;  
        string City = (insertedItem["City"].Controls[0] as TextBox).Text;  
         
        try  
        {  
            //Open the SqlConnection    
            SqlConnection.Open();  
            //Update Query to insert into  the database     
            string insertQuery = "INSERT into  Employees(LastName,FirstName,Title,Address,City) values('" + LastName + "','" + FirstName + "','" + Title + "','" + Address + "','" + City + "')";  
            SqlCommand.CommandText = insertQuery;  
            SqlCommand.Connection = SqlConnection;  
            SqlCommand.ExecuteNonQuery();  
            //Close the SqlConnection    
            SqlConnection.Close();  
 
 
        }  
        catch (Exception ex)  
        {  
            RadGrid1.Controls.Add(new LiteralControl("Unable to insert Employee. Reason: " + ex.Message));  
            e.Canceled = true;  
        }    
    protected void grdImportDetails_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "UpdateAll")
            {
                List <ImportDetails> imList = new List <ImportDetails>();
                //First store modifications made in this page to the dataset
                StoreValuesToDataSet();

                //populate list for modified or deleted rows
                PopulateImportDetailsList(imList);

                //send modifications to the DB image of the import
                ImportDetails importDetails    = new ImportDetails(CurrentConnectionManager);
                DataSet       dsNewCreatedFile = importDetails.UpdateBatchImportDetails(imList, IdImport);

                //create new file with current state of import
                bool result = CreateNewFile(dsNewCreatedFile);

                if (result)
                {
                    if (!Page.ClientScript.IsClientScriptBlockRegistered(this.Page.GetType(), "ButtonUpdateClick"))
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "ButtonUpdateClick", "window.returnValue = 1; window.close();", true);
                    }
                }
                else
                {
                    //After saving, if something went wrong re-load the grid
                    DsLogs = null;
                    LoadEditableGrid();
                }
            }
            //When changing the page, we need to store any possible modifications made to the current page in the underlying datasource of the
            //grid
            if (e.CommandName == "Page")
            {
                StoreValuesToDataSet();
            }
        }
        catch (IndException indExc)
        {
            SaveSuccessful = false;
            ShowError(indExc);
        }
        catch (Exception exc)
        {
            SaveSuccessful = false;
            ShowError(new IndException(exc));
        }
        finally
        {
            if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "ResizePopUp"))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "ResizePopUp", "SetPopUpHeight();", true);
            }
        }
    }
    protected void grdImportDetails_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "UpdateAll")
            {
                //First store modifications made in this page to the dataset
                StoreValuesToDataSet();

                List <AnnualImportDetails> imList = new List <AnnualImportDetails>();

                foreach (DataRow row in DsLogs.Tables[0].Rows)
                {
                    AnnualImportDetails importDetails = new AnnualImportDetails(CurrentConnectionManager);
                    importDetails.IdImport      = (int)row["IdImport"];
                    importDetails.IdRow         = (int)row["IdRow"];
                    importDetails.CostCenter    = (row["CostCenter"] == DBNull.Value) ? string.Empty : row["CostCenter"].ToString();
                    importDetails.ProjectCode   = (row["ProjectCode"] == DBNull.Value) ? string.Empty : row["ProjectCode"].ToString();
                    importDetails.WPCode        = (row["WPCode"] == DBNull.Value) ? string.Empty : row["WPCode"].ToString();
                    importDetails.AccountNumber = (row["AccountNumber"] == DBNull.Value) ? string.Empty : row["AccountNumber"].ToString();
                    if (row["Quantity"] != DBNull.Value)
                    {
                        importDetails.Quantity = (decimal)row["Quantity"];
                    }
                    if (row["Value"] != DBNull.Value)
                    {
                        importDetails.Value = (decimal)row["Value"];
                    }
                    if (row["CurrencyCode"] != DBNull.Value)
                    {
                        importDetails.CurrencyCode = row["CurrencyCode"].ToString();
                    }
                    if (row["Date"] != DBNull.Value)
                    {
                        importDetails.ImportDate = (DateTime)row["Date"];
                    }
                    imList.Add(importDetails);
                }

                if (imList.Count > 0)
                {
                    AnnualImportDetails annualImportDetails = new AnnualImportDetails(CurrentConnectionManager);
                    DataSet             dsNewCreatedFile    = annualImportDetails.UpdateBatchImportDetails(imList);

                    //After saving, remove the previous information from the session so that the old data (from the annual logs)
                    //is loaded from the db
                    DsLogs = null;
                    LoadEditableGrid();

                    CreateNewFile(dsNewCreatedFile);
                }

                if (!Page.ClientScript.IsClientScriptBlockRegistered(this.Page.GetType(), "ButtonUpdateClick"))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "ButtonUpdateClick", "window.returnValue = 1; window.close();", true);
                }
            }
            //When changing the page, we need to store any possible modifications made to the current page in the underlying datasource of the
            //grid
            if (e.CommandName == "Page")
            {
                StoreValuesToDataSet();
            }
        }
        catch (IndException indExc)
        {
            SaveSuccessful = false;
            ShowError(indExc);
        }
        catch (Exception exc)
        {
            SaveSuccessful = false;
            ShowError(new IndException(exc));
        }
        finally
        {
            if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "ResizePopUp"))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "ResizePopUp", "SetPopUpHeight();", true);
            }
        }
    }