Exemplo n.º 1
0
        void ModifyHT()
        {
            LeaseHT tLeaseHT = new LeaseHT();

            tLeaseHT.HTID      = Convert.ToInt32(textBoxHID.Text);
            tLeaseHT.HTNumber  = textBoxHTNumber.Text;
            tLeaseHT.HTName    = textBoxHTName.Text;
            tLeaseHT.ProjectID = i_ProjectID;
            tLeaseHT.CompanyID = Convert.ToInt32(comboBoxCompany.SelectedValue);
            if (checkBoxIncludeSDate.Checked)
            {
                tLeaseHT.IncludeSDate = 1;
            }
            else
            {
                tLeaseHT.IncludeSDate = 0;
            }
            if (checkBoxIncludeEDate.Checked)
            {
                tLeaseHT.IncludeEDate = 1;
            }
            else
            {
                tLeaseHT.IncludeEDate = 0;
            }
            BLL.LeaseBLL.ModifyLeaseHT(tLeaseHT);
        }
Exemplo n.º 2
0
        void FormLeaseHTLoad(object sender, EventArgs e)
        {
            //项目名称
            textBoxProjectName.Text = s_ProjectName;

            //得到项目单位
            ds1 = BLL.CompanyBLL.GetProjectCompanies(i_ProjectID, 3);
            comboBoxCompany.DataSource    = ds1.Tables[0];
            comboBoxCompany.DisplayMember = "CompanyName";
            comboBoxCompany.ValueMember   = "CompanyID";
            if (this.Text == "租赁合同-修改")
            {
                textBoxHID.Text = i_HTID.ToString();
                LeaseHT tLeaseHT = BLL.LeaseBLL.GetLeaseHT(i_HTID);
                textBoxHTNumber.Text          = tLeaseHT.HTNumber;
                textBoxHTName.Text            = tLeaseHT.HTName;
                comboBoxCompany.SelectedValue = tLeaseHT.CompanyID;
                if (tLeaseHT.IncludeSDate == 1)
                {
                    checkBoxIncludeSDate.Checked = true;
                }
                else
                {
                    checkBoxIncludeSDate.Checked = false;
                }
                if (tLeaseHT.IncludeEDate == 1)
                {
                    checkBoxIncludeEDate.Checked = true;
                }
                else
                {
                    checkBoxIncludeEDate.Checked = false;
                }
            }
        }
Exemplo n.º 3
0
        //删除租赁合同
        public static void DelLeaseHT(int iHTID)
        {
            //ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
            ISession     session  = NHibernateHelper.OpenSession();
            ITransaction tx       = session.BeginTransaction();
            LeaseHT      toDelete = session.Get <LeaseHT>(iHTID);
            //判断是否有租赁项信息,如果有,不允许删除!!!
            int i_rtn = 0;

            //查询租赁项信息表中是否存在
            i_rtn = Convert.ToInt32(SQLiteHelper.ExecuteScalar("SELECT Count(*) FROM LeaseItems WHERE HTID = @HTID", iHTID));
            if (i_rtn > 0)
            {
                MessageBox.Show("要删除的租赁合同在租赁项表中有使用,不能删除!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                session.Close();
                return;
            }

            try {
                session.Delete(toDelete);
                tx.Commit();
                session.Close();
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
                tx.Rollback();
                session.Close();
            }
        }
Exemplo n.º 4
0
        //获取指定HTID的LeaseHT
        public static LeaseHT GetLeaseHT(int i_HTID)
        {
            ISession session = NHibernateHelper.OpenSession();
            LeaseHT  tClass  = new LeaseHT();

            try {
                tClass = session.Get <LeaseHT>(i_HTID);
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
            }
            session.Close();
            return(tClass);
        }
Exemplo n.º 5
0
        //获取指定ProjectID和CompanyID的LeaseHT
        public static LeaseHT GetLeaseHT(int i_ProjectID, int i_CompanyID)
        {
            int      i_HTID  = Convert.ToInt32(SQLiteHelper.ExecuteScalar("SELECT HTID FROM LeaseHT WHERE ProjectID = @ProjectID AND CompanyID=@CompanyID", i_ProjectID, i_CompanyID));
            ISession session = NHibernateHelper.OpenSession();
            LeaseHT  tClass  = new LeaseHT();

            try {
                tClass = session.Get <LeaseHT>(i_HTID);
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
            }
            session.Close();
            return(tClass);
        }
Exemplo n.º 6
0
        void ButtonPrintClick(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                return;
            }



            DataSet   tmpDs    = new DataSet();
            DataSet   FDataSet = new DataSet();
            DataTable table    = new DataTable();


            int     i_CompanyID      = Convert.ToInt32(comboBoxProjectCompany.SelectedValue);
            int     i_ProjectID      = Convert.ToInt32(comboBoxProject.SelectedValue);
            string  s_StatementCycle = dataGridView1.CurrentRow.Cells["StatementCycle"].Value.ToString();;
            LeaseHT tLeaseHT         = BLL.LeaseBLL.GetLeaseHT(i_ProjectID, i_CompanyID);

            tmpDs           = BLL.LeaseBLL.GetLeaseAccountDs(i_ProjectID, i_CompanyID, s_StatementCycle);
            table           = tmpDs.Tables[0].Copy();
            table.TableName = "LeaseAccount";
            FDataSet.Tables.Add(table);

            int i_BillID = 0;

            foreach (DataRow drtmp in table.Rows)
            {
                i_BillID = Convert.ToInt32(drtmp["BillID"]);
            }

            tmpDs           = BLL.LeaseBLL.GetLeaseAccountList(i_BillID);
            table           = tmpDs.Tables[0].Copy();
            table.TableName = "LeaseAccountList";
            FDataSet.Tables.Add(table);

            tmpDs           = BLL.LeaseBLL.GetLeaseAccountList(0, i_BillID);
            table           = tmpDs.Tables[0].Copy();
            table.TableName = "LeaseAccountLeft";
            FDataSet.Tables.Add(table);
            //将需要结算的数据填写到报表中的表中

            FastReport.Report report1 = new FastReport.Report();
            report1.Load("Reports\\LeaseHisJS.frx");
            report1.RegisterData(FDataSet);
            report1.Show();
            report1.Dispose();
        }
