public void Delete(DepartmentDisplayModel obj)
 {
     Channel.Delete(obj);
     try
     {
         if (this.State != System.ServiceModel.CommunicationState.Faulted)
         {
             this.Close();
         }
     }
     catch (Exception)
     {
         this.Abort();
     }
 }
        public Int64 GetId(DepartmentDisplayModel obj)
        {
            var result = Channel.GetId(obj);

            try
            {
                if (this.State != System.ServiceModel.CommunicationState.Faulted)
                {
                    this.Close();
                }
            }
            catch (Exception)
            {
                this.Abort();
            }
            return(result);
        }
 public void Delete(DepartmentDisplayModel obj)
 {
     _service.DeleteById(GetId(obj));
 }
 public long GetId(DepartmentDisplayModel obj)
 {
     return(obj.Target.Id);
 }
示例#5
0
        private async void btnOK_Click(object sender, RoutedEventArgs e)
        {
            #region 新增
            if (Om == OperationMode.AddMode)
            {
                string strErrorMsg = string.Empty;
                try
                {
                    DepartmentEditModel newEditDepartment = new DepartmentEditModel();
                    newEditDepartment.DepartmentCode = txtDeptCode.Text.Trim();
                    newEditDepartment.Name           = txtName.Text.Trim();
                    newEditDepartment.ShowIndex      = Convert.ToInt16(txtShowIndex.Value.Value);
                    newEditDepartment.Remark         = txtRemark.Text.Trim();
                    newEditDepartment.IsRealy        = chkIsRealDept.IsChecked.HasValue ? chkIsRealDept.IsChecked.Value : false;

                    DepartmentDisplayModel selectDept = cmbFatherDept.SelectedItem as DepartmentDisplayModel;
                    if (selectDept != null)
                    {
                        newEditDepartment.ParentCode = selectDept.Code;
                    }

                    newEditDepartment = await asyncProxy.CallAsync(c => c.Add(newEditDepartment, IsParent));

                    this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "新增部门成功!");
                    //MessageDialogResult result = await DialogManager.ShowMessageAsync(this, UIResources.MsgInfo, "新增部门成功!", MessageDialogStyle.Affirmative, null);
                    this.DialogResult = true;

                    #region 延时1s的弹窗
                    ////this.MetroDialogOptions.ColorScheme = UseAccentForDialogsMenuItem.IsChecked ? MetroDialogColorScheme.Accented : MetroDialogColorScheme.Theme;
                    //this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "新增部门成功!");
                    #endregion
                }
                catch (TimeoutException timeProblem)
                {
                    strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
                }
                catch (FaultException <LCFault> af)
                {
                    strErrorMsg = af.Detail.Message;
                }
                catch (FaultException unknownFault)
                {
                    strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
                }
                catch (CommunicationException commProblem)
                {
                    strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
                }
                if (strErrorMsg != string.Empty)
                {
                    await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "新增部门失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);

                    //AisinoMessageBox.Show("新增部门失败!原因:" + strMsg, UIResources.MsgError, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
            }
            #endregion

            #region 修改
            else
            {
                SelectSysDepartment.Name      = txtName.Text.Trim();
                SelectSysDepartment.ShowIndex = Convert.ToInt16(txtShowIndex.Value.Value);
                SelectSysDepartment.Remark    = txtRemark.Text.Trim();
                SelectSysDepartment.IsRealy   = chkIsRealDept.IsChecked.HasValue ? chkIsRealDept.IsChecked.Value : false;
                SelectSysDepartment.Stopped   = chkIsStoped.IsChecked.HasValue ? chkIsStoped.IsChecked.Value : false;
                DepartmentDisplayModel selectDept = cmbFatherDept.SelectedItem as DepartmentDisplayModel;
                if (selectDept != null)
                {
                    SelectSysDepartment.ParentCode = selectDept.Code;
                }

                string strErrorMsg = string.Empty;

                try
                {
                    SelectSysDepartment = await asyncProxy.CallAsync(c => c.Update(SelectSysDepartment));

                    //MessageDialogResult result = await DialogManager.ShowMessageAsync(this, UIResources.MsgInfo, "修改部门成功!", MessageDialogStyle.Affirmative, null);
                    this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "修改部门成功!");
                    this.DialogResult = true;
                }
                catch (TimeoutException timeProblem)
                {
                    strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
                }
                catch (FaultException <LCFault> af)
                {
                    strErrorMsg = af.Detail.Message;
                }
                catch (FaultException unknownFault)
                {
                    strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
                }
                catch (CommunicationException commProblem)
                {
                    strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
                }
                if (strErrorMsg != string.Empty)
                {
                    await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "修改部门失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);

                    //AisinoMessageBox.Show("修改部门失败!原因:" + strMsg, UIResources.MsgError, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
            }
            #endregion
        }