private void kryptonDataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            客房出租历史记录 entity = 客房出租历史记录BindingSource.Current as 客房出租历史记录;
            客房       kf     = entity.客房;

            /*只允许删除“历史”客户的记录。因为[续租]后当前租户相关租房信息转到‘客房出租历史记录’表里,那么如果
             * 欲删除的记录是当前客户上次续租的合约记录的话,以后的退租操作无法正常进行(退租时要计算该客户整个
             * 签约期内的款项、押金等等,多退少补)。*/
            //1.


            //删除某条出租历史记录后,相关的【客房收租明细】信息也自动删除。
        }
        private void BtnDel_Click(object sender, EventArgs e)
        {
            客房出租历史记录 entity = 客房出租历史记录BindingSource.Current as 客房出租历史记录;

            if (entity == null)
            {
                return;
            }

            客房 tempKF = entity.客房;

            ////只允许删除“历史”客户的记录。因为[续租]后当前租户相关租房信息转到‘客房出租历史记录’表里,那么如果
            ////欲删除的记录是当前客户上次续租的合约记录的话,以后的退租操作无法正常进行(退租时要计算该客户整个
            ////签约期内的款项、押金等等,多退少补)。*/
            if (tempKF.租户 == entity.租户 && tempKF.身份证号 == entity.身份证号)
            {
                KryptonMessageBox.Show("此条【客房出租历史记录】相关信息涉及到当前租户,无法删除。\r\n(当前租户退租后,才能删除此租户相关的【客房出租历史记录】。)", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else//删除某条出租历史记录后,相关的【客房收租明细】信息也自动删除。
            {
                List <客房租金明细> willBeDeletedList = 客房出租历史记录.GetHistoryRentDetails(entity);
                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);
                    }
                }
            }
        }
Beispiel #3
0
        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.气止码;
            }
        }