Exemplo n.º 7
0
        //添加租赁合同
        public static void AddLeaseHT(LeaseHT tLeaseHT)
        {
            //ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
            ISession     session = NHibernateHelper.sessionFactory.OpenSession();
            ITransaction tx      = session.BeginTransaction();

            try {
                session.Save(tLeaseHT);
                tx.Commit();
                session.Close();
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
                tx.Rollback();
                session.Close();
            }
        }
Exemplo n.º 8
0
        // 修改租赁合同
        public static void ModifyLeaseHT(LeaseHT tLeaseHT)
        {
            ISession session = NHibernateHelper.OpenSession();

            try {
                ITransaction tx = session.BeginTransaction();
                LeaseHT      t1 = session.Get <LeaseHT>(tLeaseHT.HTID);
                t1.HTNumber     = tLeaseHT.HTNumber;
                t1.HTName       = tLeaseHT.HTNumber;
                t1.ProjectID    = tLeaseHT.ProjectID;
                t1.CompanyID    = tLeaseHT.CompanyID;
                t1.IncludeSDate = tLeaseHT.IncludeSDate;
                t1.IncludeEDate = tLeaseHT.IncludeEDate;
                tx.Commit();
            } catch (Exception e) {
                Debug.Assert(false, e.Message);
            }
            session.Close();
        }
Exemplo n.º 9
0
        void 修改租赁记录ToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                FormLeaseRecord1 tF = new FormLeaseRecord1();
                tF.Text = "租赁记录-修改";

                int i_ProjectID;
                int i_CompanyID;
//				int i_RID;
                i_ProjectID = Convert.ToInt32(comboBoxProject.SelectedValue.ToString());
                i_CompanyID = Convert.ToInt32(comboBoxCompany.SelectedValue.ToString());
                LeaseHT tLeaseHT = BLL.LeaseBLL.GetLeaseHT(i_ProjectID, i_CompanyID);
                tF.i_HTID = tLeaseHT.HTID;
                tF.i_RID  = Convert.ToInt32(dataGridView1.CurrentRow.Cells["RID"].Value);
                tF.ShowDialog();
                //刷新
                RefreshLeaseRecord();
            }
        }
