Ejemplo n.º 1
0
        private void RegisterAccount()
        {
            if (!(String.IsNullOrEmpty(tb_Username.Text) || String.IsNullOrEmpty(tb_Password.Text) || String.IsNullOrEmpty(tb_FirstName.Text) || String.IsNullOrEmpty(tb_LastName.Text)))
            {
                if (tb_Password.Text == tb_ConfirmPassword.Text)
                {
                    using (SrisContext ctx = new SrisContext())
                    {
                        var registerUser = new Account
                        {
                            Username    = tb_Username.Text,
                            Password    = tb_Password.Text,
                            FirstName   = tb_FirstName.Text,
                            LastName    = tb_LastName.Text,
                            AccessLevel = cb_UserRole.Text,
                            IsActive    = false
                        };
                        ctx.Account.Add(registerUser);
                        ctx.SaveChanges();
                    }

                    MessageBox.Show("Registration Successfull.Please wait for Confirmation");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Password did not match");
                }
            }
            else
            {
                MessageBox.Show("Please filled up the fields");
            }
        }
Ejemplo n.º 2
0
        private void Bt_SaveUser_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(tb_Username.Text))
            {
                MessageBox.Show("Plesae Fill up the required fields");
            }
            else
            {
                if (String.IsNullOrEmpty(tempId_UserList))
                {
                    if (tb_Password.Text == tb_ConfirmPassword.Text)
                    {
                        SQLCon.DbCon();
                        SQLCon.sqlCommand             = new SqlCommand("INSERT INTO Accounts VALUES(@Username,@Password,@FirstName,@LastName,@AccessLevel,@IsActive,@IsLogon,@MiddleName)", SQLCon.sqlConnection);
                        SQLCon.sqlCommand.CommandType = CommandType.Text;
                        SQLCon.sqlCommand.Parameters.AddWithValue("@Username", tb_Username.Text);
                        SQLCon.sqlCommand.Parameters.AddWithValue("@Password", tb_Password.Text);
                        SQLCon.sqlCommand.Parameters.AddWithValue("@FirstName", tb_FirstName.Text);
                        SQLCon.sqlCommand.Parameters.AddWithValue("@MiddleName", tb_MiddleName.Text);
                        SQLCon.sqlCommand.Parameters.AddWithValue("@LastName", tb_LastName.Text);
                        SQLCon.sqlCommand.Parameters.AddWithValue("@AccessLevel", cb_AccessLevel.Text);
                        SQLCon.sqlCommand.Parameters.AddWithValue("@IsActive", 1);
                        SQLCon.sqlCommand.Parameters.AddWithValue("@IsLogon", 1);
                        SQLCon.sqlCommand.ExecuteNonQuery();
                        MessageBox.Show("User added Successfully");
                        LoadUserList();
                    }
                    else
                    {
                        MessageBox.Show("Password did not match");
                        tb_Password.Clear();
                        tb_ConfirmPassword.Clear();
                    }
                }
                else
                {
                    using (SrisContext ctx = new SrisContext())
                    {
                        int     tempId      = Convert.ToInt32(tempId_UserList);
                        Account userAccount = ctx.Account.Where(x => x.USER_ID == tempId).FirstOrDefault();
                        userAccount.Username    = tb_Username.Text;
                        userAccount.Password    = tb_Password.Text;
                        userAccount.FirstName   = tb_FirstName.Text;
                        userAccount.MiddleName  = tb_MiddleName.Text;
                        userAccount.LastName    = tb_LastName.Text;
                        userAccount.AccessLevel = cb_AccessLevel.Text;
                        userAccount.IsActive    = checkBox_Status.Checked;
                        ctx.SaveChanges();
                        MessageBox.Show("User update Successfully");
                        LoadUserList();
                        tempId_UserList = null;
                        dataGridView_UserList.ClearSelection();
                    }
                }
            }

            ClearText();
        }
        private void btUpdate_Click(object sender, EventArgs e)
        {
            using (SrisContext ctx = new SrisContext())
            {
                //var unitSpecification = new UnitSpecification();
                //foreach (DataGridViewRow row in dataGridView_UnitSpecs.Rows)
                //{
                //    unitSpecification.HardwareComponent = row.Cells["Column2"].Value.ToString();
                //    unitSpecification.Remarks = row.Cells["Column3"].Value.ToString();
                //    unitSpecification.II_ID = tempIdRequest;
                //    ctx.UnitSpecification.Add(unitSpecification);
                //    ctx.SaveChanges();
                //}


                var unitSpecificationUpdate = new UnitSpecification();
                foreach (DataGridViewRow itemUnitSpecification in dataGridView_UnitSpecs.Rows)
                {
                    string hardWareComponents = itemUnitSpecification.Cells["Column2"].Value.ToString();
                    string hardwareRemarks    = itemUnitSpecification.Cells["Column3"].Value.ToString();

                    if (!(ctx.UnitSpecification.Any(x => x.II_ID == tempIdRequest && x.HardwareComponent == hardWareComponents && x.Remarks == hardwareRemarks)))
                    {
                        unitSpecificationUpdate.HardwareComponent = itemUnitSpecification.Cells["Column2"].Value.ToString();
                        unitSpecificationUpdate.Remarks           = itemUnitSpecification.Cells["Column3"].Value.ToString();
                        unitSpecificationUpdate.II_ID             = tempIdRequest;
                        ctx.UnitSpecification.Add(unitSpecificationUpdate);
                        ctx.SaveChanges();
                    }
                    else
                    {
                        var usID = ctx.UnitSpecification.Where(x => x.II_ID == tempIdRequest && x.HardwareComponent == hardWareComponents && x.Remarks == hardwareRemarks).Select(p => p.US_ID).FirstOrDefault().ToString();
                        unitSpecificationUpdate.HardwareComponent = itemUnitSpecification.Cells["Column2"].Value.ToString();
                        unitSpecificationUpdate.Remarks           = itemUnitSpecification.Cells["Column3"].Value.ToString();
                        unitSpecificationUpdate.II_ID             = tempIdRequest;
                        unitSpecificationUpdate.US_ID             = Int32.Parse(usID);
                        ctx.UnitSpecification.Attach(unitSpecificationUpdate);
                        ctx.Entry(unitSpecificationUpdate).State = System.Data.Entity.EntityState.Modified;
                        ctx.SaveChanges();
                    }
                }
            }
        }