public virtual int ExecUpdate(EmployeeEditPage data)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            EmployeeDto dto = new EmployeeDto();
            dto.Code = data.Code;
            dto.DeptNo = data.Depart;
            dto.EntryDay = data.Entry;
            dto.Gender = data.Gender;
            dto.Id = data.Id;
            dto.Name = data.Name;

            if (data.Id.HasValue)
            {
                EmployeeDto e1 = dao.GetData(data.Id.Value);
                if (e1 != null)
                    return (dao.UpdateData(dto));
                else
                    return (dao.InsertData(dto));
            }
            else
            {
                return (dao.InsertData(dto));
            }
        }
        /// <summary>
        /// 社員データを取得する
        /// </summary>
        /// <param name="id">社員ID</param>
        /// <returns>社員データ</returns>
        public EmployeeEditPage GetData(int id)
        {
            EmployeeEditPage page = new EmployeeEditPage();

            EmployeeDto dto = dao.GetData(id);
            if (dto != null)
            {
                page.Code = dto.Code;
                page.Depart = dto.DeptNo;
                page.Entry = dto.EntryDay;
                page.Gender = dto.Gender;
                page.Id = dto.Id;
                page.Name = dto.Name;
            }
            else
            {
                page = null;
            }
            return page;
        }
Exemplo n.º 3
0
        public void TestEditService()
        {
            EmployeeEditPage data = editService.GetData(3);
            Assert.AreEqual(3, data.Id.Value, "Id");
            Assert.AreEqual("佐藤愛子", data.Name, "Name");
            Assert.AreEqual("010003", data.Code, "Code");
            Assert.AreEqual(2, data.Gender, "Gender");
            Assert.AreEqual(new DateTime(2001, 4, 1, 0, 0, 0),
                            data.Entry, "Entry");
            Assert.AreEqual(1, data.Depart, "DeptNo");

            // 挿入のテスト
            data = new EmployeeEditPage();
            data.Code = "060006";
            data.Name = "後藤六郎";
            data.Entry = new DateTime(2006, 4, 1, 0, 0, 0);
            data.Gender = 1;
            data.Depart = 1;

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

            // 更新のテスト
            data = new EmployeeEditPage();
            data.Id = 2;
            data.Code = "999999";
            data.Name = "鈴木二郎";
            data.Entry = new DateTime(1999, 5, 1, 0, 0, 0);
            data.Gender = 1;
            data.Depart = 2;

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

            data = editService.GetData(2);
            Assert.AreEqual(2, data.Id.Value, "Id");
            Assert.AreEqual("鈴木二郎", data.Name, "Name");
            Assert.AreEqual("999999", data.Code, "Code");
            Assert.AreEqual(1, data.Gender, "Gender");
            Assert.AreEqual(new DateTime(1999, 5, 1, 0, 0, 0),
                            data.Entry, "Entry");
            Assert.AreEqual(2, data.Depart, "DeptNo");
        }
Exemplo n.º 4
0
        /// <summary>
        /// フォームをロードしたときの処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmEmployeeEdit_Load(object sender, EventArgs e)
        {
            logger.InfoFormat("{0}がロードされました", Name);

            _InitializeControls();
            if (_id.HasValue)
            {
                EmployeeEditPage data = service.GetData(_id.Value);
                if (data != null)
                {
                    DataSource = data;
                    btnDelete.Enabled = true;
                }
                else
                {
                    DataSource = null;
                    throw new ApplicationException("社員データが見つかりませんでした");
                }
            }
            else
            {
                DataSource = new EmployeeEditPage();
            }
        }