Exemplo n.º 10
0
        void ButtonJSPreviewClick(object sender, EventArgs e)
        {
            if (CheckFillOK())
            {
                DataSet   tmpDs    = new DataSet();
                DataSet   FDataSet = new DataSet();
                DataTable table    = new DataTable();


                int i_ProjectID;
                int i_CompanyID;
                i_ProjectID = Convert.ToInt32(comboBoxProject.SelectedValue.ToString());
                i_CompanyID = Convert.ToInt32(comboBoxCompany.SelectedValue.ToString());
                LeaseHT tLeaseHT = BLL.LeaseBLL.GetLeaseHT(i_ProjectID, i_CompanyID);

                tmpDs           = BLL.LeaseBLL.GetLeaseAccountDs(0);            //随便取数据,用空结构填充
                table           = tmpDs.Tables[0].Clone();
                table.TableName = "LeaseAccount";
                FDataSet.Tables.Add(table);

                tmpDs           = BLL.LeaseBLL.GetLeaseAccountList(0);
                table           = tmpDs.Tables[0].Clone();
                table.TableName = "LeaseAccountList";
                FDataSet.Tables.Add(table);

                tmpDs           = BLL.LeaseBLL.GetLeaseAccountLeft(0);
                table           = tmpDs.Tables[0].Clone();
                table.TableName = "LeaseAccountLeft";
                FDataSet.Tables.Add(table);

                //将需要结算的数据填写到报表中的表中
                FillReportData(FDataSet);

                FastReport.Report report1 = new FastReport.Report();
                report1.Load("Reports\\LeaseJS.frx");
                report1.RegisterData(FDataSet);
                report1.Show();
                report1.Dispose();
            }
        }
Exemplo n.º 11
0
        void 新租赁记录ToolStripMenuItemClick(object sender, EventArgs e)
        {
            FormLeaseRecord1 tF = new FormLeaseRecord1();

            tF.Text = "租赁记录-新增";

            int i_ProjectID;
            int i_CompanyID;

            if (comboBoxProject.SelectedValue == null || comboBoxCompany.SelectedValue == null)
            {
                return;
            }

            i_ProjectID = Convert.ToInt32(comboBoxProject.SelectedValue.ToString());
            i_CompanyID = Convert.ToInt32(comboBoxCompany.SelectedValue.ToString());
            LeaseHT tLeaseHT = BLL.LeaseBLL.GetLeaseHT(i_ProjectID, i_CompanyID);

            tF.i_HTID = tLeaseHT.HTID;
            tF.ShowDialog();
            //刷新
            RefreshLeaseRecord();
        }
