Exemple #1
0
        /// <summary>
        /// Save user information
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtConfirm.Text == txtPassword.Text)
            {
                User us = new User();
                if (_userId != 0)
                {
                    us.LoadByPrimaryKey(_userId);
                }
                else
                {
                    us.AddNew();
                    us.UserName = txtUsername.Text;
                    us.Password = txtPassword.Text;
                }
                us.FullName = txtFullName.Text;
                us.Address  = txtAddress.Text;
                us.Mobile   = txtMobile.Text;
                us.Active   = ckActive.Checked;
                us.UserType = Convert.ToInt32(cboUserType.SelectedValue);
                us.Save();


                string            selectedCommodity = cbCommodity.EditValue.ToString();
                string[]          comArr            = selectedCommodity.Split(',');
                UserCommodityType uc = new UserCommodityType();
                uc.DeleteAllTypeForUser(us.ID);
                foreach (var t in comArr)
                {
                    uc.AddNew();
                    uc.TypeID = Convert.ToInt16(t);
                    uc.UserID = us.ID;
                    uc.Save();
                }

                string    selectedStore = cbStore.EditValue.ToString();
                string[]  storeArr      = selectedStore.Split(',');
                UserStore ustr          = new UserStore();
                ustr.DeleteAllTStoreForUser(us.ID);
                if (selectedStore != "")
                {
                    foreach (var t in storeArr)
                    {
                        ustr.AddNew();
                        ustr.StoreID = Convert.ToInt16(t);
                        ustr.UserID  = us.ID;
                        ustr.Save();
                    }
                }
                XtraMessageBox.Show("successfully Saved", "Success");
                PopulateUser();
            }
            else
            {
                XtraMessageBox.Show("Password doesnt match!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }