Ejemplo n.º 1
0
 private void Addposition(Position pos)
 {
     using (ITransaction tx = Session.BeginTransaction())
     {
         Session.Save(pos);
         Session.Flush();
         tx.Commit();
     }
 }
Ejemplo n.º 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;

            }
        }
Ejemplo n.º 3
0
 private void cboposition_SelectedValueChanged(object sender, EventArgs e)
 {
     var position = Session.CreateQuery("from Position p where p.Id =" + cboposition.SelectedValue.ToString()).Future<Position>();
     positioncur = position.First();
 }
Ejemplo n.º 4
0
        private void cmdedit_Click(object sender, EventArgs e)
        {
            if (cmdedit.Text == "Edit")
            {

                txtusername.Enabled = true;
                txtpassword.Enabled = true;

                cmdedit.Text = "Save";
            }
            else if (cmdedit.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;
                    }

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

                    EditUser.Position = positioncur;

                    using (ITransaction tx = Session.BeginTransaction())
                    {
                        Session.SaveOrUpdate(EditUser);
                        Session.Flush();
                        tx.Commit();
                    }
                    // Session.Dispose();
                    XtraMessageBox.Show("แก้ไข ข้อมูลเรียบร้อยแล้ว ");
                    ShowData();
                    cmdedit.Text = "Edit";
                    txtusername.Enabled = false;
                    txtpassword.Enabled = false;

            }
        }