Develop Together9
Develop Together -9 ((ModuleName)ListForm View Code)
The first thing we need to do here is to import the object in the Business layer we created before into our project.. As an example, let’s look at the CustomerListForm codes that we use to list users : First we call CustomerDAL on the DAL layer at the top of the form. CustomerDAL customerDAL = new CustomerDAL(); Then we call by overriding the functions named ListData that we defined in the BaseListForm.. And we write the following codes below
public partial class BaseEditForm : RibbonForm
{
protected override void ListData()
{
Table = table; // we assign the table of the datagridview that we have added to the form to the table named in BaseListForm
table.GridControl.DataSource = customerDAL.LoadDataJoin(context);
//Then we send the Linq query to the datasource section of the table named LoadDataJoin on the DAL layer that we defined above with the context we added.
Navigators = MyNavigator.controlNavigator;//we had put navigator below, we send it.
}
//We have successfully listed the data. Now let’s write the codes of the buttons we will use in the related forms. When we want to delete a record selected in the table, we call the EntityDelete function that we defined in BaseListForm and fill it inside: protected override void EntityDelete()
{
object CellValue = table.GetFocusedRowCellValue("Id"); //we assign the Id column of the selected table to our variable of type object CellValue.
if (MessageFunctions.DeleteMessage("Customer") == DialogResult.Yes) //then we send the Customer String as the field name to be deleted on the screen to the Delete Message functions of our MessageFunctions functions and if the user presses Yes, we will do the following.
{
customerDAL.Delete(context, d => d.Id == (long)CellValue);//We are sending the selected one in the lamp with context to the Delete that we have defined on IbaseRepository that CustomerDAL is implementing.
customerDAL.Save(context);//After transactions, we save.
ListData();//we are renewing our list.
}
}
//Now we override the our required variable to open in edit mode.
protected override void OpenEditForm()
{
string selectedEntity = table.GetFocusedRowCellValue(colCustomerCode).ToString(); // We pass the column named CustomerCode of the currently selected row to the variable named selectedEntity.
CustomerEditForm frm = new CustomerEditForm(customerDAL.BaseSingle(context, s => s.CustomerCode == selectedEntity)); // then we will open a CustomerEditForm as ShowDialog. So we say that we want to list the BaseSingle in IbaseRepository, which CustomerDAL is implementing, and send the selected variable in the lamp.
frm.DataLoad(); //we call our DataLoad variable defined in BaseEditForm so that the data in the opened form is full.
frm.ShowDialog();// Now we open as ShowDialog
ListData(); //Since the process will return to this form after the user will work after this line and we are renewing our list.
}
protected override void OpenEditFormAdd() // we are doing this process in order to send our form to be opened as showDialog as above.
{
CustomerEditForm frm = new CustomerEditForm(new Customer()); // Here, since the value we send to the form is not edit, it will be new, so we send one entity by new.
frm.DataLoad(); //we run dataload variable so that the buttons in the form can perform operations.
frm.ShowDialog();//we open as ShowDialog
ListData();//After the process, we are updating our list again.
}
protected override void ActivityOpen() // Here we run button codes to examine Customers plug activities.
{
string selectedEntity = table.GetFocusedRowCellValue(colCustomerCode).ToString(); //again we take the value of the selected CustomerCode column, and pass to the selectedEntity variable.
ShowForms.ShowListForm(selectedEntity); //we send the form named CustomerActivityListForm to the Showforms function and pass the selected value to the function ShowListForm. This function will open the form as showdialog in the background and load the data.
ListData();//it will be renewed if there are any changes back.
}
}