-1

更改文件名后出现几个错误。从默认表单名称 (Form2.cs)、(Form1.cs) 等到 System.cs、LoginPage.cs,当我改回默认表单名称 (Form2.cs) 时,会发生这种情况,出现错误。我应该怎么办?有什么解决方案可以让我将这个问题追溯到我更改文件名之前的时间吗?

在此处输入图像描述

这是“Form1.cs”的完整代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Data.OleDb;
using System.Security.Principal;

namespace Sell_System
{
    public partial class Form1 : Form
    {
        string connectionString = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\Archives\Projects\Program\Sell System\Sell System\App_Data\db1.accdb;Persist Security Info=False;");

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label4.Visible = false;
            comboBox1.Items.Add("English");
            comboBox1.Items.Add("Indonesian");
            comboBox1.SelectedIndex = 0;

            OleDbDataReader dReader;
            OleDbConnection conn = new OleDbConnection(connectionString);
            conn.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT DISTINCT [Username] FROM [Member]", conn); 
            dReader = cmd.ExecuteReader();
            AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();

            while (dReader.Read())
            {
               namesCollection.Add(dReader.GetString(0));
            }

            textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
            textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            textBox1.AutoCompleteCustomSource = namesCollection;

            dReader.Close();
            conn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(connectionString);

            conn.Open();

            DataTable dt = new DataTable();

            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Member] WHERE [Username]='" + textBox1.Text + "'AND [Password]='" + textBox2.Text + "'", conn);

            OleDbDataAdapter da = new OleDbDataAdapter(cmd);

            da.Fill(dt);

            if (dt.Rows.Count != 0)
            {
                this.Hide();

                Form2 secondaryForm = new Form2(this);
                secondaryForm.ShowDialog();

                this.Close();
            }

            else if (textBox1.Text == "Admin" && textBox2.Text == "")
            {
                this.Hide();

                Form5 fifthForm = new Form5();
                fifthForm.ShowDialog();

                this.Close();
            }

            else
            {
                label4.Visible = true;

                if (comboBox1.SelectedItem.ToString() == "English")
                {
                    RecursiveClearTextBoxes(this.Controls);
                    label4.Text = "Invalid Username or Password!";
                    label4.ForeColor = Form1.Drawing.Color.Red;
                }

                else if (comboBox1.SelectedItem.ToString() == "Indonesian")
                {
                    RecursiveClearTextBoxes(this.Controls);
                    label4.Text = "Username atau Password anda salah!";
                    label4.ForeColor = Form1.Drawing.Color.Red;
                }
            }

            conn.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem.ToString() == "English")
            {
                ChangeLanguage("en");
            }

            else if (comboBox1.SelectedItem.ToString() == "Indonesian")
            {
                ChangeLanguage("id");
            }
        }

        private void ChangeLanguage(string language)
        {
            foreach (Control c in this.Controls)
            {
                ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
                resources.ApplyResources(c, c.Name, new CultureInfo(language));
            }
        }

        private void RecursiveClearTextBoxes(Control.ControlCollection cc)
        {
            foreach (Control ctrl in cc)
            {
                TextBox tb = ctrl as TextBox;

                if (tb != null)
                {
                    tb.Clear();
                }

                else
                {
                    RecursiveClearTextBoxes(ctrl.Controls);
                }
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Hide();

            Form3 thirdForm = new Form3();
            thirdForm.ShowDialog();

            this.Close();
        }

        protected virtual void ClosedHandler(object sender, EventArgs e)
        {
            FormsHandler.Remove(this);
        }

    }
}

“Form1.cs”上的错误是:

“Sell_System.Form1.cs”不包含“绘图”的定义

4

1 回答 1

1

试着看一下设计器类(designer.cs),可能设计器类还在引用旧文件名?

于 2013-08-26T08:04:22.593 回答