Esempio n. 1
0
        void FormLeaseRecord1Load(object sender, EventArgs e)
        {
            //填充租赁项

            ds1 = BLL.LeaseBLL.GetLeaseItemsByHTID(i_HTID);
            comboBoxItemsName.DataSource    = ds1.Tables[0];
            comboBoxItemsName.ValueMember   = "ItemsID";
            comboBoxItemsName.DisplayMember = "MName";
            if (this.Text == "租赁记录-新增")
            {
            }
            else
            {
                LeaseRecord tRI = BLL.LeaseBLL.GetLeaseRecord(i_RID);
                LeaseItems  tI  = BLL.LeaseBLL.GetLeaseItem(tRI.ItemsID);
                comboBoxItemsName.SelectedValue = tI.ItemsID;
                textBoxLeaseUnit.Text           = tI.LeaseUnit;
                dateTimePickerLeaseDate.Value   = tRI.LeaseDate;
                textBoxQuality.Text             = tRI.Quality.ToString();
                textBoxHandler.Text             = tRI.Handler;
                textBoxAbstract.Text            = tRI.Abstract;
            }

            bindingFlag = true;
        }
Esempio n. 2
0
        //获取指定的租赁记录
        public static LeaseRecord GetLeaseRecord(int i_RID)
        {
            ISession    session = NHibernateHelper.OpenSession();
            LeaseRecord tClass  = new LeaseRecord();

            try {
                tClass = session.Get <LeaseRecord>(i_RID);
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
            }
            session.Close();
            return(tClass);
        }
Esempio n. 3
0
        void ModifyLeaseRecord()
        {
            LeaseRecord tLeaseRecord = new LeaseRecord();

            tLeaseRecord = BLL.LeaseBLL.GetLeaseRecord(i_RID);

            tLeaseRecord.ItemsID   = Convert.ToInt32(comboBoxItemsName.SelectedValue);
            tLeaseRecord.LeaseDate = dateTimePickerLeaseDate.Value.Date;
            tLeaseRecord.Quality   = Convert.ToDecimal(textBoxQuality.Text);
            tLeaseRecord.Handler   = textBoxHandler.Text;
            tLeaseRecord.Abstract  = textBoxAbstract.Text;

            BLL.LeaseBLL.ModifyLeaseRecord(tLeaseRecord);
        }
Esempio n. 4
0
        void AddNewLeaseRecord()
        {
            LeaseRecord tLeaseRecord = new LeaseRecord();

            tLeaseRecord.HTID        = i_HTID;
            tLeaseRecord.ItemsID     = Convert.ToInt32(comboBoxItemsName.SelectedValue);
            tLeaseRecord.LeaseDate   = dateTimePickerLeaseDate.Value.Date;
            tLeaseRecord.Quality     = Convert.ToDecimal(textBoxQuality.Text);
            tLeaseRecord.Handler     = textBoxHandler.Text;
            tLeaseRecord.Abstract    = textBoxAbstract.Text;
            tLeaseRecord.LeaseStatus = "未结算";

            BLL.LeaseBLL.AddLeaseRecord(tLeaseRecord);
        }
Esempio n. 5
0
        //添加租赁记录
        public static void AddLeaseRecord(LeaseRecord tLeaseRecord)
        {
            ISession     session = NHibernateHelper.sessionFactory.OpenSession();
            ITransaction tx      = session.BeginTransaction();

            try {
                session.Save(tLeaseRecord);
                tx.Commit();
                session.Close();
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
                tx.Rollback();
                session.Close();
            }
        }
Esempio n. 6
0
        // 修改租赁记录
        public static void ModifyLeaseRecord(LeaseRecord tLeaseRecord)
        {
            ISession session = NHibernateHelper.OpenSession();

            try {
                ITransaction tx = session.BeginTransaction();
                LeaseRecord  t1 = session.Get <LeaseRecord>(tLeaseRecord.RID);
                t1.HTID        = tLeaseRecord.HTID;
                t1.ItemsID     = tLeaseRecord.ItemsID;
                t1.LeaseDate   = tLeaseRecord.LeaseDate;
                t1.BalanceDate = tLeaseRecord.BalanceDate;
                t1.Quality     = tLeaseRecord.Quality;
                t1.Handler     = tLeaseRecord.Handler;
                t1.Abstract    = tLeaseRecord.Abstract;

                tx.Commit();
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
            }
            session.Close();
        }
