private void BtnDel_Click(object sender, EventArgs e) { //只允许删除---只能针对当前租户,删除某条记录,则该记录起的后续记录都将被删除! 客房租金明细 current = 客房租金明细BindingSource.Current as 客房租金明细; if (current == null) { return; } List <客房租金明细> currentList = 客房租金明细.GetRentDetails_Current2(current.客房); if (!currentList.Contains(current)) { string msg; if (string.IsNullOrEmpty(current.客房.租户)) { msg = "此条【收租明细信息】属于历史租户历史协议期内信息,无法删除!(详见上方操作说明)"; } else { msg = string.Format("此条【收租明细信息】非‘当前租户[{0}]、当前协议期内[{1}]’的记录,无法删除!", current.客房.租户, current.客房.期始.Value.ToShortDateString() + "~" + current.客房.期止.Value.ToShortDateString()); } KryptonMessageBox.Show(msg); return; } else { willBeDeletedList = currentList.Where(m => m.起付日期 > current.起付日期); int num = willBeDeletedList.Count(); string msg = string.Format("删除此条记录,该记录的后续收租明细信息[{0}条]都将被删除!\r\n(详见上方操作说明)\r\n是否删除?", num); if (KryptonMessageBox.Show(msg, "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { //删除当前选中 客房租金明细BindingSource.RemoveCurrent(); //删除涉及到的 foreach (var o in willBeDeletedList) { context.客房租金明细.DeleteObject(o); } willBeDeletedList = null;//删除后置空 CaculateSumMoney(); } } }
private void kryptonDataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { //只允许删除---只能针对当前租户,删除某条记录,则该记录起的后续记录都将被删除! 客房租金明细 entity = 客房租金明细BindingSource.Current as 客房租金明细; List <客房租金明细> currentList = 客房租金明细.GetRentDetails_Current2(entity.客房); if (!currentList.Contains(entity)) { string msg; if (string.IsNullOrEmpty(entity.客房.租户)) { msg = "此条【收租明细信息】属于历史租户历史协议期内信息,无法删除!(详见上方操作说明)"; } else { msg = string.Format("此条【收租明细信息】非‘当前租户[{0}]、当前协议期内[{1}]’的记录,无法删除!", entity.客房.租户, entity.客房.期始.Value.ToShortDateString() + "~" + entity.客房.期止.Value.ToShortDateString()); } KryptonMessageBox.Show(msg); e.Cancel = true; } else { willBeDeletedList = currentList.Where(m => m.起付日期 > entity.起付日期); int num = willBeDeletedList.Count(); string msg = string.Format("删除此条记录,该记录的后续记录[{0}条]都将被删除!(详见上方操作说明)\r\n是否删除?", num); if (KryptonMessageBox.Show(msg, "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { //删除后续记录不能写在这里,会又一次引发UserDeletingRow事件,将其放在UserDeletedRow中处理。 //foreach (var o in laterList) //{ // //Main.context.客房租金明细.DeleteObject(o); //} } else { e.Cancel = true; } } }
private void BindingData() { //进入此界面,理论上客房应该出租了,有租户信息 #if DEBUG System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(kf.租户)); #endif //针对当前租户的所有协议历史缴费(包括之前续租的) List <客房租金明细> orderedList = 客房租金明细.GetRentDetails_Current(kf); 参考历史BindingSource.DataSource = orderedList; //新对象,根据情况赋予初始值 collectRent = new 客房租金明细(); collectRent.付款人 = kf.租户; collectRent.客房ID = kf.ID; //新对象的‘起付时间’与之前的‘止付时间’连续 if (orderedList.Count == 0)//该租户第一次交租 { isFirstTime = true; collectRent.起付日期 = kf.期始.Value.Date; collectRent.水止码 = kf.水始码;//止码设置为始码值,相当于没有用 collectRent.电止码 = kf.电始码; collectRent.气止码 = kf.气始码; nud水费.Enabled = false;//首次收租,不需要调整水电气 nud电费.Enabled = false; nud气费.Enabled = false; toolTip1.SetToolTip(tableLayoutPanel1, "首次收租不涉及水电气费用,如需调整始码,请进行[客房编辑]操作。"); } else { isFirstTime = false; collectRent.起付日期 = kf.客房租金明细.Max(m => m.止付日期).AddDays(1).Date; collectRent.水止码 = kf.客房租金明细.Max(m => m.水止码);//止码设置为始码值,相当于没有用(用户会自行修改) collectRent.电止码 = kf.客房租金明细.Max(m => m.电止码); collectRent.气止码 = kf.客房租金明细.Max(m => m.气止码); 押金Label1.ForeColor = Color.Gray; //非首次收租,押金置灰。 toolTip1.SetToolTip(押金Label1, "非首次收租不涉及押金。"); //非初次交租,计算该租户历史余款 foreach (var rent in orderedList) { balancePayment += rent.实付金额 - rent.应付金额; } } collectRent.止付日期 = collectRent.起付日期.AddMonths(kf.支付月数).AddDays(-1); //当协议的期止并非刚好间隔支付月数时,协议期内最后一次收租的止付日期需要调整,再计算租金 realMonthNum = kf.支付月数; if (collectRent.止付日期 > kf.期止.Value.Date) { while (collectRent.止付日期 > kf.期止.Value.Date) { realMonthNum--; collectRent.止付日期 = collectRent.止付日期.AddMonths(-1); } if (collectRent.止付日期 < kf.期止.Value.Date) { //剩余天数不足一个月的,按1个月收租。 realMonthNum++; collectRent.止付日期 = kf.期止.Value.Date; 止付日期Label1.ForeColor = Color.Red; toolTip1.SetToolTip(止付日期Label1, "尾期天数不足1个月,按1个月计算。实收租金可与租户协商而定。"); } } //---------- nud水费.Minimum = (decimal)collectRent.水止码; nud电费.Minimum = (decimal)collectRent.电止码; nud气费.Minimum = (decimal)collectRent.气止码; 水始码Label1.Text = collectRent.水止码.ToString(); 电始码Label1.Text = collectRent.电止码.ToString(); 气始码Label1.Text = collectRent.气止码.ToString(); 月租金Label1.Text = (kf.月租金 * realMonthNum).ToString("F2"); 月宽带费Label1.Text = (kf.月宽带费 * realMonthNum).ToString("F2"); 月物业费Label1.Text = (kf.月物业费 * realMonthNum).ToString("F2"); 月厨房费Label1.Text = (kf.月厨房费 * realMonthNum).ToString("F2"); 押金Label1.Text = kf.押金.ToString("F2"); lblBalance.Text = balancePayment.ToString("F2"); lblBalance.ForeColor = balancePayment >= 0 ? Color.Green : Color.Red;//历史欠款的话,红色 CaculateSum(); Main.context.客房租金明细.AddObject(collectRent);//此操作后可实现外键同步 客房租金明细BindingSource.DataSource = collectRent; }
private void BindingData() { if (collectRent != null) { context.客房租金明细.DeleteObject(collectRent);//删除前次新增的对象 } kryptonHeader1.Values.Heading = kf.源房.房名; kryptonHeader1.Values.Description = kf.命名; 租户Label1.Text = kf.租户; //进入此界面,理论上客房应该出租了,有租户信息 #if DEBUG System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(kf.租户)); #endif //针对当前租户的所有协议历史缴费(包括之前续租的) List <客房租金明细> orderedList = 客房租金明细.GetRentDetails_Current(kf); 参考历史BindingSource.DataSource = orderedList; //新对象,根据情况赋予初始值 collectRent = new 客房租金明细(); collectRent.付款人 = kf.租户; collectRent.客房ID = kf.ID; //新对象的‘起付时间’与之前的‘止付时间’连续 if (orderedList.Count == 0)//该租户第一次交租 { isFirstTime = true; collectRent.起付日期 = kf.期始.Value.Date; collectRent.水止码 = kf.水始码;//止码设置为始码值,相当于没有用 collectRent.电止码 = kf.电始码; collectRent.气止码 = kf.气始码; nud水费.Enabled = false;//首次收租,不需要调整水电气 nud电费.Enabled = false; nud气费.Enabled = false; toolTip1.SetToolTip(tableLayoutPanel1, "首次收租不涉及水电气费用,如需调整始码,请进行[客房编辑]操作。"); } else { 客房租金明细 lastCollectRent = orderedList[0];//最近交租明细记录 isFirstTime = false; collectRent.起付日期 = lastCollectRent.止付日期.AddDays(1).Date; collectRent.水止码 = lastCollectRent.水止码;//止码设置为始码值,相当于没有用(用户会自行修改) collectRent.电止码 = lastCollectRent.电止码; collectRent.气止码 = lastCollectRent.气止码; 押金Label1.ForeColor = Color.Gray; //非首次收租,押金置灰。 toolTip1.SetToolTip(押金Label1, "非首次收租不涉及押金。"); //非初次交租,计算该租户历史余款 foreach (var rent in orderedList) { balancePayment += rent.实付金额 - rent.应付金额; } } collectRent.止付日期 = collectRent.起付日期.AddMonths(kf.支付月数).AddDays(-1); //当协议的期止并非刚好间隔支付月数时,协议期内最后一次收租的止付日期需要调整,再计算租金 realMonthNum = kf.支付月数; if (collectRent.止付日期 > kf.期止.Value.Date) { collectRent.止付日期 = kf.期止.Value.Date;//赋值,后续将进入‘计算月数’函数 //计算支付月数 if (collectRent.起付日期 > kf.期止.Value.Date) { realMonthNum = 0; } else { CaculateMonth(); } } //---------- nud水费.Minimum = (decimal)collectRent.水止码; nud电费.Minimum = (decimal)collectRent.电止码; nud气费.Minimum = (decimal)collectRent.气止码; 水始码Label1.Text = collectRent.水止码.ToString(); 电始码Label1.Text = collectRent.电止码.ToString(); 气始码Label1.Text = collectRent.气止码.ToString(); 月租金Label1.Text = (kf.月租金 * realMonthNum).ToString("F2"); 月宽带费Label1.Text = (kf.月宽带费 * realMonthNum).ToString("F2"); 月物业费Label1.Text = (kf.月物业费 * realMonthNum).ToString("F2"); 月厨房费Label1.Text = (kf.月厨房费 * realMonthNum).ToString("F2"); 押金Label1.Text = kf.押金.ToString("F2"); lblBalance.Text = balancePayment.ToString("F2"); lblBalance.ForeColor = balancePayment >= 0 ? Color.Green : Color.Red;//历史欠款的话,红色 CaculateSum(); context.客房租金明细.AddObject(collectRent);//此操作后可实现外键同步 客房租金明细BindingSource.DataSource = collectRent; }
private void BindingData() { //拷贝数据到新的【客房出租历史记录】对象 history = new 客房出租历史记录();//构造一个新的【客房出租历史记录】对象 history.备注 = kf.备注; history.操作日期 = DateTime.Now; history.电话1 = kf.电话1; history.电话2 = kf.电话2; history.电始码 = kf.电始码; history.客房ID = kf.ID; //此时因为还未加入context中,所以不会同步客房引用。 history.联系地址 = kf.联系地址; history.期始 = kf.期始.Value; history.期止 = kf.期止.Value; history.气始码 = kf.气始码; history.身份证号 = kf.身份证号; history.水始码 = kf.水始码; history.押金 = kf.押金; history.月厨房费 = kf.月厨房费; history.月宽带费 = kf.月宽带费; history.月物业费 = kf.月物业费; history.月租金 = kf.月租金; history.支付月数 = kf.支付月数; history.中介费用 = kf.中介费用; history.租户 = kf.租户; history.租赁协议照片1 = kf.租赁协议照片1; history.租赁协议照片2 = kf.租赁协议照片2; history.租赁协议照片3 = kf.租赁协议照片3; if (collectRent != null) { context.客房租金明细.DeleteObject(collectRent); //删除前次新增的对象 } btnOK.Enabled = true; //这里先置true,后续判断该租户没有交租记录会置false的。 kryptonHeader1.Values.Heading = kf.源房.房名; kryptonHeader1.Values.Description = kf.命名; 租户Label1.Text = kf.租户; 协议期label1.Text = kf.期始.Value.ToShortDateString(); 协议期label2.Text = kf.期止.Value.ToShortDateString(); //进入此界面,理论上客房应该出租了,有租户信息 #if DEBUG System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(kf.租户)); #endif //针对当前租户的所有协议历史缴费(包括之前续租的) List <客房租金明细> orderedList = 客房租金明细.GetRentDetails_Current(kf); 参考历史BindingSource.DataSource = orderedList; if (orderedList.Count == 0)//该租户第一次交租 { var result = KryptonMessageBox.Show("该租户没有交租记录,是否直接清除租户信息?\r\n(客房将转为【未出租】状态)", "清除租户信息", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == System.Windows.Forms.DialogResult.Yes) { kf.移除租户信息(); string msg; if (Helper.saveData(context, kf, out msg)) { KryptonMessageBox.Show(msg, "成功清除租户信息"); if (this.Owner is Main) { (this.Owner as Main).RefreshAndLocateTree(kf);//刷新TreeView,并定位到kf节点。 } Close(); } else { KryptonMessageBox.Show(msg, "失败"); } } else { btnOK.Enabled = false;//保存按钮不可用,用户可以在此界面更改欲操作客房。 } return; } else//非第一次交租情况下的退租:(有可能结算日期小于上次交租的期止时间,这时需要计算的是‘退款’) { bool IsDrawback = false;//是否为‘退款’ myRtf = new MyRtf(); //初始化 客房租金明细 lastCollectRent = orderedList[0]; //最近交租明细记录 //新对象,根据情况赋予初始值 collectRent = new 客房租金明细(); collectRent.付款人 = kf.租户; collectRent.客房ID = kf.ID; //新对象的‘起付时间’与之前的‘止付时间’连续 collectRent.起付日期 = lastCollectRent.止付日期.AddDays(1).Date; collectRent.止付日期 = dtpDateEnd.Value.Date; collectRent.水止码 = lastCollectRent.水止码;//止码设置为始码值,相当于没有用(用户会自行修改) collectRent.电止码 = lastCollectRent.电止码; collectRent.气止码 = lastCollectRent.气止码; #if DEBUG System.Diagnostics.Debug.Assert(lastCollectRent.止付日期.Date <= kf.期止.Value.Date); #endif if (dtpDateEnd.Value.Date == kf.期止.Value.Date) { myRtf.结算日期VS协议期止日期 = "等于"; myRtf.退租类型 = "正常退租"; history.状态 = "正常退租"; //正常退租状态下,转入历史记录的 if (lastCollectRent.止付日期.Date == kf.期止.Value.Date) //协议租金已全部收讫 { collectRent.起付日期 = dtpDateEnd.Value.Date; //这种情况,接下来只计算水电气费用 } } else if (dtpDateEnd.Value.Date > kf.期止.Value.Date) { myRtf.结算日期VS协议期止日期 = "大于"; myRtf.退租类型 = "逾期退租"; history.状态 = "逾期退租"; //逾期退租状态下,转入历史记录的 } else { myRtf.结算日期VS协议期止日期 = "小于"; myRtf.退租类型 = "提前退租"; history.状态 = "提前退租"; //提前退租状态下,转入历史记录的 if (dtpDateEnd.Value.Date < lastCollectRent.止付日期.Date) //需退款 { IsDrawback = true; //临时对起止日期赋值,退款操作统一计算这段时间应退款。 collectRent.起付日期 = dtpDateEnd.Value.Date.AddDays(1); collectRent.止付日期 = lastCollectRent.止付日期.Date; } } //计算支付月数 if (dtpDateEnd.Value.Date == lastCollectRent.止付日期.Date) { realMonthNum = 0; } else { CaculateMonth(IsDrawback); } myRtf.退租支付期Begin = collectRent.起付日期.ToShortDateString(); myRtf.退租支付期End = collectRent.止付日期.ToShortDateString(); //更新RichTextBox内容,并调整高度 int cutHeight; richTbox.Rtf = myRtf.getRTF(out cutHeight); richTbox.Height = 89 - cutHeight; //89为原始高度 this.Height = 610 - cutHeight; //610为原始高度 //计算该租户历史余款 foreach (var rent in orderedList) { balancePayment += rent.实付金额 - rent.应付金额; } 水始码Label1.Text = collectRent.水止码.ToString(); 电始码Label1.Text = collectRent.电止码.ToString(); 气始码Label1.Text = collectRent.气止码.ToString(); 月租金Label1.Text = (kf.月租金 * realMonthNum).ToString("F2"); 月宽带费Label1.Text = (kf.月宽带费 * realMonthNum).ToString("F2"); 月物业费Label1.Text = (kf.月物业费 * realMonthNum).ToString("F2"); 月厨房费Label1.Text = (kf.月厨房费 * realMonthNum).ToString("F2"); 押金Label1.Text = kf.押金.ToString("F2"); lblBalance.Text = balancePayment.ToString("F2"); lblBalance.ForeColor = balancePayment >= 0 ? Color.Green : Color.Red;//历史欠款的话,红色 CaculateSum(); context.客房租金明细.AddObject(collectRent);//此操作后可实现外键同步 客房租金明细BindingSource.DataSource = collectRent; //---------- nud水费.Minimum = (decimal)collectRent.水止码; nud电费.Minimum = (decimal)collectRent.电止码; nud气费.Minimum = (decimal)collectRent.气止码; } }