Exemplo n.º 12
0
        void ButtonJSClick(object sender, EventArgs e)
        {
            //结算
            int      i_ProjectID = Convert.ToInt32(comboBoxProject.SelectedValue.ToString());
            int      i_CompanyID = Convert.ToInt32(comboBoxCompany.SelectedValue.ToString());
            DateTime dSDate      = dateTimePickerSDate.Value.Date;
            DateTime dEDate      = dateTimePickerEDate.Value.Date;
            string   s_BillCycle = textBoxBillCycle.Text;                       //结算周期
            //1.结算周期不包含在结算时间段中
            string s1 = dSDate.ToString("yyyyMM");
            string s2 = dEDate.ToString("yyyyMM");

            if (String.Compare(s_BillCycle, s1) == -1 || String.Compare(s_BillCycle, s2) == 1)
            {
                MessageBox.Show("结算周期错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //2.结算周期已经结算过了
            if (BLL.LeaseBLL.GetLeaseJSLine(i_ProjectID, i_CompanyID, s_BillCycle) > 0)
            {
                MessageBox.Show("输入的结算周期已经结算过了!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //3.还有日期在结算日期之前的记录未结算
            LeaseHT tLeaseHT = new LeaseHT();

            tLeaseHT = BLL.LeaseBLL.GetLeaseHT(i_ProjectID, i_CompanyID);
            if (BLL.LeaseBLL.GetLeaseRecord(tLeaseHT.HTID, dSDate) > 0)
            {
                MessageBox.Show("存在结算日期段前未结算的租赁数据!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            ButtonJSPreviewClick(sender, e);
            MainForm pF = (MainForm)(this.Parent.Parent.Parent.Parent);

            UpdateToDataBase(pF);
        }
Exemplo n.º 13
0
        //删除租赁结算
        public static void DelLeaseAccount(int i_ProjectID, int i_CompanyID, string s_BillCycle)
        {
            //1.检查是否是最后的结算周期
            int i_rtn = Convert.ToInt32(SQLiteHelper.ExecuteScalar("SELECT Count(*) FROM LeaseAccount WHERE ProjectID=@ProjectID AND CompanyID = @CompanyID AND BillCycle > @BillCycle", i_ProjectID, i_CompanyID, s_BillCycle));

            if (i_rtn > 0)
            {
                return;
            }
            string[,] ALeaseAccountLeft = new string[50, 2];                    //用于保存当前剩余租赁材料
            int    i_BillID           = Convert.ToInt32(SQLiteHelper.ExecuteScalar("SELECT BillID FROM LeaseAccount WHERE ProjectID=@ProjectID AND CompanyID = @CompanyID AND BillCycle = @BillCycle", i_ProjectID, i_CompanyID, s_BillCycle));
            int    i_SID              = Convert.ToInt32(SQLiteHelper.ExecuteScalar("SELECT SID FROM StatementList WHERE ProjectID=@ProjectID AND CompanyID = @CompanyID AND StatementCycle = @StatementCycle", i_ProjectID, i_CompanyID, s_BillCycle));
            string s_LastMaxBillCycle = "";                     //删除周期前的最大周期

            s_LastMaxBillCycle = SQLiteHelper.ExecuteScalar("SELECT MAX(BillCycle) FROM LeaseAccount WHERE BillCycle < @BillCycle", s_BillCycle).ToString();

            LeaseHT tLeaseHT = BLL.LeaseBLL.GetLeaseHT(i_ProjectID, i_CompanyID);
            //把保存剩余租赁量的数组数据填好,全部是字符串
            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;
                    }
                }
            }

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

            try {
                //2.删除LeaseAccountList
                dsTmp = BLL.LeaseBLL.GetLeaseAccountList(i_BillID);
                foreach (DataRow dr in dsTmp.Tables[0].Rows)
                {
                    LeaseAccountList tLeaseAccountList = session.Get <LeaseAccountList>(Convert.ToInt32(dr["ListID"]));
                    if (tLeaseAccountList.LeaseClass != 0)
                    {
                        session.Delete(tLeaseAccountList);                              //删除
                        continue;
                    }

                    //检查此租赁项是否存在,存在则更新LeaseAccountLeft,否则添加
                    string s_0 = tLeaseAccountList.ItemsID.ToString();
                    string s_1 = tLeaseAccountList.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;
                            }
                            //继续找
                        }
                    }
                    session.Delete(tLeaseAccountList);                          //删除
                }

                //3.改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 = s_LastMaxBillCycle;
                            tLeaseAccountLeft.LastEDate     = DateTime.Now.Date;
                            session.Save(tLeaseAccountLeft);
                        }
                        else
                        {
                            tLeaseAccountLeft.QualityLeft   = Convert.ToDecimal(ALeaseAccountLeft[j, 1]);
                            tLeaseAccountLeft.LastBillCycle = s_LastMaxBillCycle;
                            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();
            }
            //4.删除LeaseAccount
            SQLiteHelper.ExecuteNonQuery("DELETE FROM LeaseAccount WHERE BillID=@BillID", i_BillID);
            //5.删除StatementList
            SQLiteHelper.ExecuteNonQuery("DELETE FROM StatementList WHERE SID=@SID", i_SID);
            //6.更新LeaseRecord表对应周期的结算状态为“未结算”
            DateTime dt1 = new DateTime(Convert.ToInt32(s_BillCycle.Substring(0, 4)), Convert.ToInt32(s_BillCycle.Substring(4, 2)), 1);

            DateTime dt2 = dt1.AddMonths(1).AddDays(-1 * (dt1.Day));

            SQLiteHelper.ExecuteNonQuery("UPDATE LeaseRecord SET LeaseStatus = '未结算' WHERE LeaseDate BETWEEN @SDate AND @EDate", dt1, dt2);

            return;
        }
Exemplo n.º 14
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 = "就绪";
        }
