Exemplo n.º 1
0
 public bool Save(StUser newStUser)
 {
     int TempId = dc.CreateStUser(newStUser);
     if (TempId > 0)
     {
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
        public int CreateStUser(StUser newStUser)
        {
            int result = -1;
            try
            {
                Conn = db.openConnAccess();
                tr = Conn.BeginTransaction();

                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO tbUser(SUsername,SPassword,SPriority)");
                sb.Append(" VALUES ('"+newStUser.Username+"','"+newStUser.Password +"','"+newStUser.Priority+"')");

                string sqlSave;
                sqlSave = sb.ToString();

                com = new OleDbCommand();
                com.Connection = Conn;
                com.CommandText = sqlSave;
                com.Transaction = tr;
                com.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                Conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                Conn.Close();
            }

            return result;
        }
Exemplo n.º 3
0
 public frmMain(ref StUser _user)
 {
     InitializeComponent();
     iUser = _user;
 }
Exemplo n.º 4
0
        public StUser getByUserAndPass(string _user,string _pass)
        {
            StUser stUser = null;

            try
            {
                Conn = db.openConnAccess();

                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append("  SELECT ID,SUsername,SPassword,SPriority ");
                sb.Append("  FROM tbUser ");
                sb.Append("  WHERE  SUsername ='******'");
                sb.Append("  AND  SPassword ='******'");
                string sql;
                sql = sb.ToString();

                com = new OleDbCommand();
                com.CommandText = sql;
                com.CommandType = CommandType.Text;
                com.Connection = Conn;
                dr = com.ExecuteReader();
                if (dr.HasRows)
                {

                    DataTable dt = new DataTable();
                    dt.Load(dr);

                    foreach (DataRow drw in dt.Rows)
                    {
                        stUser = new StUser();
                        stUser.ID = Convert.ToInt32(drw["ID"].ToString());
                        stUser.Username = Convert.ToString(drw["SUsername"].ToString());
                        stUser.Password = Convert.ToString(drw["SPassword"].ToString());
                        stUser.Priority = Convert.ToString(drw["SPriority"].ToString());

                    }

                }

            }
            catch (Exception ex)
            {
                dr.Close();
                Conn.Close();
                return null;
                throw ex;

            }
            finally
            {
                Conn.Close();
            }

            return stUser;
        }
Exemplo n.º 5
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtNewUserName.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อน UserName ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtNewUserName.Focus();
                return;
            }

            if (txtNewUserName.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อน Password ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtNewUserName.Focus();
                return;
            }
            if (cbopriority.Text == "")
            {
                MessageBox.Show("กรุณาเลือกสิทธิการเข้าใช้ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                cbopriority.Focus();
                return;
            }

            StUser _user = serviecuser.getByUserAndPass(txtNewUserName.Text.Trim(), txtNewPassWord.Text.Trim());
            if (_user == null)
            {
                StUser newStUser = new StUser();
                newStUser.Username = txtNewUserName.Text.Trim();
                newStUser.Password = txtNewPassWord.Text.Trim();

                if (cbopriority.Text.Equals("พนักงานสต๊อก"))
                {
                    newStUser.Priority = "1";
                }
                else if (cbopriority.Text.Equals("ผู้จัดการร้าน"))
                {
                    newStUser.Priority = "2";
                }

                bool save = serviecuser.Save(newStUser);
                if (save)
                {
                    MessageBox.Show("เพิ่มผู้ใช้ เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtNewUserName.Text = "";
                    txtNewPassWord.Text = "";
                }
                else
                {
                    MessageBox.Show("ไม่สามารถ เพิ่มผู้ใช้ใหม่ได้!!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
            else
            {
                MessageBox.Show("มีผู้ใช้นี้อยู่แล้ว !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtNewUserName.Focus();
                return;

            }
        }