private void GetStory() { dbConnection db = new dbConnection(); DataTable Tt = db.CarryOutSqlGeDataTable( "select top 1 NiLifeStory ,NiName from [Family].[dbo].[tblNumberInfo] where LEN(NiLifeStory)>30 order by newid()"); txtStroyFamily.Text = " " + Tt.Rows[0]["NiName"].ToString() + ":" + Tt.Rows[0]["NiLifeStory"].ToString(); }
/// <summary> /// 配偶的出生日期必须在本人的健在时间段内 /// </summary> /// <param name="dtPeiOuBirth"></param> /// <param name="FatherId"></param> /// <returns></returns> public bool CheckHavePeiOu(DateTime dtPeiOuBirth, int FatherId) { dbConnection Get = new dbConnection(); //父亲出生日期 DateTime dt = Convert.ToDateTime(Get.CarryOutSqlGetFirstColmun(String.Format(" select NiBirthDay from [Family].[dbo].[tblNumberInfo] where NiId ={0}", FatherId))); int NianLingFather = Convert.ToInt32(Get.CarryOutSqlGetFirstColmun(String.Format("select 年龄 from [Family].[dbo].[vwNumberInfo] where NiId ={0}", FatherId))); //年龄 DateTime dtmin = dt.AddYears(0); DateTime max = dt.AddYears(NianLingFather); if (dtPeiOuBirth > max || dtPeiOuBirth < dtmin) { return(false); } return(true); }
private void DeleteAllDateTSM_Click(object sender, EventArgs e) { if (IsCan == 20) { MessageBox.Show("你暂时未有此项权限", "提示"); return; } if (System.Windows.Forms.MessageBox.Show("你确定要删除所有数据吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { if (System.Windows.Forms.MessageBox.Show("请你再次慎重考虑是否重建家谱!", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { dbConnection db = new dbConnection(); db.CarryOutSqlSentence(" truncate table [Family].[dbo].[tblNumberInfo]"); MessageBox.Show("已经清空!", "提示"); } } }
private void btnAdd_Click(object sender, EventArgs e) { try { if (txtNumNmae.Text == "") { MessageBox.Show("请输入名称", "提示"); return; } if (txtnumjob.Text == "") { MessageBox.Show("请输入职业", "提示"); return; } if (dtpOne.IsNull()) { MessageBox.Show("请输入出生日期", "提示"); return; } DateTime dtlast = new DateTime(); DateTime dt = Convert.ToDateTime(dtpOne.Text); Rule Rle = new Rule(); bool iscan = Rle.CheckHavePeiOu(dt, GetID); if (!iscan) { MessageBox.Show("配偶出生日期不符合配偶规则!(可查看具体规则)", "不符"); return; } string dieday = "NULL"; bool IsHaveDieDay = false; if (txtDieDay.Text != "") { bool isdate = ValueJudge.IsDateTime(txtDieDay.Text); if (!isdate) { MessageBox.Show("日期格式错诶!", "不符"); return; } dtlast = Convert.ToDateTime(txtDieDay.Text); if (dtlast < dt) { MessageBox.Show("请输入正确时间", "提示"); return; } IsHaveDieDay = true; dieday = dtlast.ToString(); } else { } if (txtnumaddress.Text == "") { MessageBox.Show("请输入地址", "提示"); return; } if (txtnumlifestory.Text == "") { MessageBox.Show("请输入生平事迹", "提示"); return; } string state = ""; if (cbxDieNow.SelectedIndex == 1) { state = "40"; } else { state = "30"; } if (IsHaveDieDay && cbxDieNow.SelectedIndex == 0) { MessageBox.Show("此人既有死亡日期!又被标定为健在!逻辑不符合", "错误"); return; } string sql = String.Format("insert into [Family].[dbo].[tblNumberInfo] " + "( [JobID],[NiName],[NiSex],[NiSpouseId] ,[NiBirthDay],[NiDIeDay],[NiFatherId],[NiMotherId],[NiPicture],[NiAddress],[NiLifeStory],[Nistate]) " + "values('{0}','{1}',{2},{3},cast('{4}' as datetime2),{5},{6},{7},NULL,'{8}','{9}',{10})", txtnumjob.Text, txtNumNmae.Text, PeiOuSex, GetID, dtpOne.Text, dieday, -1, -1, txtnumaddress.Text.Replace("\'", "\'\'"), txtnumlifestory.Text.Replace("\'", "\'\'"), state); dbvwNumberInfo vw = new dbvwNumberInfo(); vw.CarryOutSqlSentence(sql); dbConnection db = new dbConnection(); string ID = db.CarryOutSqlGetFirstColmun(String.Format( "select NiId from [Family].[dbo].[tblNumberInfo] where JobID ='{0}' and NiName='{1}' and NiSpouseId={2} and NiFatherId =-1 and NiBirthDay ='{3}'", txtnumjob.Text, txtNumNmae.Text, GetID, dtpOne.Text)); db.CarryOutSqlSentence("update [Family].[dbo].[tblNumberInfo] set NiSpouseId =" + ID + " where NiId= " + GetID); MessageBox.Show("添加成功", "提示"); changeNull(); } catch (Exception exception) { MessageBox.Show(exception.Message + exception.StackTrace); } }
private void getListData(string sql) { dbConnection db = new dbConnection(); dgvList.DataSource = db.CarryOutSqlGeDataTable(sql); }
private void ShowData() { dbConnection con = new dbConnection(); string AllPeople = con.CarryOutSqlGetFirstColmun("select count(*) from [Family].[dbo].[tblNumberInfo]"); double countAllPeople = Convert.ToDouble(AllPeople); RsAllPeopleCount.Height = 200; RsAllPeopleCount.Width = 25; lblAll.Text = "总人数:" + countAllPeople; dbvwNumberInfo num = new dbvwNumberInfo(); DataTable td = num.GetAllDataFrom_vwNumberInfo(); int sexCountGirl = 0; int sexCountBoy = 0; int weichengnian = 0; int lblLifeCount = 0; //当前健在人口 int lblTillNowDieCount = 0; /*目前为止先祖人口*/ int lblNowDanCount = 0; /*当前单身人数*/ int lblJiaZuJiCount = 0; /*未记载*/ int BoyNowStillLfe = 0; int GirlNowLifeStill = 0; int JianZiaWeicheng = 0; for (int i = 0; i < td.Rows.Count; i++) { if (td.Rows[i]["NiSex"].ToString() == "True") { sexCountGirl++; } else { sexCountBoy++; } if (Convert.ToInt32(td.Rows[i]["年龄"]) < 18) { weichengnian++; } /*统计健在人口*/ if (td.Rows[i]["Nistate"].ToString() == "30") { lblLifeCount++; } /*统计死亡人口*/ if (td.Rows[i]["Nistate"].ToString() == "40") { lblTillNowDieCount++; } if (td.Rows[i]["配偶"].ToString() == "未记载" && td.Rows[i]["Nistate"].ToString() == "30") { lblNowDanCount++; } if (td.Rows[i]["NiLifeStory"].ToString() == "" || td.Rows[i]["NiLifeStory"].ToString().Length < 50) { lblJiaZuJiCount++; } if (td.Rows[i]["Nistate"].ToString() == "30" && td.Rows[i]["性别"].ToString() == "男") { BoyNowStillLfe++; } if (td.Rows[i]["Nistate"].ToString() == "30" && td.Rows[i]["性别"].ToString() == "女") { GirlNowLifeStill++; } if (Convert.ToInt32(td.Rows[i]["年龄"]) < 18 && td.Rows[i]["Nistate"].ToString() == "30") { JianZiaWeicheng++; } } lblLifeCountNow.Text = lblLifeCount.ToString(); /*显示健在总人口*/ lblTillNowDieCountNow.Text = lblTillNowDieCount.ToString(); //显示死亡人口 lblNowDanCountNow.Text = lblNowDanCount.ToString(); /*单身人数*/ lblJiZaiWithOut.Text = lblJiaZuJiCount.ToString(); /*记载*/ lblLifeGrilNow.Text = GirlNowLifeStill.ToString(); lblLifeBoyNow.Text = BoyNowStillLfe.ToString(); lblWhouChengNian.Text = JianZiaWeicheng.ToString(); lblWEichengnian.Text = "未成年:" + weichengnian; lblGirl.Text = "女生:" + sexCountGirl; lblBoy.Text = "男生:" + sexCountBoy; RSGrilCount.Height = Convert.ToInt32((sexCountGirl / countAllPeople) * 200); RSBoyCount.Height = Convert.ToInt32((sexCountBoy / countAllPeople) * 200); CRWeichengNain.Height = Convert.ToInt32((weichengnian / countAllPeople) * 200); GetDate(); }