Exemplo n.º 15
0
        //填数据
        void FillReportData(DataSet FDataSet)
        {
            int      i_ProjectID    = Convert.ToInt32(comboBoxProject.SelectedValue.ToString());
            int      i_CompanyID    = Convert.ToInt32(comboBoxCompany.SelectedValue.ToString());
            int      i_SNumber      = 1;                //租赁结算顺序号
            DateTime dSDate         = dateTimePickerSDate.Value.Date;
            DateTime dEDate         = dateTimePickerEDate.Value.Date;
            TimeSpan tTS            = dEDate.Subtract(dSDate);
            int      i_Days         = tTS.Days + 1;             //结余时租赁天数
            LeaseHT  tLeaseHT       = BLL.LeaseBLL.GetLeaseHT(i_ProjectID, i_CompanyID);
            int      i_IncludeSDate = tLeaseHT.IncludeSDate;    //租金包含开始日
            int      i_IncludeEDate = tLeaseHT.IncludeEDate;    //租金包含结束日
            string   s_BillCycle    = textBoxBillCycle.Text;    //结算周期
            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 = "倒扣计算法,算尾不算头";
            }
            List <ItemsLeftStru> RemainKeyValue = new List <ItemsLeftStru>();
//			myKV.ItemdID = 1;
//			myKV.ItemsName = "asdd";
//			myKV.ItemsValue = 12.80;
//			RemainKeyValue.Add(myKV);


            //1.填LeaseAccount表
            DataRow dr = FDataSet.Tables["LeaseAccount"].NewRow();

            dr["BillID"]      = 10000;
            dr["ProjectID"]   = i_ProjectID;
            dr["ProjectName"] = comboBoxProject.Text;
            dr["CompanyID"]   = i_CompanyID;
            dr["CompanyName"] = comboBoxCompany.Text;
            dr["BillCycle"]   = s_BillCycle;
            dr["CalMethod"]   = s_CalMethod;
            FDataSet.Tables["LeaseAccount"].Rows.Add(dr);

            //2.填LeaseAccountList表
            //2.1填结余租赁项
            DataSet tds = BLL.LeaseBLL.GetLeaseAccountLeft(tLeaseHT.HTID);

            foreach (DataRow drtmp in tds.Tables[0].Rows)
            {
                dr = FDataSet.Tables["LeaseAccountList"].NewRow();
                int        i_ItemsID  = Convert.ToInt32(drtmp["ItemsID"]);
                LeaseItems tLeaseItem = BLL.LeaseBLL.GetLeaseItem(i_ItemsID);
                dr["ListID"]       = i_SNumber;
                dr["SNumber"]      = i_SNumber;
                dr["BillID"]       = 10000;
                dr["Abstract"]     = tLeaseItem.MName + " 上期结余";
                dr["SDate"]        = dSDate;
                dr["EDate"]        = dEDate;
                dr["LeaseUnit"]    = tLeaseItem.LeaseUnit;
                dr["LeaseQuality"] = drtmp["QualityLeft"];
                dr["LeasePrice"]   = tLeaseItem.LeasePrice;
                dr["LeaseDays"]    = i_Days;
                dr["LeaseAmt"]     = Convert.ToDecimal(dr["LeaseQuality"]) * Convert.ToDecimal(dr["LeasePrice"]) * i_Days;

                FDataSet.Tables["LeaseAccountList"].Rows.Add(dr);

                ItemsLeftStru myKV = new ItemsLeftStru();
                myKV.ItemdID    = tLeaseItem.ItemsID;
                myKV.ItemsName  = tLeaseItem.MName;
                myKV.ItemsUnit  = tLeaseItem.LeaseUnit;
                myKV.ItemsValue = Convert.ToDouble(dr["LeaseQuality"]);
                AddKeyValue(ref RemainKeyValue, myKV);

                i_SNumber++;
            }
            //2.2按照时间顺序计算各项租金
            tds = BLL.LeaseBLL.GetLeaseRecord2(i_ProjectID, i_CompanyID);               //未结算的记录
            foreach (DataRow drtmp in tds.Tables[0].Rows)
            {
                //检查租赁日期是否在结算日期范围
                DateTime tLeaseDate = Convert.ToDateTime(drtmp["LeaseDate"]);
                if (tLeaseDate >= dSDate && tLeaseDate <= dEDate)
                {
                    dr = FDataSet.Tables["LeaseAccountList"].NewRow();
                    int        i_ItemsID  = Convert.ToInt32(drtmp["ItemsID"]);
                    LeaseItems tLeaseItem = BLL.LeaseBLL.GetLeaseItem(i_ItemsID);



                    dr["ListID"]  = i_SNumber;
                    dr["SNumber"] = i_SNumber;
                    dr["BillID"]  = 10000;
                    if (drtmp["Abstract"].ToString().Length != 0)
                    {
                        dr["Abstract"] = tLeaseItem.MName + "(" + drtmp["Abstract"] + ")";
                    }
                    else
                    {
                        dr["Abstract"] = tLeaseItem.MName;
                    }
                    DateTime dt1 = Convert.ToDateTime(drtmp["LeaseDate"]);
                    dr["SDate"] = dt1;
                    dr["EDate"] = dEDate;
                    TimeSpan tTS1  = dEDate.Subtract(dt1);
                    int      tDays = tTS1.Days;

                    if (Convert.ToDecimal(drtmp["Quality"]) > 0)
                    {
                        if (i_IncludeSDate == 1)
                        {
                            tDays++;
                        }
                    }
                    else
                    {
                        if (i_IncludeEDate != 1)
                        {
                            tDays++;
                        }
                    }

                    if (tLeaseItem.LeaseClass == 0)
                    {
                        //租赁项
                        dr["LeaseUnit"]    = tLeaseItem.LeaseUnit;
                        dr["LeaseQuality"] = drtmp["Quality"];
                        dr["LeasePrice"]   = tLeaseItem.LeasePrice;
                        dr["LeaseDays"]    = tDays;
                        dr["LeaseAmt"]     = Convert.ToDecimal(dr["LeaseQuality"]) * Convert.ToDecimal(dr["LeasePrice"]) * tDays;

                        dr["LoadingUnit"]    = tLeaseItem.LoadingUnit;
                        dr["LoadingFactor"]  = tLeaseItem.LoadingFactor;
                        dr["LoadingQuality"] = Math.Abs(Convert.ToDecimal(dr["LeaseQuality"]) / Convert.ToDecimal(dr["LoadingFactor"]));
                        dr["LoadingPrice"]   = tLeaseItem.LoadingPrice;
                        dr["LoadingAmt"]     = Math.Abs(Convert.ToDecimal(dr["LoadingPrice"]) * Convert.ToDecimal(dr["LoadingQuality"]));

                        if (Convert.ToDecimal(drtmp["Quality"]) < 0)
                        {
                            dr["RepairUnit"]    = tLeaseItem.RepairUnit;
                            dr["RepairFactor"]  = tLeaseItem.RepairFactor;
                            dr["RepairQuality"] = Math.Abs(Convert.ToDecimal(dr["LeaseQuality"]) / Convert.ToDecimal(dr["RepairFactor"]));
                            dr["RepairPrice"]   = tLeaseItem.RepairPrice;
                            dr["RepairAmt"]     = Math.Abs(Convert.ToDecimal(dr["RepairPrice"]) * Convert.ToDecimal(dr["RepairQuality"]));
                        }

                        ItemsLeftStru myKV = new ItemsLeftStru();
                        myKV.ItemdID    = tLeaseItem.ItemsID;
                        myKV.ItemsName  = tLeaseItem.MName;
                        myKV.ItemsUnit  = tLeaseItem.LeaseUnit;
                        myKV.ItemsValue = Convert.ToDouble(dr["LeaseQuality"]);
                        AddKeyValue(ref RemainKeyValue, myKV);
                    }
                    else
                    {
                        //单独结算项
                        dr["LeaseUnit"]    = tLeaseItem.LeaseUnit;
                        dr["OtherUnit"]    = tLeaseItem.LeaseUnit;
                        dr["OtherQuality"] = drtmp["Quality"];
                        dr["OtherPrice"]   = tLeaseItem.LeasePrice;
                        dr["OtherAmt"]     = Convert.ToDecimal(dr["OtherPrice"]) * Convert.ToDecimal(dr["OtherQuality"]);
                    }
                    FDataSet.Tables["LeaseAccountList"].Rows.Add(dr);



                    i_SNumber++;
                }
            }
            //2.3将计算出来的余量数据填写好
            foreach (ItemsLeftStru itemLS in RemainKeyValue)
            {
                dr                = FDataSet.Tables["LeaseAccountLeft"].NewRow();
                dr["ItemsID"]     = itemLS.ItemdID;
                dr["MName"]       = itemLS.ItemsName;
                dr["LeaseUnit"]   = itemLS.ItemsUnit;
                dr["QualityLeft"] = itemLS.ItemsValue;
                FDataSet.Tables["LeaseAccountLeft"].Rows.Add(dr);
            }
        }