/// <summary>
        /// 部門編集Pageを取得する
        /// </summary>
        /// <param name="id">部門ID</param>
        /// <returns>部門編集Page</returns>
        public DepartmentEditPage GetData(int id)
        {
            DepartmentEditPage page = new DepartmentEditPage();

            DepartmentDto dto = dao.GetData(id);
            if (dto != null)
            {
                page.Code = dto.Code;
                page.Id = dto.Id;
                page.Name = dto.Name;
                page.Order = Convert.ToString(dto.ShowOrder);
            }
            else
            {
                page = null;
            }
            return page;
        }
        public virtual int ExecUpdate(DepartmentEditPage dto)
        {
            if (dto == null)
                throw new ArgumentNullException("dto");

            DepartmentDto data = new DepartmentDto();
            data.Code = dto.Code;
            data.Id = dto.Id;
            data.Name = dto.Name;
            data.ShowOrder = Convert.ToInt32(dto.Order);

            if (dto.Id.HasValue)
            {
                DepartmentDto departmentDto = dao.GetData(dto.Id.Value);
                if (departmentDto != null)
                    return (dao.UpdateData(data));
                else
                    return (dao.InsertData(data));
            }
            else
            {
                return (dao.InsertData(data));
            }
        }
        /// <summary>
        /// フォームをロードしたときの処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmDepartmentEdit_Load(object sender, EventArgs e)
        {
            logger.InfoFormat("{0}がロードされました", Name);

            try
            {
                _InitializeControls();
                if (_id.HasValue)
                {
                    DepartmentEditPage data = service.GetData(_id.Value);
                    if (data != null)
                    {
                        DataSource = data;
                        btnDelete.Enabled = true;
                    }
                    else
                    {
                        throw new ApplicationException("部門データが見つかりませんでした");
                    }
                }
                else
                {
                    DataSource = new DepartmentEditPage();
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat(EXCEPTION_MSG_FORMAT, ex.Message);
                logger.Error(ex.StackTrace);
                MessageBox.Show(String.Format(EXCEPTION_MSG_FORMAT, ex.Message), Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Esempio n. 4
0
        public void TestEditService()
        {
            DepartmentEditPage data = editService.GetData(2);
            Assert.AreEqual(2, data.Id.Value, "ID");
            Assert.AreEqual("0002", data.Code, "Code");
            Assert.AreEqual("技術部", data.Name, "Name");
            Assert.AreEqual("2", data.Order, "Order");

            // 挿入のテスト
            data = new DepartmentEditPage();
            data.Code = "0102";
            data.Name = "管理部";
            data.Order = "4";

            Assert.AreEqual(1, editService.ExecUpdate(data), "Insert");

            // 更新のテスト
            data = new DepartmentEditPage();
            data.Id = 2;
            data.Code = "0020";
            data.Name = "技術事業部";
            data.Order = "5";

            Assert.AreEqual(1, editService.ExecUpdate(data), "Update");

            data = editService.GetData(2);
            Assert.AreEqual(2, data.Id.Value, "ID");
            Assert.AreEqual("0020", data.Code, "Code");
            Assert.AreEqual("技術事業部", data.Name, "Name");
            Assert.AreEqual("5", data.Order, "Order");
        }