Beispiel #1
0
 private void btnSaveCompany_Click(object sender, EventArgs e)
 {
     if (ValidationUtility.FieldNotAllowNull(txtCompanyCode) == false)
     {
         lblNotify1.SetText(UI.hasnoinfomation, LabelNotify.EnumStatus.Failed);
         return;
     }
     if (m_Company == null)
     {
         return;
     }
     CoverObjectUtility.GetAutoBindingData(this.tableLayoutPanel1, m_Company);
     if (m_Deputy.CompanyId <= 0)
     {
         lblNotify1.SetText(UI.failed, ToolBoxCS.LabelNotify.EnumStatus.Failed);
         return;
     }
     m_Deputy.SetModify();
     try
     {
         SaveCompany(m_Company);
         lblNotify1.SetText(UI.success, ToolBoxCS.LabelNotify.EnumStatus.Success);
         gridUtility2.UpdateRow <Company>(m_Company);
         InitializeForm(m_Company);
     }
     catch
     {
         lblNotify1.SetText(UI.failed, ToolBoxCS.LabelNotify.EnumStatus.Failed);
     }
 }
Beispiel #2
0
        private Deputy SaveAccount(Users user)
        {
            int companyId = string.IsNullOrWhiteSpace(txtCompanyId.Text) == false?Convert.ToInt32(txtCompanyId.Text) : 0;

            if (companyId <= 0)
            {
                lblNotify1.SetText(UI.deputyhasnocompany, LabelNotify.EnumStatus.Failed);
                return(null);
            }
            if (ValidationUtility.IsTextAllowed(user.UserName) == false)
            {
                lblNotify1.SetText(UI.usernotallowspace, LabelNotify.EnumStatus.Failed);
                return(null);
            }
            user.Sex = rdNam.Checked == true ? true : false;
            user.SetCreate();
            user.UserGroupId = (int)UserTypeFlag.Customer;
            m_Deputy         = new Deputy();
            CoverObjectUtility.GetAutoBindingData(tableLayoutPanel2, m_Deputy);
            if (user.UserId <= 0)
            {
                m_Deputy.DeputyId = 0;
            }
            m_Deputy.DeputyName = user.FullName;
            m_Deputy.IsActive   = cbActive.Checked;
            m_Deputy.Email      = user.Email;
            m_Deputy.Phone      = user.Phone;
            m_Deputy.Address    = user.Address;
            m_Deputy.Sex        = user.Sex;
            m_Deputy.UserId     = user.UserId;
            m_Deputy.CompanyId  = companyId;

            IList <Deputy> lstExistsDeputy = gridControl1.DataSource as IList <Deputy>;
            Deputy         main            = lstExistsDeputy != null?lstExistsDeputy.Where(p => p.IsMain == true && p.DeputyId != m_Deputy.DeputyId).FirstOrDefault() : null;

            if (main == null)
            {
                m_Deputy.IsMain = true;
            }
            else
            {
                m_Deputy.IsMain = false;
            }
            using (IUnitOfWork uow = new UnitOfWork())
            {
                if (user.UserId <= 0)
                {
                    uow.UsersRepository.Add(user);
                    m_Deputy.SetCreate();
                    m_Deputy.UserId   = user.UserId;
                    m_Deputy.DeputyId = 0;
                    uow.DeputyRepository.Add(m_Deputy);
                }
                else
                {
                    uow.UsersRepository.Update(user);
                    m_Deputy.SetModify();
                    uow.DeputyRepository.Update(m_Deputy);
                }
                uow.Commit();
            }
            return(m_Deputy);
        }