Esempio n. 7
0
        //删除
        public static void DelLeaseRecord(int i_RID)
        {
            ISession     session  = NHibernateHelper.OpenSession();
            ITransaction tx       = session.BeginTransaction();
            LeaseRecord  toDelete = session.Get <LeaseRecord>(i_RID);

            try {
                if (toDelete.LeaseStatus == "已结算")
                {
                    tx.Rollback();
                    session.Close();
                    MessageBox.Show("已结算,不能删除!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    return;
                }
                session.Delete(toDelete);
                tx.Commit();
                session.Close();
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
                tx.Rollback();
                session.Close();
            }
        }
Esempio n. 8
0
        public Task <IApiResult> CarRequest(Models.Parameter.P_Devices.P_CarRequest arg)
        {
            return(Task.Run(() =>
            {
                IApiResult hr = new IApiResult();
                using (CarRentEntities cre = new CarRentEntities())
                {
                    try
                    {
                        //var deviceQuery = from d in cre.Devices where d.DeviceID == arg.deviceid select new { d.Status,d.DeviceName };
                        //var device = deviceQuery.First();
                        //if (device.Status == 1)
                        //{

                        //}
                        var dev = from d in cre.Devices
                                  join l in cre.LeaseRecord
                                  on d.DeviceID equals l.DeviceID
                                  into lr
                                  from dli in lr.DefaultIfEmpty()
                                  where d.DeviceID == arg.deviceid && d.Deleted == false
                                  orderby dli.Created descending
                                  select new{ dli.Status, devStatus = d.Status, d.UserID, d.DeviceID };
                        var query = dev.FirstOrDefault();
                        //Status (1:已租,0:未租)
                        if (query.Status == 1)
                        {
                            hr.code = StatusCode.failure;
                            hr.message = "Occupied."; //已经被别人申请了
                        }
                        else if (query.Status == 2)
                        {
                            hr.code = StatusCode.failure;
                            hr.message = "Occupied.";//已经租出去了
                        }
                        else
                        {
                            LeaseRecord lr = new LeaseRecord();
                            lr.DeviceID = query.DeviceID;
                            //1 已申请,等待确认,2 正在出租,3出租完成,4已拒绝
                            lr.Status = 1;
                            lr.UserPhone = arg.phone;
                            lr.UserID = query.UserID;
                            lr.Created = DateTime.Now;
                            lr = cre.LeaseRecord.Add(lr);
                            //DAL.Devices device = new DAL.Devices();
                            //device.Status = 1;
                            cre.SaveChanges();
                            hr.message = "success!";
                        }
                    }
                    catch (InvalidOperationException ioe)
                    {
                        hr.message = "未找到元素";
                        hr.code = StatusCode.error;
                        Log.Error(this, ioe);
                    }
                    catch (Exception ex)
                    {
                        hr.message = ex.Message;
                        hr.code = StatusCode.error;
                        Log.Error(this, ex);
                    }
                    return hr;
                }
            }));
        }
Esempio n. 9
0
        //添加租赁结算
        public static void AddNewLeaseJS(int i_ProjectID, int i_CompanyID, string s_BillCycle, DateTime d_SDate, DateTime d_EDate, ToolStripLabel labelStatus)
        {
            labelStatus.Text = "现在开始把数据添加到数据库中...";
            Application.DoEvents();
            string[,] ALeaseAccountLeft = new string[50, 2];                    //用于保存当前剩余租赁材料

            ISession     session = NHibernateHelper.sessionFactory.OpenSession();
            ITransaction tx      = session.BeginTransaction();

            try {
                int i_SNumber = 1;                              //租赁结算顺序号

                //1.先添加租赁结算单,以得到BillID
                labelStatus.Text = "现在开始添加租赁结算单...";
                Application.DoEvents();

                Projects  tProject       = BLL.ProjectsBLL.GetProject(i_ProjectID);
                Companies tCompany       = BLL.CompanyBLL.GetCompany(i_CompanyID);
                LeaseHT   tLeaseHT       = BLL.LeaseBLL.GetLeaseHT(i_ProjectID, i_CompanyID);
                int       i_IncludeSDate = tLeaseHT.IncludeSDate;       //租金包含开始日
                int       i_IncludeEDate = tLeaseHT.IncludeEDate;       //租金包含结束日
                string    s_CalMethod    = "";                          //计算方式
                if (i_IncludeSDate == 0 && i_IncludeEDate == 0)
                {
                    s_CalMethod = "倒扣计算法,头尾都不算";
                }
                if (i_IncludeSDate == 1 && i_IncludeEDate == 0)
                {
                    s_CalMethod = "倒扣计算法,算头不算尾";
                }
                if (i_IncludeSDate == 1 && i_IncludeEDate == 1)
                {
                    s_CalMethod = "倒扣计算法,既算头又算尾";
                }
                if (i_IncludeSDate == 0 && i_IncludeEDate == 1)
                {
                    s_CalMethod = "倒扣计算法,算尾不算头";
                }
                TimeSpan tTS    = d_EDate.Subtract(d_SDate);
                int      i_Days = tTS.Days + 1;                         //结余时租赁天数

                LeaseAccount newLeaseAccount = new LeaseAccount();
                newLeaseAccount.ProjectID    = i_ProjectID;
                newLeaseAccount.CompanyID    = i_CompanyID;
                newLeaseAccount.BillCycle    = s_BillCycle;
                newLeaseAccount.SDate        = d_SDate;
                newLeaseAccount.EDate        = d_EDate;
                newLeaseAccount.CalMethod    = s_CalMethod;
                newLeaseAccount.ProjectName  = tProject.ProjectName;
                newLeaseAccount.CompanyName  = tCompany.CompanyName;
                newLeaseAccount.IncludeSDate = i_IncludeSDate;
                newLeaseAccount.IncludeEDate = i_IncludeEDate;
                session.Save(newLeaseAccount);

                StatementList newStatementList = new StatementList();
                newStatementList.ProjectID      = i_ProjectID;
                newStatementList.ProjectName    = tProject.ProjectName;
                newStatementList.CompanyID      = i_CompanyID;
                newStatementList.CompanyName    = tCompany.CompanyName;
                newStatementList.MoneyTypeID    = 10000;
                newStatementList.MoneyTypeName  = "租赁结算自动生成";
                newStatementList.StatementType  = "租赁结算";
                newStatementList.StatementMemo  = "应付租金";
                newStatementList.StatementCycle = s_BillCycle;
                newStatementList.StatementDate  = DateTime.Now.Date;
                session.Save(newStatementList);

                decimal d_BillAmt = 0.0m;
                //2.添加租赁明细单,并计算金额合计,以便完成后填写到LeaseAccount表记录中
                //把保存剩余租赁量的数组数据填好,全部是字符串
                DataSet dsTmp = BLL.LeaseBLL.GetLeaseAccountLeft(tLeaseHT.HTID);
                foreach (DataRow dr in dsTmp.Tables[0].Rows)
                {
                    string s_0 = dr["ItemsID"].ToString();
                    string s_1 = dr["QualityLeft"].ToString();

                    for (int j = 0; j < ALeaseAccountLeft.GetLength(0); j++)
                    {
                        string s0 = ALeaseAccountLeft[j, 0];
                        string s1 = ALeaseAccountLeft[j, 1];
                        if (ALeaseAccountLeft[j, 0] == null)
                        {
                            ALeaseAccountLeft[j, 0] = s_0;
                            ALeaseAccountLeft[j, 1] = s_1;
                            break;
                        }
                    }
                }
                //2.1添加结余租赁明细项目
                dsTmp = BLL.LeaseBLL.GetLeaseItemsByHTID(tLeaseHT.HTID);
                foreach (DataRow dr in dsTmp.Tables[0].Rows)
                {
                    LeaseAccountList newLeaseAccountList = new LeaseAccountList();
                    int              i_ItemsID           = Convert.ToInt32(dr["ItemsID"]);
                    LeaseItems       tLeaseItem          = BLL.LeaseBLL.GetLeaseItem(i_ItemsID);
                    LeaseAccountLeft tLeaseAccountLeft   = BLL.LeaseBLL.GetLeaseAccountLeft(tLeaseHT.HTID, i_ItemsID);
                    if (tLeaseAccountLeft == null)
                    {
                        continue;
                    }
                    newLeaseAccountList.SNumber      = i_SNumber;
                    newLeaseAccountList.BillID       = newLeaseAccount.BillID;
                    newLeaseAccountList.ItemsID      = tLeaseItem.ItemsID;
                    newLeaseAccountList.ItemsName    = tLeaseItem.MName;
                    newLeaseAccountList.LeaseClass   = 3;                   //将结余类重设
                    newLeaseAccountList.Abstract     = tLeaseItem.MName + " 上期结余";
                    newLeaseAccountList.SDate        = d_SDate;
                    newLeaseAccountList.EDate        = d_EDate;
                    newLeaseAccountList.LeaseUnit    = tLeaseItem.LeaseUnit;
                    newLeaseAccountList.LeaseQuality = tLeaseAccountLeft.QualityLeft;
                    newLeaseAccountList.LeasePrice   = tLeaseItem.LeasePrice;
                    newLeaseAccountList.LeaseDays    = i_Days;
                    newLeaseAccountList.LeaseAmt     = newLeaseAccountList.LeaseQuality * newLeaseAccountList.LeasePrice * i_Days;

                    d_BillAmt += newLeaseAccountList.LeaseAmt;

                    session.Save(newLeaseAccountList);

                    i_SNumber++;
                }
                //2.2按照未结算租赁记录添加租赁结算明细项
                dsTmp = BLL.LeaseBLL.GetLeaseRecord2(i_ProjectID, i_CompanyID);                 //未结算的记录
                foreach (DataRow dr in dsTmp.Tables[0].Rows)
                {
                    //检查租赁日期是否在结算日期范围
                    int         i_RID        = Convert.ToInt32(dr["RID"]);
                    LeaseRecord tLeaseRecord = session.Get <LeaseRecord>(i_RID);

                    if (tLeaseRecord.LeaseDate >= d_SDate && tLeaseRecord.LeaseDate <= d_EDate)
                    {
                        LeaseAccountList newLeaseAccountList = new LeaseAccountList();
                        int        i_ItemsID  = tLeaseRecord.ItemsID;
                        LeaseItems tLeaseItem = session.Get <LeaseItems>(i_ItemsID);


                        newLeaseAccountList.SNumber    = i_SNumber;
                        newLeaseAccountList.BillID     = newLeaseAccount.BillID;
                        newLeaseAccountList.ItemsID    = tLeaseItem.ItemsID;
                        newLeaseAccountList.ItemsName  = tLeaseItem.MName;
                        newLeaseAccountList.LeaseClass = tLeaseItem.LeaseClass;
                        if (tLeaseRecord.Abstract.ToString().Length != 0)
                        {
                            newLeaseAccountList.Abstract = tLeaseItem.MName + "(" + tLeaseRecord.Abstract + ")";
                        }
                        else
                        {
                            newLeaseAccountList.Abstract = tLeaseItem.MName;
                        }
                        DateTime dt1 = tLeaseRecord.LeaseDate;
                        newLeaseAccountList.SDate = dt1;
                        newLeaseAccountList.EDate = d_EDate;
                        TimeSpan tTS1  = d_EDate.Subtract(dt1);
                        int      tDays = tTS1.Days;
                        if (tLeaseRecord.Quality > 0)
                        {
                            if (i_IncludeSDate == 1)
                            {
                                tDays++;
                            }
                        }
                        else
                        {
                            if (i_IncludeEDate != 1)
                            {
                                tDays++;
                            }
                        }
                        if (tLeaseItem.LeaseClass == 0)
                        {
                            //租赁项
                            newLeaseAccountList.LeaseUnit    = tLeaseItem.LeaseUnit;
                            newLeaseAccountList.LeaseQuality = tLeaseRecord.Quality;
                            newLeaseAccountList.LeasePrice   = tLeaseItem.LeasePrice;
                            newLeaseAccountList.LeaseDays    = tDays;
                            newLeaseAccountList.LeaseAmt     = newLeaseAccountList.LeaseQuality * newLeaseAccountList.LeasePrice * tDays;

                            d_BillAmt += newLeaseAccountList.LeaseAmt;

                            newLeaseAccountList.LoadingUnit    = tLeaseItem.LoadingUnit;
                            newLeaseAccountList.LoadingFactor  = Convert.ToDecimal(tLeaseItem.LoadingFactor);
                            newLeaseAccountList.LoadingQuality = Math.Abs(newLeaseAccountList.LeaseQuality / newLeaseAccountList.LoadingFactor);
                            newLeaseAccountList.LoadingPrice   = Convert.ToDecimal(tLeaseItem.LoadingPrice);
                            newLeaseAccountList.LoadingAmt     = Math.Abs(newLeaseAccountList.LoadingPrice * newLeaseAccountList.LoadingQuality);

                            d_BillAmt += newLeaseAccountList.LoadingAmt;

                            if (tLeaseRecord.Quality < 0)
                            {
                                newLeaseAccountList.RepairUnit    = tLeaseItem.RepairUnit;
                                newLeaseAccountList.RepairFactor  = Convert.ToDecimal(tLeaseItem.RepairFactor);
                                newLeaseAccountList.RepairQuality = Math.Abs(newLeaseAccountList.LeaseQuality / newLeaseAccountList.RepairFactor);
                                newLeaseAccountList.RepairPrice   = Convert.ToDecimal(tLeaseItem.RepairPrice);
                                newLeaseAccountList.RepairAmt     = Math.Abs(newLeaseAccountList.RepairPrice * newLeaseAccountList.RepairQuality);
                                d_BillAmt += newLeaseAccountList.RepairAmt;
                            }

                            //检查此租赁项是否存在,存在则更新LeaseAccountLeft,否则添加
                            string s_0 = tLeaseItem.ItemsID.ToString();
                            string s_1 = newLeaseAccountList.LeaseQuality.ToString();
                            for (int j = 0; j < ALeaseAccountLeft.GetLength(0); j++)
                            {
                                if (ALeaseAccountLeft[j, 0] == null)
                                {
                                    ALeaseAccountLeft[j, 0] = s_0;
                                    ALeaseAccountLeft[j, 1] = s_1;
                                    break;
                                }
                                else
                                {
                                    if (ALeaseAccountLeft[j, 0] == s_0)
                                    {
                                        //找到了
                                        decimal d1 = Convert.ToDecimal(s_1) + Convert.ToDecimal(ALeaseAccountLeft[j, 1]);
                                        ALeaseAccountLeft[j, 1] = d1.ToString();
                                        break;
                                    }
                                    //继续找
                                }
                            }
                        }
                        else
                        {
                            //单独结算项
                            newLeaseAccountList.LeaseUnit    = tLeaseItem.LeaseUnit;
                            newLeaseAccountList.OtherUnit    = tLeaseItem.LeaseUnit;
                            newLeaseAccountList.OtherQuality = tLeaseRecord.Quality;
                            newLeaseAccountList.OtherPrice   = tLeaseItem.LeasePrice;
                            newLeaseAccountList.OtherAmt     = newLeaseAccountList.OtherPrice * newLeaseAccountList.OtherQuality;
                            d_BillAmt += newLeaseAccountList.OtherAmt;
                        }

                        tLeaseRecord.LeaseStatus = "已结算";
                        tLeaseRecord.BalanceDate = DateTime.Now.Date;
                        session.Update(tLeaseRecord);
                        session.Save(newLeaseAccountList);


                        i_SNumber++;
                    }
                }

                newLeaseAccount.BillAmt = Convert.ToDecimal(d_BillAmt);
                newStatementList.BillYF = Convert.ToDecimal(d_BillAmt);
                //把LeaseAccountLeft更新
                for (int j = 0; j < ALeaseAccountLeft.GetLength(0); j++)
                {
                    if (ALeaseAccountLeft[j, 0] != null)
                    {
                        int iItem = Convert.ToInt32(ALeaseAccountLeft[j, 0]);
                        LeaseAccountLeft tLeaseAccountLeft = BLL.LeaseBLL.GetLeaseAccountLeft(tLeaseHT.HTID, iItem);
                        if (tLeaseAccountLeft == null)
                        {
                            tLeaseAccountLeft               = new LeaseAccountLeft();
                            tLeaseAccountLeft.HTID          = tLeaseHT.HTID;
                            tLeaseAccountLeft.ItemsID       = iItem;
                            tLeaseAccountLeft.QualityLeft   = Convert.ToDecimal(ALeaseAccountLeft[j, 1]);
                            tLeaseAccountLeft.LastBillCycle = newLeaseAccount.BillCycle;
                            tLeaseAccountLeft.LastEDate     = DateTime.Now.Date;
                            session.Save(tLeaseAccountLeft);
                        }
                        else
                        {
                            tLeaseAccountLeft.QualityLeft   = Convert.ToDecimal(ALeaseAccountLeft[j, 1]);
                            tLeaseAccountLeft.LastBillCycle = newLeaseAccount.BillCycle;
                            tLeaseAccountLeft.LastEDate     = DateTime.Now.Date;
                            session.Update(tLeaseAccountLeft);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                tx.Commit();
                session.Close();
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
                tx.Rollback();
                session.Close();
            }
            labelStatus.Text = "就绪";
        }