Exemplo n.º 1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            ClientForm form = new ClientForm();

            form.Text         = "Добавить клиента";
            form.button1.Text = "Добавить";
            if (form.ShowDialog() == DialogResult.OK)
            {
                using (var sql = new SqlConnection(Program.sql.ConnectionString))
                {
                    sql.Open();
                    var com = sql.CreateCommand();
                    com.CommandText = String.Format("insert into Клиенты values('{0}','{1}','{2}', '{3}')",
                                                    form.lastName.Text, form.firstName.Text, form.middleName.Text, form.contacts.Text);
                    com.ExecuteNonQuery();
                    sql.Close();
                }
                RefreshDB();
                Owner.OwnedForms.OfType <IRefreshable>().ToList().ForEach(f => f.RefreshDB());
            }
        }
Exemplo n.º 2
0
        //验证是否正确
        private void ValidateRight()
        {
            DBHelper db  = null;
            string   sql = "";

            try
            {
                int count = 0;
                db = new DBHelper();
                if (cboLoginType.Text == "管理员")
                {
                    sql = string.Format("select Password from Admin where A_AdminId='{0}' and A_Type ='{1}'", txtLoginId.Text.Trim(), "管理员");
                }
                else if (cboLoginType.Text == "服务员")
                {
                    sql = string.Format("select Password from Admin where A_AdminId='{0}' and A_Type ='{1}'", txtLoginId.Text.Trim(), "服务员");
                }
                else
                {
                    sql   = string.Format("select count(*) from Users where U_UsersId='{0}' and Pass='******'", txtLoginId.Text.Trim(), txtLoginPwd.Text);
                    count = (int)db.SelectOne(sql);
                }

                SqlDataReader sdr = db.SelectAll(sql);

                string tempPass = "";
                if (sdr.Read())
                {
                    tempPass = sdr["Password"].ToString();
                }
                if (tempPass == txtLoginPwd.Text)
                {
                    count = 1;
                }

                if (count > 0)
                {
                    this.Hide();
                    if (cboLoginType.Text == "客户")
                    {
                        UserHelper.UserId = txtLoginId.Text.Trim();

                        ClientForm cf = new ClientForm(txtLoginId.Text);
                        cf.Show();
                    }
                    else
                    {
                        UserHelper.LoginId   = txtLoginId.Text.Trim();
                        UserHelper.LoginType = cboLoginType.Text;
                        AnnalLog();
                        MainForm mf = new MainForm();
                        mf.Show();
                    }
                }
                else
                {
                    MessageBox.Show("用户名或密码错误!", "登录提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                //ClientForm cf = new ClientForm();
                //cf.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //db.GetClose();
            }
        }