示例#1
0
        public AjaxMessage CreateEmployeeType(string TypeName)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";
            try
            {
                Sys_EmployeeType empType = new Sys_EmployeeType();
                empType.TypeName   = TypeName;
                empType.CreateTime = DateTime.Now;
                empType.EmployeeId = LoginInfo.UserInfo.EmployeeId;
                empType.Status     = (byte)SysStatus.Enable;
                int result = _empTypeService.Insert(empType);
                if (result > 0)
                {
                    ajax.IsSuccess = true;
                    ajax.Message   = "添加成功";
                }
            }
            catch (Exception e)
            {
                ajax.Message = e.Message;
            }

            return(ajax);
        }
示例#2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string msg = "Invalid input. Please refer to the error box";
            IEnumerable <string> brokenRules = null;
            bool isValid = true;

            if (newEmployeeType)
            {
                EmployeeType et = new EmployeeType(0, cbmEmployeeType.Text);
                isValid = et.Validate(out brokenRules);
                if (isValid)
                {
                    et.Insert();
                    employeeTypes.Add(et);
                    cbmEmployeeType.DataSource   = employeeTypes;
                    cbmEmployeeType.SelectedItem = et;
                }
            }

            if (newNotificationType)
            {
                NotificationType nt = new NotificationType(0, cmbNotificationType.Text);
                isValid = nt.Validate(out brokenRules);
                if (isValid)
                {
                    nt.Insert();
                    notificationTypes.Add(nt);
                    cmbNotificationType.DataSource   = notificationTypes;
                    cmbNotificationType.SelectedItem = nt;
                }
            }

            if (isValid)
            {
                isValid = validateCurrent(out brokenRules);
                if (isValid)
                {
                    if (insert)
                    {
                        currentPerson.Insert();
                        if (currentPerson.GetType() == typeof(Client))
                        {
                            (currentPerson as Client).Insert();
                            msg = "Client inserted";
                        }
                        else
                        {
                            (currentPerson as Employee).Insert();
                            msg = "Employee inserted";
                        }
                    }
                    else
                    {
                        currentPerson.Update();
                        if (currentPerson.GetType() == typeof(Client))
                        {
                            (currentPerson as Client).Update();
                            msg = "Client updated";
                        }
                        else
                        {
                            (currentPerson as Employee).Update();
                            msg = "Employee updated";
                        }
                    }
                    insert = editable = false;
                    enableTabs(!insert);
                    setControlEnabled(false);
                }
            }

            lstError.DataSource = brokenRules.ToList();
            MessageBox.Show(msg, "Modification Status", MessageBoxButtons.OK, isValid ? MessageBoxIcon.Information : MessageBoxIcon.Error);
        }