Example #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbDeptNo.Text))
            {
                WinInfoHelper.ShowInfoWindow(this, "部门编码不能为空!");
                tbDeptNo.Focus();
                return;
            }
            if (string.IsNullOrWhiteSpace(tbDeptName.Text))
            {
                WinInfoHelper.ShowInfoWindow(this, "部门名称不能为空!");
                tbDeptName.Focus();
                return;
            }
            Maticsoft.Model.SMT_ORG_INFO info = new Maticsoft.Model.SMT_ORG_INFO();
            info.ORG_CODE    = tbDeptNo.Text.Trim();
            info.ORG_NAME    = tbDeptName.Text.Trim();
            info.ORDER_VALUE = iOrder.Value;
            Maticsoft.BLL.SMT_ORG_INFO bll = new Maticsoft.BLL.SMT_ORG_INFO();
            CtrlWaiting ctrlWaiting        = new CtrlWaiting(() =>
            {
                bool ret = false;
                try
                {
                    var exitscode = bll.GetModelList("ORG_CODE='" + info.ORG_CODE + "'");

                    if (_orgInfo == null)
                    {
                        if (exitscode.Count > 0)
                        {
                            WinInfoHelper.ShowInfoWindow(this, "部门编码已存在!");
                            return;
                        }
                        // info.ORDER_VALUE = 100;
                        info.PAR_ID = _parId;
                        DeptDataHelper.AddDept(info);
                        _orgInfo = info;
                        ret      = true;
                    }
                    else
                    {
                        if (exitscode.Count > 0)
                        {
                            if (!exitscode.Exists(m => m.ID == _orgInfo.ID))
                            {
                                WinInfoHelper.ShowInfoWindow(this, "部门编码已存在!");
                                return;
                            }
                        }

                        info.ID     = _orgInfo.ID;
                        info.PAR_ID = _orgInfo.PAR_ID;
                        //info.ORDER_VALUE = _orgInfo.ORDER_VALUE;
                        if (bll.Update(info))
                        {
                            _orgInfo.ORG_CODE = info.ORG_CODE;
                            _orgInfo.ORG_NAME = info.ORG_NAME;
                            ret = true;
                        }
                        else
                        {
                            WinInfoHelper.ShowInfoWindow(this, "更新部门失败,可能部门已被删除!");
                        }
                    }
                    if (ret)
                    {
                        this.BeginInvoke(new Action(() =>
                        {
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }));
                    }
                }
                catch (Exception ex)
                {
                    log.Error("添加或保修改部门:", ex);
                    WinInfoHelper.ShowInfoWindow(this, "添加或修改部门失败:" + ex.Message);
                }
            });

            ctrlWaiting.Show(this);
        }
Example #2
0
        private void biInput_Click(object sender, EventArgs e)
        {
            //WinInfoHelper.ShowInfoWindow(this, "建设中,敬请期待!");
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                try
                {
                    bool iscancel;
                    List <Maticsoft.Model.SMT_ORG_INFO> orgs = new List <Maticsoft.Model.SMT_ORG_INFO>();
                    ImportHelper2.ImportEx(out iscancel, 2, 1, 4, new ImportDataHandle((o, ise, row, error) =>
                    {
                        if (ise)
                        {
                            WinInfoHelper.ShowInfoWindow(this, "导入中发生行值错误,行号:" + row + " 错误:" + error);
                            return;
                        }
                        Maticsoft.Model.SMT_ORG_INFO org = new Maticsoft.Model.SMT_ORG_INFO();
                        org.ORG_CODE = o[0];
                        int ord      = 100;
                        int.TryParse(o[3], out ord);
                        org.ORDER_VALUE  = ord;
                        org.ORG_NAME     = o[2];
                        org.PAR_ORG_CODE = o[1];
                        org.PAR_ID       = -1;
                        orgs.Add(org);
                    }));
                    if (!iscancel)
                    {
                        if (orgs.Count == 0)
                        {
                            WinInfoHelper.ShowInfoWindow(this, "导入部门个数为0!");
                            return;
                        }
                        foreach (var item in orgs)
                        {
                            if (string.IsNullOrWhiteSpace(item.ORG_CODE) || string.IsNullOrWhiteSpace(item.ORG_NAME))
                            {
                                WinInfoHelper.ShowInfoWindow(this, "导入失败,存在部门编码或者名称为空!编码:" + item.ORG_CODE + ",名称:" + item.ORG_NAME + ",行号:" + orgs.IndexOf(item));
                                return;
                            }
                        }

                        foreach (var item in orgs)
                        {
                            var dept = DeptDataHelper.GetDeptByCode(item.ORG_CODE);
                            if (dept == null)
                            {
                                item.ID = DeptDataHelper.AddDept(item);//添加
                            }
                            else
                            {
                                item.ID     = dept.ID;
                                item.PAR_ID = dept.PAR_ID;
                                DeptDataHelper.UpdateDept(item);//更新
                            }
                        }
                        foreach (var item in orgs)
                        {
                            if (string.IsNullOrWhiteSpace(item.PAR_ORG_CODE))
                            {
                                continue;
                            }
                            var f = orgs.Find(m => m.ORG_CODE == item.PAR_ORG_CODE);
                            if (f == null)
                            {
                                f = DeptDataHelper.GetDeptByCode(item.PAR_ORG_CODE);
                            }
                            if (f == null)
                            {
                                if (item.PAR_ID == -1)
                                {
                                    continue;
                                }
                                item.PAR_ID = -1;
                            }
                            else
                            {
                                if (item.PAR_ID == f.ID)
                                {
                                    continue;
                                }
                                item.PAR_ID = f.ID;
                            }
                            DeptDataHelper.UpdateDept(item);
                        }
                        WinInfoHelper.ShowInfoWindow(this, "导入结束!");
                        this.Invoke(new Action(() =>
                        {
                            biRefreshDept_Click(sender, e);
                        }));
                    }
                }
                catch (Exception ex)
                {
                    log.Error("导入异常:", ex);
                    WinInfoHelper.ShowInfoWindow(this, "导入异常:" + ex.Message);
                }
            });

            waiting.Show(this);
        }