Hi Team
I have textbox and want to only be enabled when its admin and superadmin for security reason, when the page loads after login, this logic is not working and did set the debug does goes in but the problem is textbox is not not editable for these roles.
What I have tried:
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"/>
// front end for textbox name
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 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("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("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("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;
}
if(user.UserTypeID == Convert.ToInt32(Enum.UserType.Admin))
{
txtWeighbridgeWeight.IsEnabled = true;
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;
} if(user.UserTypeID == Convert.ToInt32(Enum.UserType.SuperUser))
{
txtWeighbridgeWeight.IsEnabled = true;
}
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()));
}
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(item3, this));
menuQC.Add(new SubItem("Users", new UCLabAssistant()));
}
else
{
}
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);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "/n" + ex.InnerException);
}
}