public bool UpdateHonPhoi() { try { if (checkInput()) { //check ton tai roi DataTable tblHonPhoi = GxHonPhoi.HonPhoiExists(NguoiChong, NguoiVo); if (tblHonPhoi != null && tblHonPhoi.Rows.Count > 0) { operation = GxOperation.EDIT; maHonPhoi = (int)tblHonPhoi.Rows[0][HonPhoiConst.MaHonPhoi]; } else { tblHonPhoi = Memory.GetData(SqlConstants.SELECT_HONPHOI_THEO_ID, new object[] { maHonPhoi }); if (Memory.ShowError() || tblHonPhoi == null) { return(false); } if (tblHonPhoi.Rows.Count == 0) { maHonPhoi = Memory.Instance.GetNextId(HonPhoiConst.TableName, HonPhoiConst.MaHonPhoi, false); operation = GxOperation.ADD; } } tblHonPhoi.TableName = HonPhoiConst.TableName; DataRow dataReturn = null; if (operation == GxOperation.ADD) { dataReturn = tblHonPhoi.NewRow(); AssignDataSource(dataReturn); tblHonPhoi.Rows.Add(dataReturn); } else if (operation == GxOperation.EDIT) { if (tblHonPhoi.Rows.Count > 0) { dataReturn = tblHonPhoi.Rows[0]; AssignDataSource(dataReturn); } } else { return(false); } DataSet ds = new DataSet(); ds.Tables.Add(tblHonPhoi); //Update UpdateDate field foreach (DataRow rowTmp in tblHonPhoi.Rows) { rowTmp[GiaoDanConst.UpdateDate] = Memory.Instance.GetServerDateTime(); } //delete GiaoDanHonPhoi if (operation == GxOperation.EDIT) { string deleteSql = "DELETE FROM GiaoDanHonPhoi WHERE MaHonPhoi=?"; Memory.ExecuteSqlCommand(deleteSql, new object[] { maHonPhoi }); if (Memory.ShowError()) { return(false); } } DataTable tblGiaoDanHonPhoi = Memory.GetTableStruct(GiaoDanHonPhoiConst.TableName); //them nguoi nam DataRow newRow = tblGiaoDanHonPhoi.NewRow(); newRow[GiaoDanHonPhoiConst.MaHonPhoi] = maHonPhoi; newRow[GiaoDanHonPhoiConst.MaGiaoDan] = NguoiVo; newRow[GiaoDanHonPhoiConst.SoThuTu] = GxHonPhoi.GetNextSoThuTu(NguoiVo); tblGiaoDanHonPhoi.Rows.Add(newRow); //them nguoi nu newRow = tblGiaoDanHonPhoi.NewRow(); newRow[GiaoDanHonPhoiConst.MaHonPhoi] = maHonPhoi; newRow[GiaoDanHonPhoiConst.MaGiaoDan] = NguoiChong; newRow[GiaoDanHonPhoiConst.SoThuTu] = GxHonPhoi.GetNextSoThuTu(NguoiChong); tblGiaoDanHonPhoi.Rows.Add(newRow); //add to data set ds.Tables.Add(tblGiaoDanHonPhoi); Memory.UpdateDataSet(ds); ds.Tables.Remove(tblHonPhoi); if (Memory.ShowError()) { return(false); } } return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi Exception (GxHonPhoiGiaDinh, UpdateHonPhoi)", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
private bool checkInput() { if (!Validator.IsNumber(txtMaHonPhoi.Text)) { MessageBox.Show("Mã hôn phối phải được nhập số"); txtMaHonPhoi.Focus(); return(false); } if (string.IsNullOrEmpty(txtNguoiChong.Text.Trim()) && txtNguoiChong.MaGiaoDan == -1 || string.IsNullOrEmpty(txtNguoiVo.Text.Trim()) && txtNguoiVo.MaGiaoDan == -1) { MessageBox.Show("Hãy nhập đầy đủ người nam và người nữ!"); txtNguoiChong.Focus(); return(false); } DataTable tblTanHien = Memory.GetData(SqlConstants.SELECT_TANHIEN_HIENTAI, maGiaoDan); if (!Memory.ShowError() && tblTanHien != null && tblTanHien.Rows.Count > 0) { Memory.ShowError("Giáo dân này đã đi tu và chưa hồi tục nên không thể lập hôn phối"); return(false); } //check ton tai roi DataTable tblHonPhoi = GxHonPhoi.HonPhoiExists(txtNguoiChong.MaGiaoDan, txtNguoiVo.MaGiaoDan); if (operation == GxOperation.ADD && tblHonPhoi != null && tblHonPhoi.Rows.Count > 0) { MessageBox.Show("Đã tồn tại hôn phối cho đôi bạn nhập!"); txtNguoiChong.Focus(); return(false); } if (!Validator.IsNumber(txtSoThuTu.Text)) { MessageBox.Show("Số thứ tự phải được nhập số", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSoThuTu.Focus(); return(false); } if (string.IsNullOrEmpty(txtTenHonPhoi.Text.Trim())) { MessageBox.Show("Hãy nhập tên đôi hôn phối!"); txtTenHonPhoi.Focus(); return(false); } DataRow rowNguoiChong = txtNguoiChong.CurrentRow; DataRow rowNguoiVo = txtNguoiVo.CurrentRow; if (!Memory.IsNullOrEmpty(dtNgayHonPhoi.Value)) { DateTime dNgayHonPhoi = Memory.GetDateFromString(dtNgayHonPhoi.Value.ToString()); if (rowNguoiChong != null && !Memory.IsNullOrEmpty(rowNguoiChong[GiaoDanConst.NgaySinh])) { DateTime d1 = Memory.GetDateFromString(rowNguoiChong[GiaoDanConst.NgaySinh].ToString()); if (d1.CompareTo(dNgayHonPhoi) >= 0) { Memory.ShowError("Ngày hôn phối phải sau ngày sinh của người chồng"); return(false); } if (dNgayHonPhoi.Year - d1.Year < GxConstants.TUOI_HON_PHOI_NAM) { if (MessageBox.Show("Người chồng chưa đủ tuổi kết hôn với ngày hôn phối. Bạn có chắc muốn tiếp tục chọn người này không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return(false); } } } if (rowNguoiVo != null && !Memory.IsNullOrEmpty(rowNguoiVo[GiaoDanConst.NgaySinh])) { DateTime d1 = Memory.GetDateFromString(rowNguoiVo[GiaoDanConst.NgaySinh].ToString()); if (d1.CompareTo(dNgayHonPhoi) >= 0) { Memory.ShowError("Ngày hôn phối phải sau ngày sinh của người vợ"); return(false); } if (dNgayHonPhoi.Year - d1.Year < GxConstants.TUOI_HON_PHOI_NU) { if (MessageBox.Show("Người vợ chưa đủ tuổi kết hôn so với ngày hôn phối. Bạn có chắc muốn tiếp tục chọn người này không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return(false); } } } } return(true); }