在C#表单中,即使没有编写代码,也会填充表单 [英] In C# forms , form is populated even no code is written

查看:101
本文介绍了在C#表单中,即使没有编写代码,也会填充表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在编写程序来创建弹出消息的系统托盘。



在程序中检查是否它是有效的用户然后会显示通知



else



不会显示任何通知消息。



但是如果用户(用户代码)没有会议,则会弹出空白通知消息。



我想要隐藏通知消息。



请帮助我。



我已编写代码



Hi
I am writing program to create system tray to popup messages.

in the program i check if it is valid user then notification will be displayed

else

no notification message will be displayed.

But if the user(user code) has no meeting then blank notification message popup is coming.

I want to hide the notification message.

Please help me.

I have written code

using (SqlConnection CNN = new SqlConnection(AppManager.GetConnectionString()))
                    {
                        CNN.Open();
                        //getting all records from Meeting

                        using (SqlCommand scmd = new SqlCommand())
                        {

                            using (DataTable dtMeeting = new DataTable())
                            {

                                scmd.CommandText = "SELECT MeetingNumber from Meeting";

                                scmd.Connection = CNN;
                                SqlDataAdapter sdaMeeting = new SqlDataAdapter(scmd);
                                sdaMeeting.Fill(dtMeeting);


                                foreach (DataRow drMeeting in dtMeeting.Rows)
                                {

                                    using (DataTable dtAttendies = new DataTable())
                                    {
                                        scmd.CommandText = "SELECT MEETING.MeetingNumber, MEETING.MeetingType," +
                                          " MEETINGTYPEMASTER.MeetingTypeName, MEETING.MeetingName,MEETING.Location," +
                                          " MEETING.StartTime, MEETING.EndTime, MEETINGATTENDEES.AttendeeType," +
                                           
                                          " MEETING.Prepared, MEETING.PreparedBy, MEETING.PreparedDateTime," +
                                          " MEETING.BranchCode" +
                                          " FROM MEETING, MEETINGTYPEMASTER, EMPLOYEEMASTER ,MEETINGATTENDEES," +
                                          " DESIGNATIONMASTER, DEPARTMENTMASTER,USERMASTER" +
                                          " Where MEETING.MeetingType=MEETINGTYPEMASTER.MeetingTypeCode" +
                                          " And EMPLOYEEMASTER.EmployeeCode=MEETINGATTENDEES.EmployeeCode" +
                                          " And EMPLOYEEMASTER.DepartmentCode=DEPARTMENTMASTER.DepartmentCode" +
                                          " And EMPLOYEEMASTER.DesignationCode=DESIGNATIONMASTER.DesignationCode" +
                                          " And MEETING.BranchCode=xxx" +
                                          " And MEETING.MeetingNumber=MEETINGATTENDEES.MeetingNumber" +
                                          " And MEETING.MeetingNumber= " + drMeeting["MeetingNumber"] + "" + //This meeting number coming from outer loop
                                          " And EMPLOYEEMASTER.EmployeeCode=USERMASTER.EmployeeCode" +
                                          " And USERMASTER.UserCode=2";//User code

                                        scmd.Connection = CNN;
                                        SqlDataAdapter sdaAttendies = new SqlDataAdapter(scmd);
                                        sdaAttendies.Fill(dtAttendies);
                                        if (dtAttendies.Rows.Count != 0)
                                        {                                          
                                            foreach (DataRow drAttendies in dtAttendies.Rows)
                                            {
                                                lblMeetingType.Text = dtAttendies.Rows[0]["MeetingTypeName"].ToString();
                                                lblMeetingName.Text = dtAttendies.Rows[0]["MeetingName"].ToString();
                                            }
                                        }
                                        else
                                        {     // if the user code has no meeting still the blank popup is coming                                     
                                           //Here no code is given  but still the notification popup is coming

                                        }
                                    }
                                }
                            }
                        }

                    }
                    this.Close();
                }                
             
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            }      
        private void Form1_Resize(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                ShowInTaskbar = false;
                notifyIcon1.Visible = true;
                notifyIcon1.ShowBalloonTip(1000);
            }
        }
 private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ShowInTaskbar = true;
            notifyIcon1.Visible = false;
            WindowState = FormWindowState.Normal;            
        }    public Form1()
        {
            InitializeComponent();          
           
        }                              
 static class Program
    {
              [STAThread]
        static void Main()
        {            
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
          }





我无法纠正错误。



请帮我不要显示通知消息



谢谢



Rama < br $> b $ b

我尝试了什么:



我想要隐藏通知窗口显示甚至记录不存在



I am unable to rectify the error.

Please help me not to display notification message

Thanks

Rama

What I have tried:

I want to hide the notification window which is displayed even record is not there

推荐答案

这是奇怪的代码:

That's odd code:
foreach (DataRow drAttendies in dtAttendies.Rows)
 {
     lblMeetingType.Text = dtAttendies.Rows[0]["MeetingTypeName"].ToString();
     lblMeetingName.Text = dtAttendies.Rows[0]["MeetingName"].ToString();
 }

为什么每次循环写入相同的数据?



这不是你遇到的问题虽然:这可能是你的数据:我们没有任何访问权限。

所以,它将取决于你。

幸运的是,你有一个可用的工具,它可以帮助您了解正在发生的事情:调试器。你如何使用它取决于你的编译器系统,但是一个快速的谷歌用于你的IDE名称和调试器应该给你你需要的信息。



放一个该行断点:

Why loop writing the same data each time?

That isn't the problem you are having though: the chances are it's your data: and we don't have any access to that.
So, its going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the line:

if (dtAttendies.Rows.Count != 0)



并通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!


And run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


这篇关于在C#表单中,即使没有编写代码,也会填充表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