Пример #1
0
        private void gcusers_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex == -1) { return; }
            txtusername.Text = Convert.ToString(gcusers.Rows[e.RowIndex].Cells["UserName"].Value.ToString());
            txtpassword.Text = Convert.ToString(gcusers.Rows[e.RowIndex].Cells["Password"].Value.ToString());
            cboposition.SelectedValue = ((plabel2.Entities.Entity)(gcusers.Rows[e.RowIndex].Cells[2].Value)).Id;

            var user = Session.CreateQuery("from Luser p where p.Id =" + gcusers.Rows[e.RowIndex].Cells["Id"].Value.ToString()).Future<Luser>();
            EditUser = user.First();
            txtusername.Enabled = false;
            txtpassword.Enabled = false;
            cmdadd.Text = "Add";
            cmdedit.Text = "Edit";
        }
Пример #2
0
        private void cmdadd_Click(object sender, EventArgs e)
        {
            if (cmdadd.Text == "Add")
            {
                txtusername.Text = "";
                txtpassword.Text = "";
                txtusername.Enabled = true;
                txtpassword.Enabled = true;

                cmdadd.Text = "Save";
            }
            else if (cmdadd.Text == "Save")
            {
                if (txtusername.Text.Trim() == "")
                {
                    XtraMessageBox.Show("กรุณากรอกชื่อผู้ใช้งานก่อน  !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtusername.Focus();
                    return;
                }
                if (txtpassword.Text.Trim() == "")
                {
                    XtraMessageBox.Show("กรุณากรอกรหัสผ่านก่อน  !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtpassword.Focus();
                    return;
                }

                var _user = Session.CreateQuery("from Luser p where p.UserName='******'").Future<Luser>();
                if (_user.Count() > 0)
                {
                    XtraMessageBox.Show("ชื่อนี้ซ้ำ  !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtusername.Focus();
                    return;
                }

                newUser = new Luser();
                newUser.UserName = txtusername.Text.Trim();
                newUser.Password = txtpassword.Text.Trim();
                var position = Session.CreateQuery("from Position p where p.Id =" + cboposition.SelectedValue.ToString()).Future<Position>();
                positioncur = position.First();
                newUser.Position = positioncur;

                using (ITransaction tx = Session.BeginTransaction())
                {
                    Session.Save(newUser);
                    Session.Flush();
                    tx.Commit();
                }
                // Session.Dispose();
                clartData();
                ShowData();
                cmdadd.Text = "Add";
                txtusername.Enabled = false;
                txtpassword.Enabled = false;

            }
        }
Пример #3
0
 public frmMain(Luser _user)
 {
     InitializeComponent();
     user = _user;
     DevExpress.Skins.SkinManager.EnableFormSkins();
 }