I have a textbox and my requirement is, need to enable this textbox only for both admin and super-admin as soon log in to the application. Current code or logic is not working as expected and need some help on my logic so both roles can be able to edit the textbox for weight only when truck is captured.
// front end.
`<TextBox
VerticalAlignment="Center"
Foreground="Black"
Background="White"
Width="268"
FontWeight="SemiBold"
FontSize="36" TextAlignment="Right" Height="55" Margin="1,1,1,1" Padding="2,2,2,2" HorizontalAlignment="Center" x:Name="txtWeighbridgeWeight" TextChanged="txtWeighbridgeWeight_TextChanged"/>`
// back end logic
`public MainWindow()
{
try
{
InitializeComponent();
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
lblPath.Content = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.UpdateLocation.AbsolutePath;
}
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
dispatcherTimer.Start();
panelWidth = sidepanel1.Width;
panelWidth = sidePanel.Width;
User user = new User();
LabAssistant user1 = new LabAssistant();
if (Properties.Settings.Default.Quality == "Q")
{
user1 = Managers.ManageLabAssistant.GetUserByPK(Properties.Settings.Default.LoggedInUserID);
txtLoggedInUser.Text = user1.UserName;
}
else
{
user = Managers.UserManager.GetUserByPK(Properties.Settings.Default.LoggedInUserID);
txtLoggedInUser.Text = user.Username;
}
txtStation.Text = Properties.Settings.Default.Station;
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
this.txtVersion.Text = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
}
var menuWB = new List<SubItem>();
menuWB.Add(new SubItem("Raw Material", new UCRaw_Material()));
menuWB.Add(new SubItem("Finished Product", new UCFinishedProduct()));
var item0 = new ItemMenu("Weighbridge", menuWB, PackIconKind.Truck);
//var menuSchedule = new List<SubItem>();
//var item1 = new ItemMenu("Finished Product", menuSchedule, PackIconKind.TruckDelivery);
var menuReports = new List<SubItem>();
menuReports.Add(new SubItem("Customer", new UCManageCustomer()));
menuReports.Add(new SubItem("Client", new UCManageClients()));
menuReports.Add(new SubItem("Bin", new UCManageBin()));
menuReports.Add(new SubItem("Drivers", new UCManageDriver()));
menuReports.Add(new SubItem("Farm", new UCManageFarm()));
menuReports.Add(new SubItem("Material", new UCManageMaterial()));
menuReports.Add(new SubItem("Product", new UCManageProduct()));
menuReports.Add(new SubItem("Supplier", new UCManageSupplier()));
menuReports.Add(new SubItem("Vehicle", new UCManageVehicle()));
menuReports.Add(new SubItem("Batch Material", new UCManageBatchMaterial()));
menuReports.Add(new SubItem("Feed Production Schedule", new UCFeedproductionSchedule()));
menuReports.Add(new SubItem("Feed Production Requirements", new UCOrderRequirements()));
menuReports.Add(new SubItem("Batch Feed Format", new UCManageBatchFeedFormat()));
// menuReports.Add(new SubItem("Users", new UCManageUsers()));
//menuReports.Add(new SubItem("RM Code to Stock Code", new UCManageRM_Stock()));
menuReports.Add(new SubItem("Status", new UCStatusScreen()));
menuReports.Add(new SubItem("Recipes", new UCManageRecipe()));
menuReports.Add(new SubItem("Batch Recipes", new UCManageBatchRecipe()));
menuReports.Add(new SubItem("Configuration", new UCConfigScreen()));
// menuReports.Add(new SubItem("Scale Settings", new UCScaleSettings()));
menuReports.Add(new SubItem("Reports", new UCManageReports()));
var item2 = new ItemMenu("Administration", menuReports, PackIconKind.AccountCog);
var menuQC = new List<SubItem>();
menuQC.Add(new SubItem("Crumble", new UCManageQcCrumbleData()));
menuQC.Add(new SubItem("Pellet", new UCManagePelletData()));
menuQC.Add(new SubItem("Grist", new UCManageGrist()));
// menuQC.Add(new SubItem("Users", new UCLabAssistant()));
menuQC.Add(new SubItem("Reports", new UCQualityReports()));
var item3 = new ItemMenu("Quality Control", menuQC, PackIconKind.Controller);
if (user.UserTypeID == Convert.ToInt32(Enum.UserType.Admin))
{
Menu.Children.Add(new UserControlMenuItem(item0, this));
Menu.Children.Add(new UserControlMenuItem(item2, this));
Menu.Children.Add(new UserControlMenuItem(item3, this));
menuQC.Add(new SubItem("Users", new UCLabAssistant()));
menuQC.Add(new SubItem("Supervisor", new UCQCManageSupervisor()));
menuWB.Add(new SubItem("Reports", new UCManageSupervisorReports()));
txtWeighbridgeWeight.IsEnabled = true; // this not working
}
if(user.UserTypeID == Convert.ToInt32(Enum.UserType.Admin))
{
txtWeighbridgeWeight.IsEnabled = true;// this is not working, cant edit any value when page is loaded as an admin and Super-User
txtWeighbridgeWeight.IsReadOnly = false;
}
if (user.UserTypeID == Convert.ToInt32(Enum.UserType.SuperUser))
{
Menu.Children.Add(new UserControlMenuItem(item0, this));
Menu.Children.Add(new UserControlMenuItem(item2, this));
Menu.Children.Add(new UserControlMenuItem(item3, this));
menuReports.Add(new SubItem("Users", new UCManageUsers()));
menuQC.Add(new SubItem("Users", new UCLabAssistant()));
menuQC.Add(new SubItem("Supervisor", new UCQCManageSupervisor()));
menuWB.Add(new SubItem("Reports", new UCManageSupervisorReports()));
txtWeighbridgeWeight.IsEnabled = true; // this gets called first
} if(user.UserTypeID == Convert.ToInt32(Enum.UserType.SuperUser))
{
txtWeighbridgeWeight.IsEnabled = true; // here is not working
}
if (user.UserTypeID == Convert.ToInt32(Enum.UserType.User))
{
Menu.Children.Add(new UserControlMenuItem(item0, this));
}
if (user.UserTypeID == Convert.ToInt32(Enum.UserType.Supervisor))
{
Menu.Children.Add(new UserControlMenuItem(item0, this));
menuWB.Add(new SubItem("Reports", new UCManageSupervisorReports()));
}
// inventory controller logic implemented
if(user.UserTypeID == Convert.ToInt32(Enum.UserType.InventController))
{
Menu.Children.Add(new UserControlMenuItem(item0, this));
menuWB.Add(new SubItem("Reports", new UCManageReports()));
}
else
{
txtWeighbridgeWeight.IsReadOnly = true;
}
if (user1.UserLevelID == Convert.ToInt32(Enum.UserType.Admin))
{
// Menu.Children.Add(new UserControlMenuItem(item0, this));
// Menu.Children.Add(new UserControlMenuItem(item2, this));
Menu.Children.Add(new UserControlMenuItem(item3, this));
menuQC.Add(new SubItem("Users", new UCLabAssistant()));
}
else
{
// txtWeighbridgeWeight.IsReadOnly = true;
}
if (user1.UserLevelID == Convert.ToInt32(Enum.UserType.User))
{
Menu.Children.Add(new UserControlMenuItem(item3, this));
}
else
{
txtWeighbridgeWeight.IsReadOnly = true;
}
if (user.UserTypeID == Convert.ToInt32(Enum.UserType.Admin) || user.UserTypeID == Convert.ToInt32(Enum.UserType.User)|| user.UserTypeID == Convert.ToInt32(Enum.UserType.Supervisor) || user.UserTypeID == Convert.ToInt32(Enum.UserType.SuperUser) || user.UserTypeID == Convert.ToInt32(Enum.UserType.InventController))
{
if (Properties.Settings.Default.Station.ToUpper() != "BOTTOM")
{
UCRaw_Material uc = new UCRaw_Material();
SwitchScreen(uc);
}
else
{
UCFinishedProduct uc = new UCFinishedProduct();
SwitchScreen(uc);
}
}
if (user1.UserLevelID == Convert.ToInt32(Enum.UserType.Admin) || user1.UserLevelID == Convert.ToInt32(Enum.UserType.User))
{
if (Properties.Settings.Default.Station.ToUpper() != "BOTTOM")
{
UCManageQcCrumbleData uc = new UCManageQcCrumbleData();
SwitchScreen(uc);
}
else
{
UCManagePelletData uc = new UCManagePelletData();
SwitchScreen(uc);
}
}
//UCManageRecipe uc = new UCManageRecipe();
//SwitchScreen(uc);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "/n" + ex.InnerException);
}
}`