|
Try making a Boolean variable.
On login, the app must determine if the logged in user is admin or not.
Then, set the appropriate values.
On login:
If user is admin: adminbool = true
else
adminbool = false
On form_load
If(adminbool=false)
{
Menustripitem_name.enable=false;
}
else
{
Menustripitem_name.enable=true;
}
You get the idea, right?
|
|
|
|
|
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.IO.Ports
Imports System.Threading
Imports System.Text.RegularExpressions
Public Class clsSMS
#Region "Open and Close Ports"
'Open Port
Public Function OpenPort(p_strPortName As String, p_uBaudRate As Integer, p_uDataBits As Integer, p_uReadTimeout As Integer, p_uWriteTimeout As Integer) As SerialPort
receiveNow = New AutoResetEvent(False)
Dim port As New SerialPort()
Try
port.PortName = p_strPortName
'COM1
port.BaudRate = p_uBaudRate
'9600
port.DataBits = p_uDataBits
'8
port.StopBits = StopBits.One
'1
port.Parity = Parity.None
'None
port.ReadTimeout = p_uReadTimeout
'300
port.WriteTimeout = p_uWriteTimeout
'300
port.Encoding = Encoding.GetEncoding("iso-8859-1")
AddHandler port.DataReceived, New SerialDataReceivedEventHandler(AddressOf port_DataReceived)
port.Open()
port.DtrEnable = True
port.RtsEnable = True
Catch ex As Exception
Throw ex
End Try
Return port
End Function
'Close Port
Public Sub ClosePort(port As SerialPort)
Try
port.Close()
RemoveHandler port.DataReceived, New SerialDataReceivedEventHandler(AddressOf port_DataReceived)
port = Nothing
Catch ex As Exception
Throw ex
End Try
End Sub
#End Region
'Execute AT Command
Public Function ExecCommand(port As SerialPort, command As String, responseTimeout As Integer, errorMessage As String) As String
Try
port.DiscardOutBuffer()
port.DiscardInBuffer()
receiveNow.Reset()
port.Write(command & vbCr)
Dim input As String = ReadResponse(port, responseTimeout)
If (input.Length = 0) OrElse ((Not input.EndsWith(vbCr & vbLf & "> ")) AndAlso (Not input.EndsWith(vbCr & vbLf & "OK" & vbCr & vbLf))) Then
Throw New ApplicationException("No success message was received.")
End If
Return input
Catch ex As Exception
Throw ex
End Try
End Function
'Receive data from port
Public Sub port_DataReceived(sender As Object, e As SerialDataReceivedEventArgs)
Try
If e.EventType = SerialData.Chars Then
receiveNow.[Set]()
End If
Catch ex As Exception
Throw ex
End Try
End Sub
Public Function ReadResponse(port As SerialPort, timeout As Integer) As String
Dim buffer As String = String.Empty
Try
Do
If receiveNow.WaitOne(timeout, False) Then
Dim t As String = port.ReadExisting()
buffer += t
Else
If buffer.Length > 0 Then
Throw New ApplicationException("Response received is incomplete.")
Else
Throw New ApplicationException("No data received from phone.")
End If
End If
Loop While Not buffer.EndsWith(vbCr & vbLf & "OK" & vbCr & vbLf) AndAlso Not buffer.EndsWith(vbCr & vbLf & "> ") AndAlso Not buffer.EndsWith(vbCr & vbLf & "ERROR" & vbCr & vbLf)
Catch ex As Exception
Throw ex
End Try
Return buffer
End Function
#Region "Count SMS"
Public Function CountSMSmessages(port As SerialPort) As Integer
Dim CountTotalMessages As Integer = 0
Try
'#Region "Execute Command"
Dim recievedData As String = ExecCommand(port, "AT", 300, "No phone connected at ")
recievedData = ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.")
Dim command As [String] = "AT+CPMS?"
recievedData = ExecCommand(port, command, 1000, "Failed to count SMS message")
Dim uReceivedDataLength As Integer = recievedData.Length
'#End Region
'#Region "If command is executed successfully"
If (recievedData.Length >= 45) AndAlso (recievedData.StartsWith("AT+CPMS?")) Then
'#Region "Parsing SMS"
Dim strSplit As String() = recievedData.Split(","c)
Dim strMessageStorageArea1 As String = strSplit(0)
'SM
Dim strMessageExist1 As String = strSplit(1)
'Msgs exist in SM
'#End Region
'#Region "Count Total Number of SMS In SIM"
'#End Region
CountTotalMessages = Convert.ToInt32(strMessageExist1)
'#End Region
'#Region "If command is not executed successfully"
ElseIf recievedData.Contains("ERROR") Then
'#Region "Error in Counting total number of SMS"
Dim recievedError As String = recievedData
recievedError = recievedError.Trim()
'#End Region
recievedData = "Following error occured while counting the message" & recievedError
End If
'#End Region
Return CountTotalMessages
Catch ex As Exception
Throw ex
End Try
End Function
#End Region
#Region "Read SMS"
Public receiveNow As AutoResetEvent
Public Function ReadSMS(port As SerialPort, p_strCommand As String) As ShortMessageCollection
' Set up the phone and read the messages
Dim messages As ShortMessageCollection = Nothing
Try
'#Region "Execute Command"
' Check connection
ExecCommand(port, "AT", 300, "No phone connected")
' Use message format "Text mode"
ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.")
' Use character set "PCCP437"
ExecCommand(port, "AT+CSCS=""PCCP437""", 300, "Failed to set character set.")
' Select SIM storage
ExecCommand(port, "AT+CPMS=""SM""", 300, "Failed to select message storage.")
' Read the messages
Dim input As String = ExecCommand(port, p_strCommand, 5000, "Failed to read the messages.")
'#End Region
'#Region "Parse messages"
'#End Region
messages = ParseMessages(input)
Catch ex As Exception
Throw ex
End Try
If messages IsNot Nothing Then
Return messages
Else
Return Nothing
End If
End Function
Public Function ParseMessages(input As String) As ShortMessageCollection
Dim messages As New ShortMessageCollection()
Try
Dim r As New Regex("\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.+)\r\n")
Dim m As Match = r.Match(input)
While m.Success
Dim msg As New ShortMessage()
'msg.Index = int.Parse(m.Groups[1].Value);
msg.Index = m.Groups(1).Value
msg.Status = m.Groups(2).Value
msg.Sender = m.Groups(3).Value
msg.Alphabet = m.Groups(4).Value
msg.Sent = m.Groups(5).Value
msg.Message = m.Groups(6).Value
messages.Add(msg)
m = m.NextMatch()
End While
Catch ex As Exception
Throw ex
End Try
Return messages
End Function
#End Region
#Region "Send SMS"
Shared readNow As New AutoResetEvent(False)
Public Function sendMsg(port As SerialPort, PhoneNo As String, Message As String) As Boolean
Dim isSend As Boolean = False
Try
Dim recievedData As String = ExecCommand(port, "AT", 300, "No phone connected")
recievedData = ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.")
Dim command As [String] = "AT+CMGS=""" & PhoneNo & """"
recievedData = ExecCommand(port, command, 300, "Failed to accept phoneNo")
command = Message & Char.ConvertFromUtf32(26) & vbCr
recievedData = ExecCommand(port, command, 3000, "Failed to send message")
'3 seconds
If recievedData.EndsWith(vbCr & vbLf & "OK" & vbCr & vbLf) Then
isSend = True
ElseIf recievedData.Contains("ERROR") Then
isSend = False
End If
Return isSend
Catch ex As Exception
Throw ex
End Try
End Function
Private Shared Sub DataReceived(sender As Object, e As SerialDataReceivedEventArgs)
Try
If e.EventType = SerialData.Chars Then
readNow.[Set]()
End If
Catch ex As Exception
Throw ex
End Try
End Sub
#End Region
#Region "Delete SMS"
Public Function DeleteMsg(port As SerialPort, p_strCommand As String) As Boolean
Dim isDeleted As Boolean = False
Try
'#Region "Execute Command"
Dim recievedData As String = ExecCommand(port, "AT", 300, "No phone connected")
recievedData = ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.")
Dim command As [String] = p_strCommand
recievedData = ExecCommand(port, command, 300, "Failed to delete message")
'#End Region
If recievedData.EndsWith(vbCr & vbLf & "OK" & vbCr & vbLf) Then
isDeleted = True
End If
If recievedData.Contains("ERROR") Then
isDeleted = False
End If
Return isDeleted
Catch ex As Exception
Throw ex
End Try
End Function
#End Region
End Class
' MORE
' Request by Email....
CAO
|
|
|
|
|
? A big code dump. So what? What's the problem?
|
|
|
|
|
Hi,
We have a Windows Forms project with quite a few flatstyle buttons.
When we disable the buttons, the colors of the buttons are changed automatically
Is it possible to override this somehow, so we can control the colors ourselves?
Thanks,
Karl
|
|
|
|
|
You could create your own buttons, the simplest way is to inherit from Button and override some functions:
public class BernieButton : Button
{
protected override void OnEnabledChanged(EventArgs e)
{
base.OnEnabledChanged(e);
....
}
}
|
|
|
|
|
Yeah, that's the expected behavior. It's the standard notification to the user that the button will no longer work in the current situation.
Why would you want to change this?? If you don't change the color, the user will wonder what's wrong with your app because they think they're clicking on an active button and nothing is happening!
|
|
|
|
|
In fact the BackColor of control doesn't change and only ForeColor and BorderColor change.
Set FlatStyle to Flat, Set a non system BorderColor in FlatAppearance, Set a non system BackColor and you will see background and border will not change.
Only ForeColor changes to show difference of enabled and disabled button.
|
|
|
|
|
i create control and this control derived from gridview control.then i add 2 column in constructor like this :
InitializeComponent();
this.AutoGenerateColumns = false;
DataGridViewCheckBoxColumn cb = new DataGridViewCheckBoxColumn();
cb.HeaderText = "";
cb.Name = "dgvcSelect";
this.Columns.Add(cb);
DataGridViewTextBoxColumn tb = new DataGridViewTextBoxColumn();
tb.Name = "dgvcRowNumber";
tb.HeaderText = "ردیف";
but when i run my program 4 column generate for me.where is the problem?
please help me
|
|
|
|
|
Don't cross post in multiple forums.
Pick one forum best suited to your question and post your question once!
|
|
|
|
|
Need a bit more of the code the way this code looks is that you have created two columns but can't see enough to know what is happening.
Please post the entire scope of the problem so we can help.
Thanks
JD
http://www.seitmc.com/seitmcWP
|
|
|
|
|
You realize that this post is over 6 months old, right? Chances are good we'll never hear from his again.
|
|
|
|
|
HA! Well no I didn't look at the date. Doh! Just looking to do some give back.
Thanks
JD
http://www.seitmc.com/seitmcWP
|
|
|
|
|
Hi everybody,
I'm trying to bind a class variable to a textbox.
the data class looks like:
<pre lang="c#">
public class route
{
public string name { get; set; }
public int adress { get; set; }
public route()
{
name = "";
adress = 0;
}
}
public class adr
{
public int index { get; set; }
public route r1 { get; set; }
public route r2 { get; set; }
public adr()
{
index = 0;
r1 = new route();
r2 = new route();
}
}
public class para
{
public int i1 { get; set; }
public int i2 { get; set; }
}
public class adrData
{
public string label { get; set; }
public adr ad { get; set; }
public para pa { get; set; }
}
When I try to bind f.e. ad.r1.name to a textbox text via designer, it offers only label, ad and pa for binding.
What am I missing here?
Thnx adv for your answers.
modified 21-Jul-13 10:42am.
|
|
|
|
|
What type is "ad.r1.name"? As far as I can see from your code, there's only one "name" property, and that's a string, whereas the bindin-options imply that "name" contains an adrData ?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
its a tree structure:
the string name is an element of class route,
route r1 is an element of class adr,
adr ad is an element of class adrData.
|
|
|
|
|
First, I think you need to add a constructor to 'adrData:
public class adrData
{
public string label { get; set; }
public adr ad { get; set; }
public para pa { get; set; }
// ctor
public adrData()
{
label = "";
ad = new adr();
pa = new para();
}
} Then, in code, you can do something like this:
adrData newAdrData = new adrData();
newAdrData.ad.r1.name = "Route Name #1";
textBox1.DataBindings.Add("Text", newAdrData, "ad.r1.name"); To bind to a specific instance of 'adrData. Unless you create a new instance of 'ad, within 'adrData, then you never initialize the 'routes: because only creating a new instance of 'adr will initialize the 'routes.
~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal
|
|
|
|
|
Hi ,
At the moment I'm developing an Windows Form application and looking for a logger. I have seen log4c++ and boost.log, but both loggers won't work because some code isn't compatible with /clr code. Does somebody has a logger which is compatible with Windows forms?
|
|
|
|
|
|
Hello All,
I haven't coded a lot in Winforms C#. In any case I need to fetch a temporary stored image image from the local disk and process in a vendors API. Their method requires Bitmap bitmap for the parameters as indicated here(//vendor.Reader.AnalyzeField(Bitmap bitmap)).
// Example 1 - This works when I use hard coded texted.
// Example 2 fails attempting to use with the variable. The error is "Parameter is not valid".
1 - Bitmap btm = new Bitmap "C:\\Images\\2.tif");
// The variable fails here.
2 - Bitmap btm = new Bitmap(_transferFile);
//Perform recognition
result = vendor.Reader.AnalyzeField(btm);
Thanks in advance
modified 11-Jul-13 14:03pm.
|
|
|
|
|
fincity wrote: The error is "Parameter is not valid". Then you need to use a parameter that is valid, i.e. a Bitmap as specified in the method definition. You have not specified what type _transferFile is, but I assume it is not a Bitmap .
Use the best guess
|
|
|
|
|
You mean something similar to below code?
string fileName = "C:\\Images\\2.tif";
Bitmap btm = new Bitmap(fileName);
result = vendor.Reader.AnalyzeField(btm); Where is the initialization-code of your _transferFile member?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In Windows form , I'm displaying a Project_Table using tableAdapterManager.
I followed as per http://www.youtube.com/watch?v=3w2JkLcp-UA[^]
Project_Id int Primary Key with Identity specification as identity
Project_Name nvarchar(50)
Project_Type nvarchar(50)
Platform_Type nvarchar(50)
Start_Date date
Customer nvarchar(50)
In the code
private void project_TableBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.project_TableBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.pLMDataSet);
}
I'm getting error Cannot insert explicit value for identity column in table 'Project_Table' when IDENTITY_INSERT is set to OFF
Even after executing following script I'm getting same error.
USE [PLM]
GO
SET IDENTITY_INSERT [dbo].[Project_Table] ON
go
Another table Phases_table has dependency on Project_Table through FK constraint. Is the error because of this constraint?
Are there any sample examples on C# with MSSQL database which use multiple windows forms with multiples table linked in an hierarchy?
|
|
|
|
|
Member 8387808 wrote: I'm getting error Cannot insert explicit value for identity column in table 'Project_Table' when IDENTITY_INSERT is set to OFF Means you're passing in a value for the primary key - but that column is readonly, as the database will generate a value for you.
Member 8387808 wrote: Another table Phases_table has dependency on Project_Table through FK constraint. Is the error because of this constraint? Can you explain me the difference between a PK and a FK? If not, no problem - we'll start there.
Member 8387808 wrote: Are there any sample examples on C# with MSSQL database which use multiple windows forms with multiples table linked in an hierarchy? Yes. Now a bit more specific, or I'll have to point to a random db-application.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Well, I'm plum out of ideas. I've got a listbox with a List<> for its DataSource. When I init it - before the form is displayed, it works. But not after that. I am modifying the List<> contents and then I run:
public void RefreshLbx()
{
lbxQuotes.DataSource = null;
lbxQuotes.DataSource = _quotes;
}
where _quotes is the List<>
Now here is where it gets weird. I put a button on the form - here's its handler:
private void btnRefresh_Click(object sender, EventArgs e)
{
RefreshLbx();
}
So that when I click on the button then the lbxQuotes listbox is properly updated. But in the modification code - where I call RefreshLbx() directly, nothing happens.
I even tried invoking btnRefresh_Click() in the code, but alas could not find the magic.
Oh one other thought - the modification code is in a timer event handler - could this be a problem of trying to modify a control from a different thread? All I am doing is changing the List<> contents and then reseting the DataSource.
I must be missing something to kick the listbox to redisplay, or something... HELP!
|
|
|
|
|
Wow but this is weird. Okay, I found the solution because I tried the recommendation given below:
lbxQuotes.DataSource = null;
lbxQuotes.DataSource = _quotes;
lbxQuotes.SelectionMode = SelectionMode.None;
lbxQuotes.SelectionMode = SelectionMode.One;
That is, I added the SelectionMode two lines... and this caused (only once) a "from different thread" exception. Weird, I'm NOT running a method - I'm changing data... hmmm... I wonder if the DataSource is instead a Property (which secretly runs a method). D'oh!
Okay, so the solution was to create a delegate in the main form, for the RefreshLbx method, and have the RefreshLbx method recursively call this, as below:
public void RefreshLbx()
{
if (lbxQuotes.InvokeRequired)
{
lbxQuotes.Invoke(_refreshLbx);
}
else
{
lbxQuotes.DataSource = null;
lbxQuotes.DataSource = _quotes;
}
}
with the _refreshLbx delegate defined in the form's class as:
private delegate void RefreshLbxDg8();
private RefreshLbxDg8 _refreshLbx;
Then just init the delegate in the form constructor (after the InitializeComponent() call):
_refreshLbx = RefreshLbx;
Now I am able to update the listbox contents from a timer handler.
|
|
|
|
|