예제 #1
0
        ///// <summary>
        ///// List data
        ///// </summary>
        //private void ShowData(string YearMonth)
        //{
        //    //divRent.Visible = true;
        //    //divManager.Visible = true;
        //    //divParking.Visible = true;
        //    //divService.Visible = true;
        //    //divWater.Visible = true;
        //    //divExtraTime.Visible = true;
        //    //divElec.Visible = true;
        //    hidBillId.Value = DbHelper.GetScalar("Select id from PaymentBillInfo where customerid = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "' and BuildingId= '" + Func.ParseString(Session["__BUILDINGID__"]) + "'");
        //    if (!String.IsNullOrEmpty(hidBillId.Value))
        //    {
        //        PaymentBillInfoData data = new PaymentBillInfoData();
        //        ITransaction tran = factory.GetLoadObject(data, hidBillId.Value);
        //        Execute(tran);
        //        if (!HasError)
        //        {
        //            data = (PaymentBillInfoData)tran.Result;
        //            txtBillNo.Text = data.BillNo;
        //            txtBillDate.Text = data.BillDate;
        //            txtUsdExchangeDate.Text = Func.FormatDMY(data.UsdExchangeDate);
        //            txtUsdExchange.Text = Func.ParseString(Func.ParseFloat(data.UsdExchange));
        //        }
        //        btnCreate.Text = "Tính lại tiền";
        //        //divDetail.Visible = true;
        //    }
        //    else
        //    {
        //        txtBillNo.Text = "";
        //        txtBillDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
        //        txtUsdExchangeDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
        //        txtUsdExchange.Text = "";
        //        btnCreate.Text = "Tạo Hóa Đơn";
        //        //divDetail.Visible = false;
        //    }
        //    SqlDatabase db = new SqlDatabase();
        //    string sql = string.Empty;
        //    if (!Func.IsValid(ListSortExpression))
        //    {
        //        ListSortExpression = "Name";
        //        ListSortDirection = SortDirection.Descending;
        //    }
        //    try
        //    {
        //        //Rent And Manager Price
        //        sql = string.Empty;
        //        string sort = ListSortExpression + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");
        //        //Xuất ra toàn bộ nội dung theo Trang
        //        sql += " Select *";
        //        sql += " FROM PaymentRoom";
        //        sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
        //        SqlCommand cm = db.CreateCommand(sql);
        //        SqlDataAdapter da = new SqlDataAdapter(cm);
        //        DataSet ds = new DataSet();
        //        da.Fill(ds);
        //        db.Close();
        //        rptRoomRent.DataSource = ds.Tables[0].DefaultView;
        //        rptRoomRent.DataBind();
        //        rptRoomManager.DataSource = ds.Tables[0].DefaultView;
        //        rptRoomManager.DataBind();
        //        //Parking
        //        sql = string.Empty;
        //        sort = "TariffsParkingName" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");
        //        //Xuất ra toàn bộ nội dung theo Trang
        //        sql += " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND";
        //        sql += "        , SUM(LastPriceUSD) AS LastPriceUSD";
        //        sql += " FROM         dbo.PaymentParking";
        //        sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
        //        sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat, daysParking";
        //        cm = db.CreateCommand(sql);
        //        da = new SqlDataAdapter(cm);
        //        ds = new DataSet();
        //        da.Fill(ds);
        //        db.Close();
        //        rptParking.DataSource = ds.Tables[0].DefaultView;
        //        rptParking.DataBind();
        //        //Extra Time
        //        sql = string.Empty;
        //        sort = "WorkingDate" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");
        //        //Xuất ra toàn bộ nội dung theo Trang
        //        sql += " SELECT * ";
        //        sql += " FROM   PaymentExtraTime";
        //        sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
        //        cm = db.CreateCommand(sql);
        //        da = new SqlDataAdapter(cm);
        //        ds = new DataSet();
        //        da.Fill(ds);
        //        db.Close();
        //        rptExtraTime.DataSource = ds.Tables[0].DefaultView;
        //        rptExtraTime.DataBind();
        //        //Elec
        //        ListSortDirection = SortDirection.Ascending;
        //        sql = string.Empty;
        //        sort = "B.FromIndex" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");
        //        //Xuất ra toàn bộ nội dung theo Trang
        //        sql += " SELECT BD_Room.Name as RoomName, A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
        //        sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name,B.WaterPricePercent,B.ElecPricePercent ";
        //        sql += " FROM   PaymentElecWater AS A INNER JOIN ";
        //        sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId INNER JOIN";
        //        sql += "        BD_Room ON A.RoomId = BD_Room.id";
        //        sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0  and A.YearMonth = '" + YearMonth + "'";
        //        sql += " Order by " + sort;
        //        cm = db.CreateCommand(sql);
        //        da = new SqlDataAdapter(cm);
        //        ds = new DataSet();
        //        da.Fill(ds);
        //        db.Close();
        //        rptElec.DataSource = ds.Tables[0].DefaultView;
        //        rptElec.DataBind();
        //        //Water
        //        sql = string.Empty;
        //        //Xuất ra toàn bộ nội dung theo Trang
        //        sql += " SELECT BD_Room.Name as RoomName, A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
        //        sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name,B.WaterPricePercent,B.ElecPricePercent ";
        //        sql += " FROM   PaymentElecWater AS A INNER JOIN ";
        //        sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId INNER JOIN";
        //        sql += "        BD_Room ON A.RoomId = BD_Room.id";
        //        sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth = '" + YearMonth + "'";
        //        sql += " Order by " + sort;
        //        cm = db.CreateCommand(sql);
        //        da = new SqlDataAdapter(cm);
        //        ds = new DataSet();
        //        da.Fill(ds);
        //        db.Close();
        //        rptWater.DataSource = ds.Tables[0].DefaultView;
        //        rptWater.DataBind();
        //        //Service
        //        sql = string.Empty;
        //        sort = "ServiceDate" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");
        //        //Xuất ra toàn bộ nội dung theo Trang
        //        sql += " SELECT * ";
        //        sql += " FROM   PaymentService";
        //        sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
        //        cm = db.CreateCommand(sql);
        //        da = new SqlDataAdapter(cm);
        //        ds = new DataSet();
        //        da.Fill(ds);
        //        db.Close();
        //        rptService.DataSource = ds.Tables[0].DefaultView;
        //        rptService.DataBind();
        //        //Dept
        //        sql = string.Empty;
        //        sort = "YearMonth" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");
        //        ////Parking
        //        //sql = string.Empty;
        //        //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
        //        //sql += " FROM  PaymentParking";
        //        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
        //        //sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat";
        //        //dt = DbHelper.GetDataTable(sql);
        //        //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
        //        //{
        //        //    lblParkingUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //    lblParkingVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //}
        //        ////Extra Time
        //        //sql = string.Empty;
        //        //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
        //        //sql += " FROM   PaymentExtraTime";
        //        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
        //        //dt = DbHelper.GetDataTable(sql);
        //        //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
        //        //{
        //        //    lblExtraTimeUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //    lblExtraTimeVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //}
        //        ////Elec
        //        //sql = string.Empty;
        //        //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
        //        //sql += " FROM   PaymentElecWater";
        //        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0 and YearMonth = '" + YearMonth + "'";
        //        //dt = DbHelper.GetDataTable(sql);
        //        //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
        //        //{
        //        //    lblElecUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //    lblElecVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //}
        //        ////Water
        //        //sql = string.Empty;
        //        //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
        //        //sql += " FROM   PaymentElecWater ";
        //        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and YearMonth = '" + YearMonth + "'";
        //        //dt = DbHelper.GetDataTable(sql);
        //        //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
        //        //{
        //        //    lblWaterUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //    lblWaterVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //}
        //        ////Service
        //        //sql = string.Empty;
        //        //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
        //        //sql += " FROM   PaymentService";
        //        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
        //        //dt = DbHelper.GetDataTable(sql);
        //        //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
        //        //{
        //        //    lblServiceUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //    lblServiceVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
        //        //}
        //        ////Dept
        //        //sql = string.Empty;
        //        //sql += " SELECT sum(RemainRentUSD+RemainManagerUSD+RemainElecUSD+RemainWaterUSD+RemainServiceUSD+RemainParkingUSD+RemainExtraTimePriceUSD) as SumUSD,sum(RemainRentVND+RemainManagerVND+RemainElecVND+RemainWaterVND+RemainServiceVND+RemainParkingVND+RemainExtraTimePriceVND) AS SumVND ";
        //        //sql += " FROM   v_PaymentYearMonthDept";
        //        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' And";
        //        //sql += " (RemainRentUSD+RemainManagerUSD+RemainElecUSD+RemainWaterUSD+RemainServiceUSD+RemainParkingUSD+RemainExtraTimePriceUSD)>0 and YearMonth <> '" + YearMonth + "'";
        //        //dt = DbHelper.GetDataTable(sql);
        //        sql = "Select  *";
        //        sql += " From    PaymentBillDetail";
        //        sql += " Where   BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
        //        DataTable dt = DbHelper.GetDataTable(sql);
        //        for (int i = 0; i < dt.Rows.Count; i++)
        //        {
        //            string PaymentType = Func.ParseString(dt.Rows[i]["PaymentType"]);
        //            string MoneyUSD = Func.ParseString(dt.Rows[i]["MoneyUSD"]);
        //            string MoneyVND = Func.ParseString(dt.Rows[i]["MoneyVND"]);
        //            string PaidUSD = Func.ParseString(dt.Rows[i]["PaidUSD"]);
        //            string PaidVND = Func.ParseString(dt.Rows[i]["PaidVND"]);
        //            string ExchangeType = Func.ParseString(dt.Rows[i]["ExchangeType"]);
        //            //string UsdExchange = Func.ParseString(dt.Rows[i]["UsdExchange"]);
        //            decimal tmpUSD = Convert.ToDecimal(MoneyUSD) - Convert.ToDecimal(PaidUSD);
        //            decimal tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND);
        //            switch (PaymentType)
        //            {
        //                case "1":
        //                    //Rent
        //                    lblRentUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblRentVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblRentPaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblRentPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    txtRentPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    txtRentPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    if (tmpUSD > 0)
        //                    {
        //                        txtRentPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    }
        //                    if (tmpVND > 0)
        //                    {
        //                        txtRentPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    }
        //                    break;
        //                case "2":
        //                    //Manager
        //                    lblMangagerUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblMangagerVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblMangagerPaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblMangagerPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    txtManagerPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    txtManagerPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    if (tmpUSD > 0)
        //                    {
        //                        txtManagerPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    }
        //                    if (tmpVND > 0)
        //                    {
        //                        txtManagerPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    }
        //                    break;
        //                case "3":
        //                    //Parking
        //                    lblParkingUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblParkingVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblParkingPaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblParkingPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    txtParkingPaidUSD.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
        //                    txtParkingPaidVND.Text = Func.FormatNumber_New(Func.ParseDouble(MoneyVND) - Func.ParseFloat(PaidVND));
        //                    txtParkingPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    txtParkingPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    if (tmpUSD > 0)
        //                    {
        //                        txtParkingPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    }
        //                    if (tmpVND > 0)
        //                    {
        //                        txtParkingPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    }
        //                    break;
        //                case "4":
        //                    lblExtraTimeUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblExtraTimeVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblExtraTimePaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblExtraTimePaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    txtExtraTimePaidUSD.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
        //                    txtExtraTimePaidVND.Text = Func.FormatNumber_New(Func.ParseDouble(MoneyVND) - Func.ParseFloat(PaidVND));
        //                    txtExtraTimePaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    txtExtraTimePaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    if (tmpUSD > 0)
        //                    {
        //                        txtExtraTimePaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    }
        //                    if (tmpVND > 0)
        //                    {
        //                        txtExtraTimePaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    }
        //                    break;
        //                case "5":
        //                    //lblElecUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblElecVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    //lblElecPaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
        //                    lblElecPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    //txtElecPaidUSD.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
        //                    txtElecPaidVND.Text = Func.FormatNumber_New(Func.ParseDouble(MoneyVND) - Func.ParseFloat(PaidVND));
        //                    //txtElecPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    txtElecPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    //if (tmpUSD > 0)
        //                    //{
        //                    //    txtElecPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    //}
        //                    if (tmpVND > 0)
        //                    {
        //                        txtElecPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    }
        //                    break;
        //                case "6":
        //                    //lblWaterUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblWaterVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    //lblWaterPaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
        //                    lblWaterPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    //txtWaterPaidUSD.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
        //                    txtWaterPaidVND.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND));
        //                    //txtWaterPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    txtWaterPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    //if (tmpUSD > 0)
        //                    //{
        //                    //    txtWaterPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    //}
        //                    if (tmpVND > 0)
        //                    {
        //                        txtWaterPaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    }
        //                    break;
        //                case "7":
        //                    lblServiceUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblServiceVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblServicePaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
        //                    lblServicePaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get
        //                    txtServicePaidUSD.Text = Func.ParseString(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
        //                    txtServicePaidVND.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND));
        //                    txtServicePaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    txtServicePaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    if (tmpUSD > 0)
        //                    {
        //                        txtServicePaidUSD.Text = Func.FormatNumber_New(tmpUSD);
        //                    }
        //                    if (tmpVND > 0)
        //                    {
        //                        txtServicePaidVND.Text = Func.FormatNumber_New(tmpVND);
        //                    }
        //                    break;
        //                default:
        //                    break;
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        ApplicationLog.WriteError(ex);
        //    }
        //}
        private void ShowData()
        {
            hidBillId.Value = DbHelper.GetScalar("Select id from PaymentBillInfo where customerid = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "' and BuildingId= '" + Func.ParseString(Session["__BUILDINGID__"]) + "'");

            if (!String.IsNullOrEmpty(hidBillId.Value))
            {
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetLoadObject(data, hidBillId.Value);
                Execute(tran);
                if (!HasError)
                {
                    data = (PaymentBillInfoData)tran.Result;

                    txtBillNo.Text = data.BillNo;
                    txtBillDate.Text = data.BillDate;
                    txtUsdExchangeDate.Text = Func.FormatDMY(data.UsdExchangeDate);
                    txtUsdExchange.Text = Func.ParseString(Func.ParseFloat(data.UsdExchange));
                }

                btnCreate.Text = "Lưu Hóa Đơn";
                //divDetail.Visible = true;
            }
            else
            {
                txtBillNo.Text = "";
                txtBillDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
                txtUsdExchangeDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
                txtUsdExchange.Text = "";

                btnCreate.Text = "Tạo Hóa Đơn";
                //divDetail.Visible = false;
            }

            if (String.IsNullOrEmpty(hidBillId.Value))
            {
                mvMessage.AddError("Tháng chưa tạo Hóa Đơn");
                //return;
            }
            string yearMonths = DbHelper.GetScalar("Select YearMonths from PaymentBillInfo where id = '" + hidBillId.Value + "'");
            if (String.IsNullOrEmpty(yearMonths))
            {
                yearMonths = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
            }

            lstYearMonth.Items.Clear();
            lstSelectedYearMonth.Items.Clear();

            for (int i = -9; i < 12; i++)
            {
                if (yearMonths.IndexOf(DateTime.Now.AddMonths(i).ToString("yyyyMM")) < 0)
                {
                    lstYearMonth.Items.Add(new ListItem(DateTime.Now.AddMonths(i).ToString("MM/yyyy"), DateTime.Now.AddMonths(i).ToString("yyyyMM")));
                }
                else
                {
                    lstSelectedYearMonth.Items.Add(new ListItem(DateTime.Now.AddMonths(i).ToString("MM/yyyy"), DateTime.Now.AddMonths(i).ToString("yyyyMM")));
                }
            }

            string lsYearmonth = "";
            foreach (ListItem lstItem in lstSelectedYearMonth.Items)
            {
                lsYearmonth += ",'" + lstItem.Value + "'";
            }
            if (String.IsNullOrEmpty(lsYearmonth))
            {
                mvMessage.AddError("Phải chọn ít nhất 1 tháng");
                return;
            }

            //divRent.Visible = false;
            //divManager.Visible = false;
            //divParking.Visible = false;
            //divService.Visible = false;
            //divWater.Visible = false;
            //divExtraTime.Visible = false;
            //divElec.Visible = false;

            lsYearmonth = lsYearmonth.Substring(1);

            SqlDatabase db = new SqlDatabase();
            string sql = string.Empty;
            if (!Func.IsValid(ListSortExpression))
            {
                ListSortExpression = "Name";
                ListSortDirection = SortDirection.Descending;
            }
            try
            {
                //Rent And Manager Price
                sql = string.Empty;
                string sort = ListSortExpression + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " Select *";
                sql += " FROM PaymentRoom";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";

                SqlCommand cm = db.CreateCommand(sql);
                SqlDataAdapter da = new SqlDataAdapter(cm);
                DataSet ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptRoomRent.DataSource = ds.Tables[0].DefaultView;
                rptRoomRent.DataBind();

                rptRoomManager.DataSource = ds.Tables[0].DefaultView;
                rptRoomManager.DataBind();

                //Parking
                sql = string.Empty;
                sort = "TariffsParkingName" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND";
                sql += "        , SUM(LastPriceUSD) AS LastPriceUSD";
                sql += " FROM         dbo.PaymentParking";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";
                sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat, daysParking";

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptParking.DataSource = ds.Tables[0].DefaultView;
                rptParking.DataBind();

                //Extra Time
                sql = string.Empty;
                sort = "WorkingDate" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT * ";
                sql += " FROM   PaymentExtraTime";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptExtraTime.DataSource = ds.Tables[0].DefaultView;
                rptExtraTime.DataBind();

                //Elec
                ListSortDirection = SortDirection.Ascending;
                sql = string.Empty;
                sort = "B.FromIndex" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT BD_Room.Name as RoomName, A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name,B.WaterPricePercent,B.ElecPricePercent ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId INNER JOIN";
                sql += "        BD_Room ON A.RoomId = BD_Room.id";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0  and A.YearMonth in (" + lsYearmonth + ") and B.DetailType = 1";
                sql += " Order by " + sort;

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptElec.DataSource = ds.Tables[0].DefaultView;
                rptElec.DataBind();

                //Water
                sql = string.Empty;

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT BD_Room.Name as RoomName, A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name,B.WaterPricePercent,B.ElecPricePercent ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId INNER JOIN";
                sql += "        BD_Room ON A.RoomId = BD_Room.id";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth in (" + lsYearmonth + ")  and B.DetailType = 2";
                sql += " Order by " + sort;

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptWater.DataSource = ds.Tables[0].DefaultView;
                rptWater.DataBind();

                //Service
                sql = string.Empty;
                sort = "ServiceDate" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT * ";
                sql += " FROM   PaymentService";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptService.DataSource = ds.Tables[0].DefaultView;
                rptService.DataBind();

                //Dept
                sql = string.Empty;
                sort = "YearMonth" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                ////Parking
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM  PaymentParking";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
                //sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblParkingUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblParkingVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Extra Time
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM   PaymentExtraTime";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblExtraTimeUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblExtraTimeVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Elec
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM   PaymentElecWater";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0 and YearMonth = '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblElecUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblElecVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Water
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM   PaymentElecWater ";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and YearMonth = '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblWaterUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblWaterVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Service
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM   PaymentService";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblServiceUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblServiceVND.Text =  Func.FormatNumber_New(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Dept
                //sql = string.Empty;
                //sql += " SELECT sum(RemainRentUSD+RemainManagerUSD+RemainElecUSD+RemainWaterUSD+RemainServiceUSD+RemainParkingUSD+RemainExtraTimePriceUSD) as SumUSD,sum(RemainRentVND+RemainManagerVND+RemainElecVND+RemainWaterVND+RemainServiceVND+RemainParkingVND+RemainExtraTimePriceVND) AS SumVND ";
                //sql += " FROM   v_PaymentYearMonthDept";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' And";
                //sql += " (RemainRentUSD+RemainManagerUSD+RemainElecUSD+RemainWaterUSD+RemainServiceUSD+RemainParkingUSD+RemainExtraTimePriceUSD)>0 and YearMonth <> '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                sql = "  Select  SUM(MoneyUSD) AS MoneyUSD, SUM(MoneyVND) AS MoneyVND, SUM(PaidUSD) AS PaidUSD, SUM(PaidVND) AS PaidVND, PaymentType";
                sql += " From    PaymentBillDetail";
                sql += " Where   BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";
                sql += " GROUP BY PaymentType";

                DataTable dt = DbHelper.GetDataTable(sql);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string PaymentType = Func.ParseString(dt.Rows[i]["PaymentType"]);
                    string MoneyUSD = Func.ParseString(dt.Rows[i]["MoneyUSD"]);
                    string MoneyVND = Func.ParseString(dt.Rows[i]["MoneyVND"]);
                    string PaidUSD = Func.ParseString(dt.Rows[i]["PaidUSD"]);
                    string PaidVND = Func.ParseString(dt.Rows[i]["PaidVND"]);
                    //string ExchangeType = Func.ParseString(dt.Rows[i]["ExchangeType"]);
                    //string UsdExchange = Func.ParseString(dt.Rows[i]["UsdExchange"]);

                    decimal tmpUSD = Convert.ToDecimal(MoneyUSD) - Convert.ToDecimal(PaidUSD);
                    decimal tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND);

                    switch (PaymentType)
                    {
                        case "1":
                            //Rent
                            lblRentUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblRentVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get

                            lblRentPaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblRentPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get

                            txtRentPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            txtRentPaidVND.Text = Func.FormatNumber_New(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtRentPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtRentPaidVND.Text = Func.FormatNumber_New(tmpVND);
                            }
                            break;
                        case "2":
                            //Manager
                            lblMangagerUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblMangagerVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get

                            lblMangagerPaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblMangagerPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get

                            txtManagerPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            txtManagerPaidVND.Text = Func.FormatNumber_New(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtManagerPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtManagerPaidVND.Text = Func.FormatNumber_New(tmpVND);
                            }

                            break;
                        case "3":
                            //Parking
                            lblParkingUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblParkingVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get

                            lblParkingPaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblParkingPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get

                            txtParkingPaidUSD.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtParkingPaidVND.Text = Func.FormatNumber_New(Func.ParseDouble(MoneyVND) - Func.ParseFloat(PaidVND));

                            txtParkingPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            txtParkingPaidVND.Text = Func.FormatNumber_New(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtParkingPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtParkingPaidVND.Text = Func.FormatNumber_New(tmpVND);
                            }
                            break;
                        case "4":
                            lblExtraTimeUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblExtraTimeVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get

                            lblExtraTimePaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblExtraTimePaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get

                            txtExtraTimePaidUSD.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtExtraTimePaidVND.Text = Func.FormatNumber_New(Func.ParseDouble(MoneyVND) - Func.ParseFloat(PaidVND));

                            txtExtraTimePaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            txtExtraTimePaidVND.Text = Func.FormatNumber_New(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtExtraTimePaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtExtraTimePaidVND.Text = Func.FormatNumber_New(tmpVND);
                            }
                            break;
                        case "5":
                            //lblElecUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblElecVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get

                            //lblElecPaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblElecPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get

                            //txtElecPaidUSD.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtElecPaidVND.Text = Func.FormatNumber_New(Func.ParseDouble(MoneyVND) - Func.ParseFloat(PaidVND));

                            //txtElecPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            txtElecPaidVND.Text = Func.FormatNumber_New(tmpVND);

                            //if (tmpUSD > 0)
                            //{
                            //    txtElecPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            //}
                            if (tmpVND > 0)
                            {
                                txtElecPaidVND.Text = Func.FormatNumber_New(tmpVND);
                            }
                            break;
                        case "6":
                            //lblWaterUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblWaterVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get

                            //lblWaterPaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblWaterPaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get

                            //txtWaterPaidUSD.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtWaterPaidVND.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND));

                            //txtWaterPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            txtWaterPaidVND.Text = Func.FormatNumber_New(tmpVND);

                            //if (tmpUSD > 0)
                            //{
                            //    txtWaterPaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            //}
                            if (tmpVND > 0)
                            {
                                txtWaterPaidVND.Text = Func.FormatNumber_New(tmpVND);
                            }
                            break;
                        case "7":
                            lblServiceUSD.Text = Func.FormatNumber_New(MoneyUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblServiceVND.Text = Func.FormatNumber_New(MoneyVND); // Where Fieldname is the name of fields from your database that you want to get

                            lblServicePaidUSD.Text = Func.FormatNumber_New(PaidUSD); // Where Fieldname is the name of fields from your database that you want to get
                            lblServicePaidVND.Text = Func.FormatNumber_New(PaidVND); // Where Fieldname is the name of fields from your database that you want to get

                            txtServicePaidUSD.Text = Func.ParseString(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtServicePaidVND.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND));

                            txtServicePaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            txtServicePaidVND.Text = Func.FormatNumber_New(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtServicePaidUSD.Text = Func.FormatNumber_New(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtServicePaidVND.Text = Func.FormatNumber_New(tmpVND);
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.WriteError(ex);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string id = "";
            string yearmonth = drpYear.SelectedValue + drpMonth.SelectedValue;

            if (!(yearmonth.Equals(DateTime.Now.ToString("yyyyMM")) || yearmonth.Equals((DateTime.Now.AddMonths(-1).ToString("yyyyMM")))))
            {
                mvMessage.AddError("Chỉ thực hiện được trong tháng hoặc tháng trước");
                return;
            }

            mvMessage.CheckRequired(txtBillDate, "Ngày xuất Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtBillNo, "Số Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchange, "Tỉ giá USD-VN là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchangeDate, "Ngày tỉ giá là danh mục bắt buộc");

            if (!mvMessage.IsValid) return;

            if (String.IsNullOrEmpty(hidBillId.Value))
            {
                //Get and Insert Data
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetInsertObject(data);
                data.ModifiedBy = Page.User.Identity.Name;
                data.CreatedBy = Page.User.Identity.Name;
                data.Created = DateTime.Now.ToString("yyyyMMddHHmmss");
                data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss");
                data.DelFlag = "0";

                data.BuildingId = Func.ParseString(Session["__BUILDINGID__"]);
                data.CustomerId = lblCustomerId.Text.Trim();
                data.YearMonth = drpYear.SelectedValue + drpMonth.SelectedValue;
                //data.Name = txtName.Text.Trim();
                //data.ContactName = txtContactName.Text.Trim();
                //data.Bank = txtBank.Text.Trim();
                //data.Account = txtAccount.Text.Trim();
                //data.AccountName = txtAccountName.Text.Trim();
                //data.Office = txtOffice.Text.Trim();
                //data.OfficePhone = txtOfficePhone.Text.Trim();
                data.BillDate = Func.FormatYYYYmmdd(txtBillDate.Text.Trim());
                data.BillNo = txtBillNo.Text.Trim();
                data.UsdExchangeDate = Func.FormatYYYYmmdd(txtUsdExchangeDate.Text.Trim());
                data.UsdExchange = txtUsdExchange.Text.Trim();

                Execute(tran);

                if (!HasError)
                {
                    OperationLogger.WriteInfo(Constants.LogOperationAlbumId, Constants.LogActionInsertId, addSuccess, Page.User.Identity.Name);
                    mvMessage.SetCompleteMessage(addSuccess);
                    hidBillId.Value = data.id;

                    using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
                    {
                        con.Open();
                        using (SqlCommand cm = new SqlCommand("sp_PaymentDetailOneCustomer", con))
                        {
                            try
                            {
                                cm.CommandType = CommandType.StoredProcedure;
                                cm.Parameters.AddWithValue("@BuildingId", data.BuildingId);
                                cm.Parameters.AddWithValue("@CustomerId", data.CustomerId);
                                cm.Parameters.AddWithValue("@YearMonth", data.YearMonth);
                                //cm.Parameters.AddWithValue("@rent", rdoRentUSD.Checked == true ? "0" : "1");
                                //cm.Parameters.AddWithValue("@manager", rdoManagerUSD.Checked == true ? "0" : "1");
                                //cm.Parameters.AddWithValue("@parking", rdoParkingUSD.Checked == true ? "0" : "1");
                                //cm.Parameters.AddWithValue("@extratime", rdoExtraTimeUSD.Checked == true ? "0" : "1");
                                //cm.Parameters.AddWithValue("@elec", rdoElecUSD.Checked == true ? "0" : "1");
                                //cm.Parameters.AddWithValue("@water", rdoWaterUSD.Checked == true ? "0" : "1");
                                //cm.Parameters.AddWithValue("@service", rdoServiceUSD.Checked == true ? "0" : "1");

                                cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name);
                                cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name);

                                cm.CommandTimeout = 9999;

                                int ret = cm.ExecuteNonQuery();
                            }
                            catch (Exception ex)
                            {
                                ApplicationLog.WriteError(ex);
                            }
                            finally
                            {
                                con.Close();
                            }
                        }
                    }
                }
                else
                {
                    OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionInsertId, addUnSuccess, Page.User.Identity.Name);
                    mvMessage.AddError(addUnSuccess);
                }
            }
            else
            {
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetLoadObject(data, hidBillId.Value);
                Execute(tran);
                if (!HasError)
                {
                    //Get Data
                    data = (PaymentBillInfoData)tran.Result;
                    data.ModifiedBy = Page.User.Identity.Name;
                    data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss");
                    data.DelFlag = "0";
                    id = data.id;

                    data.BuildingId = Func.ParseString(Session["__BUILDINGID__"]);
                    //data.CustomerId = txtCustomerId.Text.Trim();
                    //data.YearMonth = hidYearMonth.Value;
                    //data.Name = txtName.Text.Trim();
                    //data.ContactName = txtContactName.Text.Trim();
                    //data.Bank = txtBank.Text.Trim();
                    //data.Account = txtAccount.Text.Trim();
                    //data.AccountName = txtAccountName.Text.Trim();
                    //data.Office = txtOffice.Text.Trim();
                    //data.OfficePhone = txtOfficePhone.Text.Trim();
                    data.BillDate = Func.FormatYYYYmmdd(txtBillDate.Text.Trim());
                    data.BillNo = txtBillNo.Text.Trim();
                    data.UsdExchangeDate = Func.FormatYYYYmmdd(Func.FormatYYYYmmdd(txtUsdExchangeDate.Text.Substring(0, 10)));
                    data.UsdExchange = txtUsdExchange.Text.Trim();

                    tran = factory.GetUpdateObject(data);

                    Execute(tran);

                    if (!HasError)
                    {
                        OperationLogger.WriteInfo(Constants.LogOperationAlbumId, Constants.LogActionUpdateId, addSuccess, Page.User.Identity.Name);
                        mvMessage.SetCompleteMessage(addSuccess);

                        using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
                        {
                            con.Open();
                            using (SqlCommand cm = new SqlCommand("sp_PaymentDetailOneCustomer", con))
                            {
                                try
                                {
                                    cm.CommandType = CommandType.StoredProcedure;
                                    cm.Parameters.AddWithValue("@BuildingId", data.BuildingId);
                                    cm.Parameters.AddWithValue("@CustomerId", data.CustomerId);
                                    cm.Parameters.AddWithValue("@YearMonth", data.YearMonth);
                                    //cm.Parameters.AddWithValue("@rent", rdoRentUSD.Checked == true ? "0" : "1");
                                    //cm.Parameters.AddWithValue("@manager", rdoManagerUSD.Checked == true ? "0" : "1");
                                    //cm.Parameters.AddWithValue("@parking", rdoParkingUSD.Checked == true ? "0" : "1");
                                    //cm.Parameters.AddWithValue("@extratime", rdoExtraTimeUSD.Checked == true ? "0" : "1");
                                    //cm.Parameters.AddWithValue("@elec", rdoElecUSD.Checked == true ? "0" : "1");
                                    //cm.Parameters.AddWithValue("@water", rdoWaterUSD.Checked == true ? "0" : "1");
                                    //cm.Parameters.AddWithValue("@service", rdoServiceUSD.Checked == true ? "0" : "1");

                                    cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                    cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name);
                                    cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                    cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name);

                                    cm.CommandTimeout = 9999;

                                    int ret = cm.ExecuteNonQuery();
                                }
                                catch (Exception ex)
                                {
                                    ApplicationLog.WriteError(ex);
                                }
                                finally
                                {
                                    con.Close();
                                }
                            }
                        }
                    }
                    else
                    {
                        OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionUpdateId, addUnSuccess, Page.User.Identity.Name);
                        mvMessage.AddError(addUnSuccess);
                    }
                }
            }
            ShowData(drpYear.SelectedValue + drpMonth.SelectedValue);
        }
예제 #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string id = "";
            string yearmonth = drpYear.SelectedValue + drpMonth.SelectedValue;
            hidBillId.Value = DbHelper.GetScalar("Select id from PaymentBillInfo where customerid = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "' and BuildingId= '" + Func.ParseString(Session["__BUILDINGID__"]) + "'");

            if (!(yearmonth.Equals(DateTime.Now.ToString("yyyyMM")) || yearmonth.Equals((DateTime.Now.AddMonths(-1).ToString("yyyyMM")))))
            {
                mvMessage.AddError("Chỉ thực hiện được trong tháng hoặc tháng trước");
                return;
            }

            mvMessage.CheckRequired(txtBillDate, "Ngày xuất Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtBillNo, "Số Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchange, "Tỉ giá USD-VN là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchangeDate, "Ngày tỉ giá là danh mục bắt buộc");

            string lsYearmonth = "";
            foreach (ListItem lstItem in lstSelectedYearMonth.Items)
            {
                lsYearmonth += ",'" + lstItem.Value + "'";
            }
            if (String.IsNullOrEmpty(lsYearmonth))
            {
                mvMessage.AddError("Phải chọn ít nhất 1 tháng");
                return;
            }
            lsYearmonth = lsYearmonth.Substring(1) + ",'" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";

            if (!mvMessage.IsValid) return;

            if (String.IsNullOrEmpty(hidBillId.Value))
            {
                //Get and Insert Data
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetInsertObject(data);
                data.ModifiedBy = Page.User.Identity.Name;
                data.CreatedBy = Page.User.Identity.Name;
                data.Created = DateTime.Now.ToString("yyyyMMddHHmmss");
                data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss");
                data.DelFlag = "0";

                data.BuildingId = Func.ParseString(Session["__BUILDINGID__"]);
                data.CustomerId = lblCustomerId.Text.Trim();
                data.YearMonth = drpYear.SelectedValue + drpMonth.SelectedValue;
                data.BillDate = Func.FormatYYYYmmdd(txtBillDate.Text.Trim());
                data.BillNo = txtBillNo.Text.Trim();
                data.UsdExchangeDate = Func.FormatYYYYmmdd(txtUsdExchangeDate.Text.Trim());
                data.UsdExchange = txtUsdExchange.Text.Trim();
                data.YearMonths = lsYearmonth;

                Execute(tran);

                if (!HasError)
                {
                    OperationLogger.WriteInfo(Constants.LogOperationAlbumId, Constants.LogActionInsertId, addSuccess, Page.User.Identity.Name);
                    mvMessage.SetCompleteMessage(addSuccess);
                    hidBillId.Value = data.id;
                }
                else
                {
                    OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionInsertId, addUnSuccess, Page.User.Identity.Name);
                    mvMessage.AddError(addUnSuccess);
                }
            }
            else
            {
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetLoadObject(data, hidBillId.Value);
                Execute(tran);
                if (!HasError)
                {
                    //Get Data
                    data = (PaymentBillInfoData)tran.Result;
                    data.ModifiedBy = Page.User.Identity.Name;
                    data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss");
                    data.DelFlag = "0";
                    id = data.id;

                    data.BuildingId = Func.ParseString(Session["__BUILDINGID__"]);
                    data.BillDate = Func.FormatYYYYmmdd(txtBillDate.Text.Trim());
                    data.BillNo = txtBillNo.Text.Trim();
                    data.UsdExchangeDate = Func.FormatYYYYmmdd(Func.FormatYYYYmmdd(txtUsdExchangeDate.Text.Substring(0, 10)));
                    data.UsdExchange = txtUsdExchange.Text.Trim();
                    data.YearMonths = lsYearmonth;
                    tran = factory.GetUpdateObject(data);

                    Execute(tran);

                    if (!HasError)
                    {
                        OperationLogger.WriteInfo(Constants.LogOperationAlbumId, Constants.LogActionUpdateId, addSuccess, Page.User.Identity.Name);
                        mvMessage.SetCompleteMessage(addSuccess);
                    }
                    else
                    {
                        OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionUpdateId, addUnSuccess, Page.User.Identity.Name);
                        mvMessage.AddError(addUnSuccess);
                    }
                }
            }
            ShowData();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string id = "";
            string yearmonth = drpYear.SelectedValue + drpMonth.SelectedValue;
            hidBillId.Value = DbHelper.GetScalar("Select id from PaymentBillInfo where customerid = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "' and BuildingId= '" + Func.ParseString(Session["__BUILDINGID__"]) + "'");

            if (!(yearmonth.Equals(DateTime.Now.ToString("yyyyMM")) || yearmonth.Equals((DateTime.Now.AddMonths(-1).ToString("yyyyMM")))))
            {
                mvMessage.AddError("Chỉ thực hiện được trong tháng hoặc tháng trước");
                return;
            }

            mvMessage.CheckRequired(txtBillDate, "Ngày xuất Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtBillNo, "Số Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchange, "Tỉ giá USD-VN là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchangeDate, "Ngày tỉ giá là danh mục bắt buộc");

            string lsYearmonth = "";
            foreach (ListItem lstItem in lstSelectedYearMonth.Items)
            {
                lsYearmonth += ",'" + lstItem.Value + "'";
            }
            if (String.IsNullOrEmpty(lsYearmonth))
            {
                mvMessage.AddError("Phải chọn ít nhất 1 tháng");
                return;
            }
            lsYearmonth = lsYearmonth.Substring(1) + ",'" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";

            if (!mvMessage.IsValid) return;

            if (String.IsNullOrEmpty(hidBillId.Value))
            {
                //Get and Insert Data
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetInsertObject(data);
                data.ModifiedBy = Page.User.Identity.Name;
                data.CreatedBy = Page.User.Identity.Name;
                data.Created = DateTime.Now.ToString("yyyyMMddHHmmss");
                data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss");
                data.DelFlag = "0";

                data.BuildingId = Func.ParseString(Session["__BUILDINGID__"]);
                data.CustomerId = lblCustomerId.Text.Trim();
                data.YearMonth = drpYear.SelectedValue + drpMonth.SelectedValue;
                data.BillDate = Func.FormatYYYYmmdd(txtBillDate.Text.Trim());
                data.BillNo = txtBillNo.Text.Trim();
                data.UsdExchangeDate = Func.FormatYYYYmmdd(txtUsdExchangeDate.Text.Trim());
                data.UsdExchange = txtUsdExchange.Text.Trim();
                data.YearMonths = lsYearmonth;

                Execute(tran);

                if (!HasError)
                {
                    OperationLogger.WriteInfo(Constants.LogOperationAlbumId, Constants.LogActionInsertId, addSuccess, Page.User.Identity.Name);
                    mvMessage.SetCompleteMessage(addSuccess);
                    hidBillId.Value = data.id;

                    using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
                    {
                        con.Open();
                        using (SqlCommand cm = new SqlCommand("sp_PaymentDetailOneCustomer", con))
                        {
                            try
                            {
                                cm.CommandType = CommandType.StoredProcedure;
                                cm.Parameters.AddWithValue("@BuildingId", data.BuildingId);
                                cm.Parameters.AddWithValue("@CustomerId", data.CustomerId);
                                cm.Parameters.AddWithValue("@YearMonth", data.YearMonth);
                                cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name);
                                cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name);

                                cm.CommandTimeout = 9999;

                                int ret = cm.ExecuteNonQuery();
                            }
                            catch (Exception ex)
                            {
                                ApplicationLog.WriteError(ex);
                            }
                            finally
                            {
                                con.Close();
                            }
                        }
                    }

                    foreach (ListItem lstItem in lstSelectedYearMonth.Items)
                    {
                        if (String.Compare(DateTime.Now.ToString("yyyyMMdd"), lstItem.Value) < 0)
                        {
                            using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
                            {
                                con.Open();
                                using (SqlCommand cm = new SqlCommand("sp_PaymentDetailOneCustomerRentManager", con))
                                {
                                    try
                                    {
                                        cm.CommandType = CommandType.StoredProcedure;
                                        cm.Parameters.AddWithValue("@BuildingId", Func.ParseString(Session["__BUILDINGID__"]));
                                        cm.Parameters.AddWithValue("@CustomerId", lblCustomerId.Text);
                                        cm.Parameters.AddWithValue("@YearMonth", lstItem.Value);
                                        cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                        cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name);
                                        cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                        cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name);

                                        cm.CommandTimeout = 9999;
                                        int ret = cm.ExecuteNonQuery();
                                    }
                                    catch (Exception ex)
                                    {
                                        ApplicationLog.WriteError(ex);
                                    }
                                    finally
                                    {
                                        con.Close();
                                    }
                                }
                            }
                        }
                    }

                }
                else
                {
                    OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionInsertId, addUnSuccess, Page.User.Identity.Name);
                    mvMessage.AddError(addUnSuccess);
                }
            }
            else
            {
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetLoadObject(data, hidBillId.Value);
                Execute(tran);
                if (!HasError)
                {
                    //Get Data
                    data = (PaymentBillInfoData)tran.Result;
                    data.ModifiedBy = Page.User.Identity.Name;
                    data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss");
                    data.DelFlag = "0";
                    id = data.id;

                    data.BuildingId = Func.ParseString(Session["__BUILDINGID__"]);
                    data.BillDate = Func.FormatYYYYmmdd(txtBillDate.Text.Trim());
                    data.BillNo = txtBillNo.Text.Trim();
                    data.UsdExchangeDate = Func.FormatYYYYmmdd(Func.FormatYYYYmmdd(txtUsdExchangeDate.Text.Substring(0, 10)));
                    data.UsdExchange = txtUsdExchange.Text.Trim();
                    data.YearMonths = lsYearmonth;
                    tran = factory.GetUpdateObject(data);

                    Execute(tran);

                    if (!HasError)
                    {
                        OperationLogger.WriteInfo(Constants.LogOperationAlbumId, Constants.LogActionUpdateId, addSuccess, Page.User.Identity.Name);
                        mvMessage.SetCompleteMessage(addSuccess);

                        using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
                        {
                            con.Open();
                            using (SqlCommand cm = new SqlCommand("sp_PaymentDetailOneCustomer", con))
                            {
                                try
                                {
                                    cm.CommandType = CommandType.StoredProcedure;
                                    cm.Parameters.AddWithValue("@BuildingId", data.BuildingId);
                                    cm.Parameters.AddWithValue("@CustomerId", data.CustomerId);
                                    cm.Parameters.AddWithValue("@YearMonth", data.YearMonth);
                                    cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                    cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name);
                                    cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                    cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name);

                                    cm.CommandTimeout = 9999;

                                    int ret = cm.ExecuteNonQuery();
                                }
                                catch (Exception ex)
                                {
                                    ApplicationLog.WriteError(ex);
                                }
                                finally
                                {
                                    con.Close();
                                }
                            }
                        }
                        foreach (ListItem lstItem in lstSelectedYearMonth.Items)
                        {
                            if (String.Compare(DateTime.Now.ToString("yyyyMMdd"), lstItem.Value) < 0)
                            {
                                using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
                                {
                                    con.Open();
                                    using (SqlCommand cm = new SqlCommand("sp_PaymentDetailOneCustomerRentManager", con))
                                    {
                                        try
                                        {
                                            cm.CommandType = CommandType.StoredProcedure;
                                            cm.Parameters.AddWithValue("@BuildingId", Func.ParseString(Session["__BUILDINGID__"]));
                                            cm.Parameters.AddWithValue("@CustomerId", lblCustomerId.Text);
                                            cm.Parameters.AddWithValue("@YearMonth", lstItem.Value);
                                            cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                            cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name);
                                            cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss"));
                                            cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name);

                                            cm.CommandTimeout = 9999;
                                            int ret = cm.ExecuteNonQuery();
                                        }
                                        catch (Exception ex)
                                        {
                                            ApplicationLog.WriteError(ex);
                                        }
                                        finally
                                        {
                                            con.Close();
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionUpdateId, addUnSuccess, Page.User.Identity.Name);
                        mvMessage.AddError(addUnSuccess);
                    }
                }
            }
            ShowData();
        }
        /// <summary>
        /// List data
        /// </summary>
        private void ShowData(string YearMonth)
        {
            hidBillId.Value = DbHelper.GetScalar("Select id from PaymentBillInfo where customerid = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "' and BuildingId= '" + Func.ParseString(Session["__BUILDINGID__"]) + "'");

            if (!String.IsNullOrEmpty(hidBillId.Value))
            {
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetLoadObject(data, hidBillId.Value);
                Execute(tran);
                if (!HasError)
                {
                    data = (PaymentBillInfoData)tran.Result;

                    txtBillNo.Text = data.BillNo;
                    txtBillDate.Text = data.BillDate;
                    txtUsdExchangeDate.Text = Func.FormatDMY(data.UsdExchangeDate);
                    txtUsdExchange.Text = Func.ParseString(Func.ParseFloat(data.UsdExchange));
                }

                btnCreate.Text = "Tính lại tiền";
                //divDetail.Visible = true;
            }
            else
            {
                txtBillNo.Text = "";
                txtBillDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
                txtUsdExchangeDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
                txtUsdExchange.Text = "";

                btnCreate.Text = "Tạo Hóa Đơn";
                //divDetail.Visible = false;
            }

            SqlDatabase db = new SqlDatabase();
            string sql = string.Empty;
            if (!Func.IsValid(ListSortExpression))
            {
                ListSortExpression = "Name";
                ListSortDirection = SortDirection.Descending;
            }
            try
            {
                //Rent And Manager Price
                sql = string.Empty;
                string sort = ListSortExpression + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " Select *";
                sql += " FROM PaymentRoom";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";

                SqlCommand cm = db.CreateCommand(sql);
                SqlDataAdapter da = new SqlDataAdapter(cm);
                DataSet ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptRoomRent.DataSource = ds.Tables[0].DefaultView;
                rptRoomRent.DataBind();

                rptRoomManager.DataSource = ds.Tables[0].DefaultView;
                rptRoomManager.DataBind();

                //Parking
                sql = string.Empty;
                sort = "TariffsParkingName" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND";
                sql += "        , SUM(LastPriceUSD) AS LastPriceUSD";
                sql += " FROM         dbo.PaymentParking";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
                sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat";

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptParking.DataSource = ds.Tables[0].DefaultView;
                rptParking.DataBind();

                //Extra Time
                sql = string.Empty;
                sort = "WorkingDate" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT * ";
                sql += " FROM   PaymentExtraTime";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptExtraTime.DataSource = ds.Tables[0].DefaultView;
                rptExtraTime.DataBind();

                //Elec
                ListSortDirection = SortDirection.Ascending;
                sql = string.Empty;
                sort = "B.FromIndex" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT BD_Room.Name as RoomName, A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId INNER JOIN";
                sql += "        BD_Room ON A.RoomId = BD_Room.id";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0  and A.YearMonth = '" + YearMonth + "'";
                sql += " Order by " + sort;

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptElec.DataSource = ds.Tables[0].DefaultView;
                rptElec.DataBind();

                //Water
                sql = string.Empty;

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT BD_Room.Name as RoomName, A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId INNER JOIN";
                sql += "        BD_Room ON A.RoomId = BD_Room.id";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth = '" + YearMonth + "'";
                sql += " Order by " + sort;

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptWater.DataSource = ds.Tables[0].DefaultView;
                rptWater.DataBind();

                //Service
                sql = string.Empty;
                sort = "ServiceDate" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT * ";
                sql += " FROM   PaymentService";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptService.DataSource = ds.Tables[0].DefaultView;
                rptService.DataBind();

                //Dept
                sql = string.Empty;
                sort = "YearMonth" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                //////sql += " SELECT *,(RemainRentUSD+RemainManagerUSD+RemainElecUSD+RemainWaterUSD+RemainServiceUSD+RemainParkingUSD+RemainExtraTimePriceUSD) as SumUSD,(RemainRentVND+RemainManagerVND+RemainElecVND+RemainWaterVND+RemainServiceVND+RemainParkingVND+RemainExtraTimePriceVND) AS SumVND ";
                //////sql += " FROM   v_PaymentYearMonthDept";
                //////sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' And";
                //////sql += " (RemainRentUSD+RemainManagerUSD+RemainElecUSD+RemainWaterUSD+RemainServiceUSD+RemainParkingUSD+RemainExtraTimePriceUSD)>0 and YearMonth <> '" + YearMonth + "'";

                //////cm = db.CreateCommand(sql);
                //////da = new SqlDataAdapter(cm);
                //////ds = new DataSet();
                //////da.Fill(ds);
                //////db.Close();
                //////rptDept.DataSource = ds.Tables[0].DefaultView;
                //////rptDept.DataBind();

                //DataTable dt = new DataTable();
                /////Get Sum money
                /////
                ////Rent And Manager Price
                //sql = string.Empty;
                //sql += " Select sum(LastRentSumVND),sum(LastRentSumUSD),sum(LastManagerSumVND),sum(LastManagerSumUSD)";
                //sql += " FROM PaymentRoom";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblRentUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblRentVND.Text =  Func.FormatNumber(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get

                //    lblMangagerUSD.Text = dt.Rows[0][2].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblMangagerVND.Text =  Func.FormatNumber(dt.Rows[0][3].ToString(); // Where Fieldname is the name of fields from your database that you want to get

                //}

                ////Parking
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM  PaymentParking";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
                //sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblParkingUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblParkingVND.Text =  Func.FormatNumber(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Extra Time
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM   PaymentExtraTime";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblExtraTimeUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblExtraTimeVND.Text =  Func.FormatNumber(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Elec
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM   PaymentElecWater";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0 and YearMonth = '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblElecUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblElecVND.Text =  Func.FormatNumber(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Water
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM   PaymentElecWater ";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and YearMonth = '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblWaterUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblWaterVND.Text =  Func.FormatNumber(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Service
                //sql = string.Empty;
                //sql += " SELECT SUM(LastPriceVND) AS LastPriceVND, SUM(LastPriceUSD) AS LastPriceUSD";
                //sql += " FROM   PaymentService";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                //if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
                //{
                //    lblServiceUSD.Text = dt.Rows[0][0].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //    lblServiceVND.Text =  Func.FormatNumber(dt.Rows[0][1].ToString(); // Where Fieldname is the name of fields from your database that you want to get
                //}
                ////Dept
                //sql = string.Empty;
                //sql += " SELECT sum(RemainRentUSD+RemainManagerUSD+RemainElecUSD+RemainWaterUSD+RemainServiceUSD+RemainParkingUSD+RemainExtraTimePriceUSD) as SumUSD,sum(RemainRentVND+RemainManagerVND+RemainElecVND+RemainWaterVND+RemainServiceVND+RemainParkingVND+RemainExtraTimePriceVND) AS SumVND ";
                //sql += " FROM   v_PaymentYearMonthDept";
                //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' And";
                //sql += " (RemainRentUSD+RemainManagerUSD+RemainElecUSD+RemainWaterUSD+RemainServiceUSD+RemainParkingUSD+RemainExtraTimePriceUSD)>0 and YearMonth <> '" + YearMonth + "'";
                //dt = DbHelper.GetDataTable(sql);
                sql = "Select  *";
                sql += " From    PaymentBillDetail";
                sql += " Where   BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'";
                DataTable dt = DbHelper.GetDataTable(sql);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string PaymentType = Func.ParseString(dt.Rows[i]["PaymentType"]);
                    string MoneyUSD = Func.ParseString(dt.Rows[i]["MoneyUSD"]);
                    string MoneyVND = Func.ParseString(dt.Rows[i]["MoneyVND"]);
                    string PaidUSD = Func.ParseString(dt.Rows[i]["PaidUSD"]);
                    string PaidVND = Func.ParseString(dt.Rows[i]["PaidVND"]);
                    string ExchangeType = Func.ParseString(dt.Rows[i]["ExchangeType"]);
                    string UsdExchange = Func.ParseString(dt.Rows[i]["UsdExchange"]);

                    float tmpUSD = Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD);
                    float tmpVND = Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND);

                    switch (PaymentType)
                    {
                        case "1":
                            //Rent
                            lblRentUSD.Text = MoneyUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblRentVND.Text = Func.FormatNumber(Func.ParseFloat(MoneyVND)); // Where Fieldname is the name of fields from your database that you want to get

                            lblRentPaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblRentPaidVND.Text = Func.FormatNumber(Func.ParseFloat(PaidVND)); // Where Fieldname is the name of fields from your database that you want to get

                            txtRentPaidUSD.Text = Func.FormatNumber(tmpUSD);
                            txtRentPaidVND.Text = Func.FormatNumber(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtRentPaidUSD.Text = Func.FormatDecimal2(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtRentPaidVND.Text = Func.FormatDecimal2(tmpVND);
                            }
                            //if (!String.IsNullOrEmpty(ExchangeType))
                            //{
                            //    rdoRentPaidUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoRentPaidVND.Checked = "1".Equals(ExchangeType) ? true : false;

                            //    rdoRentUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoRentVND.Checked = "1".Equals(ExchangeType) ? true : false;
                            //}
                            break;
                        case "2":
                            //Manager
                            lblMangagerUSD.Text = MoneyUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblMangagerVND.Text = Func.FormatNumber(Func.ParseFloat(MoneyVND)); // Where Fieldname is the name of fields from your database that you want to get

                            lblMangagerPaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblMangagerPaidVND.Text = Func.FormatNumber(Func.ParseFloat(PaidVND)); // Where Fieldname is the name of fields from your database that you want to get

                            //txtManagerPaidUSD.Text = Func.ParseString(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            //txtManagerPaidVND.Text = Func.FormatDecimal(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND), 0);

                            txtManagerPaidUSD.Text = Func.FormatNumber(tmpUSD);
                            txtManagerPaidVND.Text = Func.FormatNumber(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtManagerPaidUSD.Text = Func.FormatDecimal2(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtManagerPaidVND.Text = Func.FormatDecimal2(tmpVND);
                            }

                            //if (!String.IsNullOrEmpty(ExchangeType))
                            //{
                            //    rdoManagerPaidUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoManagerPaidVND.Checked = "1".Equals(ExchangeType) ? true : false;

                            //    rdoManagerUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoManagerVND.Checked = "1".Equals(ExchangeType) ? true : false;
                            //}
                            break;
                        case "3":
                            //Parking
                            lblParkingUSD.Text = MoneyUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblParkingVND.Text = Func.FormatNumber(Func.ParseFloat(MoneyVND)); // Where Fieldname is the name of fields from your database that you want to get

                            lblParkingPaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblParkingPaidVND.Text = Func.FormatNumber(Func.ParseFloat(PaidVND)); // Where Fieldname is the name of fields from your database that you want to get

                            txtParkingPaidUSD.Text = Func.ParseString(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtParkingPaidVND.Text = Func.FormatDecimal(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND), 0);
                            //if (!String.IsNullOrEmpty(ExchangeType))
                            //{
                            //    //0:USD; 1:VND
                            //    rdoParkingPaidUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoParkingPaidVND.Checked = "1".Equals(ExchangeType) ? true : false;

                            //    rdoParkingUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoParkingVND.Checked = "1".Equals(ExchangeType) ? true : false;
                            //}
                            txtParkingPaidUSD.Text = Func.FormatNumber(tmpUSD);
                            txtParkingPaidVND.Text = Func.FormatNumber(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtParkingPaidUSD.Text = Func.FormatDecimal2(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtParkingPaidVND.Text = Func.FormatDecimal2(tmpVND);
                            }
                            break;
                        case "4":
                            lblExtraTimeUSD.Text = MoneyUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblExtraTimeVND.Text = Func.FormatNumber(Func.ParseFloat(MoneyVND)); // Where Fieldname is the name of fields from your database that you want to get

                            lblExtraTimePaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblExtraTimePaidVND.Text = Func.FormatNumber(Func.ParseFloat(PaidVND)); // Where Fieldname is the name of fields from your database that you want to get

                            txtExtraTimePaidUSD.Text = Func.ParseString(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtExtraTimePaidVND.Text = Func.FormatDecimal(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND), 0);
                            //if (!String.IsNullOrEmpty(ExchangeType))
                            //{
                            //    rdoExtraTimePaidUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoExtraTimePaidVND.Checked = "1".Equals(ExchangeType) ? true : false;

                            //    rdoExtraTimeUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoExtraTimeVND.Checked = "1".Equals(ExchangeType) ? true : false;
                            //}
                            txtExtraTimePaidUSD.Text = Func.FormatNumber(tmpUSD);
                            txtExtraTimePaidVND.Text = Func.FormatNumber(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtExtraTimePaidUSD.Text = Func.FormatDecimal2(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtExtraTimePaidVND.Text = Func.FormatDecimal2(tmpVND);
                            }
                            break;
                        case "5":
                            lblElecUSD.Text = MoneyUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblElecVND.Text = Func.FormatNumber(Func.ParseFloat(MoneyVND)); // Where Fieldname is the name of fields from your database that you want to get

                            lblElecPaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblElecPaidVND.Text = Func.FormatNumber(Func.ParseFloat(PaidVND)); // Where Fieldname is the name of fields from your database that you want to get

                            txtElecPaidUSD.Text = Func.ParseString(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtElecPaidVND.Text = Func.FormatDecimal(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND), 0);
                            //if (!String.IsNullOrEmpty(ExchangeType))
                            //{
                            //    rdoElecPaidUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoElecPaidVND.Checked = "1".Equals(ExchangeType) ? true : false;

                            //    rdoElecUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoElecVND.Checked = "1".Equals(ExchangeType) ? true : false;
                            //}
                            txtElecPaidUSD.Text = Func.FormatNumber(tmpUSD);
                            txtElecPaidVND.Text = Func.FormatNumber(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtElecPaidUSD.Text = Func.FormatDecimal2(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtElecPaidVND.Text = Func.FormatDecimal2(tmpVND);
                            }
                            break;
                        case "6":
                            lblWaterUSD.Text = MoneyUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblWaterVND.Text = Func.FormatNumber(Func.ParseFloat(MoneyVND)); // Where Fieldname is the name of fields from your database that you want to get

                            lblWaterPaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblWaterPaidVND.Text = Func.FormatNumber(Func.ParseFloat(PaidVND)); // Where Fieldname is the name of fields from your database that you want to get

                            txtWaterPaidUSD.Text = Func.ParseString(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtWaterPaidVND.Text = Func.FormatNumber(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND));
                            //if (!String.IsNullOrEmpty(ExchangeType))
                            //{
                            //    rdoWaterPaidUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoWaterPaidVND.Checked = "1".Equals(ExchangeType) ? true : false;

                            //    rdoWaterUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoWaterVND.Checked = "1".Equals(ExchangeType) ? true : false;
                            //}
                            txtWaterPaidUSD.Text = Func.FormatNumber(tmpUSD);
                            txtWaterPaidVND.Text = Func.FormatNumber(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtWaterPaidUSD.Text = Func.FormatDecimal2(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtWaterPaidVND.Text = Func.FormatDecimal2(tmpVND);
                            }
                            break;
                        case "7":
                            lblServiceUSD.Text = MoneyUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblServiceVND.Text = Func.FormatNumber(Func.ParseFloat(MoneyVND)); // Where Fieldname is the name of fields from your database that you want to get

                            lblServicePaidUSD.Text = PaidUSD; // Where Fieldname is the name of fields from your database that you want to get
                            lblServicePaidVND.Text = Func.FormatNumber(Func.ParseFloat(PaidVND)); // Where Fieldname is the name of fields from your database that you want to get

                            txtServicePaidUSD.Text = Func.ParseString(Func.ParseFloat(MoneyUSD) - Func.ParseFloat(PaidUSD));
                            txtServicePaidVND.Text = Func.FormatNumber(Func.ParseFloat(MoneyVND) - Func.ParseFloat(PaidVND));
                            //if (!String.IsNullOrEmpty(ExchangeType))
                            //{
                            //    rdoServicePaidUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoServicePaidVND.Checked = "1".Equals(ExchangeType) ? true : false;

                            //    rdoServiceUSD.Checked = "0".Equals(ExchangeType) ? true : false;
                            //    rdoServiceVND.Checked = "1".Equals(ExchangeType) ? true : false;
                            //}
                            txtServicePaidUSD.Text = Func.FormatNumber(tmpUSD);
                            txtServicePaidVND.Text = Func.FormatNumber(tmpVND);

                            if (tmpUSD > 0)
                            {
                                txtServicePaidUSD.Text = Func.FormatDecimal2(tmpUSD);
                            }
                            if (tmpVND > 0)
                            {
                                txtServicePaidVND.Text = Func.FormatDecimal2(tmpVND);
                            }
                            break;
                        default:
                            break;
                    }
                }
                //string yearMonthID = DbHelper.GetScalar("Select Id from PaymentYearMonth Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + YearMonth + "'");
                //if (!String.IsNullOrEmpty(yearMonthID))
                //{

                //    PaymentYearMonthData data = new PaymentYearMonthData();
                //    ITransaction tran = factory.GetLoadObject(data, yearMonthID);
                //    Execute(tran);
                //    if (!HasError)
                //    {
                //        //Get Data
                //        data = (PaymentYearMonthData)tran.Result;
                //        //Rent
                //        lblRentUSD.Text = data.RentUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblRentVND.Text = Func.FormatNumber(Func.ParseFloat(data.RentVND)); // Where Fieldname is the name of fields from your database that you want to get
                //        //Manager
                //        lblMangagerUSD.Text = data.ManagerUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblMangagerVND.Text = Func.FormatNumber(Func.ParseFloat(data.ManagerVND)); // Where Fieldname is the name of fields from your database that you want to get

                //        //Parking
                //        lblParkingUSD.Text = data.ParkingUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblParkingVND.Text = Func.FormatNumber(Func.ParseFloat(data.ParkingVND)); // Where Fieldname is the name of fields from your database that you want to get
                //        //Extra Time
                //        lblExtraTimeUSD.Text = data.ExtraTimePriceUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblExtraTimeVND.Text = Func.FormatNumber(Func.ParseFloat(data.ExtraTimePriceVND)); // Where Fieldname is the name of fields from your database that you want to get
                //        //Elec
                //        lblElecUSD.Text = data.ElectUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblElecVND.Text = Func.FormatNumber(Func.ParseFloat(data.ElecVND)); // Where Fieldname is the name of fields from your database that you want to get
                //        //Water
                //        lblWaterUSD.Text = data.WaterUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblWaterVND.Text = Func.FormatNumber(Func.ParseFloat(data.WaterVND)); // Where Fieldname is the name of fields from your database that you want to get
                //        //Service
                //        lblServiceUSD.Text = data.ServiceUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblServiceVND.Text = Func.FormatNumber(Func.ParseFloat(data.ServiceVND)); // Where Fieldname is the name of fields from your database that you want to get
                //        /////////
                //        //Rent
                //        lblRentPaidUSD.Text = data.PaidRentUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblRentPaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.PaidRentVND)); // Where Fieldname is the name of fields from your database that you want to get
                //        //Manager
                //        lblMangagerPaidUSD.Text = data.PaidManagerUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblMangagerPaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.PaidManagerVND)); // Where Fieldname is the name of fields from your database that you want to get

                //        //Parking
                //        lblParkingPaidUSD.Text = data.PaidParkingUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblParkingPaidVND.Text = Func.FormatNumber(data.PaidParkingVND); // Where Fieldname is the name of fields from your database that you want to get
                //        //Extra Time
                //        lblExtraTimePaidUSD.Text = data.PaidExtraTimePriceUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblExtraTimePaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.PaidExtraTimePriceVND)); // Where Fieldname is the name of fields from your database that you want to get
                //        //Elec
                //        lblElecPaidUSD.Text = data.PaidElectUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblElecPaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.PaidElecVND)); // Where Fieldname is the name of fields from your database that you want to get
                //        //Water
                //        lblWaterPaidUSD.Text = data.PaidWaterUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblWaterPaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.PaidWaterVND));// Where Fieldname is the name of fields from your database that you want to get
                //        //Service
                //        lblServicePaidUSD.Text = data.PaidServiceUSD; // Where Fieldname is the name of fields from your database that you want to get
                //        lblServicePaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.PaidServiceVND)); // Where Fieldname is the name of fields from your database that you want to get

                //        txtRentPaidUSD.Text = Func.ParseString(Func.ParseFloat(data.RentUSD) - Func.ParseFloat(data.PaidRentUSD));
                //        txtRentPaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.RentVND) - Func.ParseFloat(data.PaidRentVND));
                //        //Manager	=		//Manager	)-			//Manager
                //        txtManagerPaidUSD.Text = Func.ParseString(Func.ParseFloat(data.ManagerUSD) - Func.ParseFloat(data.PaidManagerUSD));
                //        txtManagerPaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.ManagerVND) - Func.ParseFloat(data.PaidManagerVND));
                //        //Parking	=		//Parking	)-			//Parking
                //        txtParkingPaidUSD.Text = Func.ParseString(Func.ParseFloat(data.ParkingUSD) - Func.ParseFloat(data.PaidParkingUSD));
                //        txtParkingPaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.ParkingVND) - Func.ParseFloat(data.PaidParkingVND));
                //        //ExtraTime	=		//ExtraTime	)-			//ExtraTime
                //        txtExtraTimePaidUSD.Text = Func.ParseString(Func.ParseFloat(data.ExtraTimePriceUSD) - Func.ParseFloat(data.PaidExtraTimePriceUSD));
                //        txtExtraTimePaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.ExtraTimePriceVND) - Func.ParseFloat(data.PaidExtraTimePriceVND));
                //        //Elec	=		//Elec	)-			//Elec
                //        txtElecPaidUSD.Text = Func.ParseString(Func.ParseFloat(data.ElectUSD) - Func.ParseFloat(data.PaidElectUSD));
                //        txtElecPaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.ElecVND) - Func.ParseFloat(data.PaidElecVND));
                //        //Water	=		//Water	)-			//Water
                //        txtWaterPaidUSD.Text = Func.ParseString(Func.ParseFloat(data.WaterUSD) - Func.ParseFloat(data.PaidWaterUSD));
                //        txtWaterPaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.WaterVND) - Func.ParseFloat(data.PaidWaterVND));
                //        //Service	=		//Service	)-			//Service
                //        txtServicePaidUSD.Text = Func.ParseString(Func.ParseFloat(data.ServiceUSD) - Func.ParseFloat(data.PaidServiceUSD));
                //        txtServicePaidVND.Text = Func.FormatNumber(Func.ParseFloat(data.ServiceVND) - Func.ParseFloat(data.PaidServiceVND));
                //    }
                //}
            }
            catch (Exception ex)
            {
                ApplicationLog.WriteError(ex);
            }
        }
예제 #6
0
        /// <summary>
        /// List data
        /// </summary>
        private void ShowData(string YearMonth)
        {
            if (!String.IsNullOrEmpty(hidId.Value))
            {
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetLoadObject(data, hidId.Value);
                Execute(tran);
                if (!HasError)
                {
                    data = (PaymentBillInfoData)tran.Result;

                    lblBillNo.Text = data.BillNo;
                    lblBillDate.Text = data.BillDate;
                    lblUsdExchangeDate.Text = Func.FormatDMY(data.UsdExchangeDate);
                    lblUsdExchange.Text = Func.ParseString(Func.ParseFloat(data.UsdExchange));
                }
            }
            else
            {
                lblBillNo.Text = "";
                lblBillDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
                lblUsdExchangeDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
                lblUsdExchange.Text = "";
            }

            SqlDatabase db = new SqlDatabase();
            string sql = string.Empty;
            if (!Func.IsValid(ListSortExpression))
            {
                ListSortExpression = "Name";
                ListSortDirection = SortDirection.Descending;
            }
            try
            {
                //Rent And Manager Price
                sql = string.Empty;
                string sort = ListSortExpression + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " Select *";
                sql += " FROM PaymentRoom";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and YearMonth in (" + YearMonth + ")";

                SqlCommand cm = db.CreateCommand(sql);
                SqlDataAdapter da = new SqlDataAdapter(cm);
                DataSet ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptRoomRent.DataSource = ds.Tables[0].DefaultView;
                rptRoomRent.DataBind();

                rptRoomManager.DataSource = ds.Tables[0].DefaultView;
                rptRoomManager.DataBind();

                //Parking
                sql = string.Empty;
                sort = "TariffsParkingName" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVnd, PriceUsd, SUM(VatVnd) AS VatVnd,SUM(VatUsd) AS VatUsd, SUM(SumVnd) AS SumVnd, SUM(SumUsd) AS SumUsd, SUM(LastPriceVnd) AS LastPriceVnd";
                sql += "        , SUM(LastPriceUsd) AS LastPriceUsd";
                sql += " FROM         dbo.PaymentParking";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and YearMonth in (" + YearMonth + ")";
                sql += " GROUP BY YearMonth, TariffsParkingName, PriceVnd, PriceUsd, Vat, daysParking";

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptParking.DataSource = ds.Tables[0].DefaultView;
                rptParking.DataBind();

                //Extra Time
                sql = string.Empty;
                sort = "WorkingDate" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT * ";
                sql += " FROM   PaymentExtraTime";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and YearMonth in (" + YearMonth + ")";

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptExtraTime.DataSource = ds.Tables[0].DefaultView;
                rptExtraTime.DataBind();

                //Elec
                ListSortDirection = SortDirection.Ascending;
                sql = string.Empty;
                sort = "B.FromIndex" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT BD_Room.Name as RoomName, A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVnd, B.PriceUsd, B.SumVnd, B.SumUsd, ";
                sql += "        B.VatVnd, B.VatUsd, B.LastPriceVnd, B.LastPriceUsd, B.Name,B.WaterPricePercent,B.ElecPricePercent ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId INNER JOIN";
                sql += "        BD_Room ON A.RoomId = BD_Room.id";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0  and A.YearMonth = '" + YearMonth + "' and B.DetailType = 1";
                sql += " Order by " + sort;

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptElec.DataSource = ds.Tables[0].DefaultView;
                rptElec.DataBind();

                //Water
                sql = string.Empty;

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT BD_Room.Name as RoomName, A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVnd, B.PriceUsd, B.SumVnd, B.SumUsd, ";
                sql += "        B.VatVnd, B.VatUsd, B.LastPriceVnd, B.LastPriceUsd, B.Name,B.WaterPricePercent,B.ElecPricePercent ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId INNER JOIN";
                sql += "        BD_Room ON A.RoomId = BD_Room.id";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth = '" + YearMonth + "' and B.DetailType = 2";
                sql += " Order by " + sort;

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptWater.DataSource = ds.Tables[0].DefaultView;
                rptWater.DataBind();

                //Service
                sql = string.Empty;
                sort = "ServiceDate" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //Xuất ra toàn bộ nội dung theo Trang
                sql += " SELECT * ";
                sql += " FROM   PaymentService";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and YearMonth in (" + YearMonth + ")";

                cm = db.CreateCommand(sql);
                da = new SqlDataAdapter(cm);
                ds = new DataSet();
                da.Fill(ds);
                db.Close();
                rptService.DataSource = ds.Tables[0].DefaultView;
                rptService.DataBind();

                //Dept
                sql = string.Empty;
                sort = "YearMonth" + " " + (ListSortDirection == SortDirection.Ascending ? " asc " : " desc ");

                //sql = "Select  *";
                //sql += " From    PaymentBillDetail";
                //sql += " Where   BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and YearMonth in (" + YearMonth + ")";

                sql = "  Select  SUM(MoneyUSD) AS MoneyUSD, SUM(MoneyVND) AS MoneyVND, SUM(PaidUSD) AS PaidUSD, SUM(PaidVND) AS PaidVND, PaymentType";
                sql += " From    PaymentBillDetail";
                sql += " Where   BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + YearMonth + ")";
                sql += " GROUP BY PaymentType";

                DataTable dt = DbHelper.GetDataTable(sql);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string PaymentType = Func.ParseString(dt.Rows[i]["PaymentType"]);
                    string MoneyUsd = Func.ParseString(dt.Rows[i]["MoneyUsd"]);
                    string MoneyVnd = Func.ParseString(dt.Rows[i]["MoneyVnd"]);
                    string PaidUsd = Func.ParseString(dt.Rows[i]["PaidUsd"]);
                    string PaidVnd = Func.ParseString(dt.Rows[i]["PaidVnd"]);
                    string ExchangeType = Func.ParseString(dt.Rows[i]["ExchangeType"]);
                    //string UsdExchange = Func.ParseString(dt.Rows[i]["UsdExchange"]);

                    decimal tmpUsd = Convert.ToDecimal(MoneyUsd) - Convert.ToDecimal(PaidUsd);
                    decimal tmpVnd = Convert.ToDecimal(MoneyVnd) - Convert.ToDecimal(PaidVnd);

                    switch (PaymentType)
                    {
                        case "1":
                            //Rent
                            lblRentUsd.Text = Func.FormatNumber_New(MoneyUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblRentVnd.Text = Func.FormatNumber_New(MoneyVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblRentPaidUsd.Text = Func.FormatNumber_New(PaidUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblRentPaidVnd.Text = Func.FormatNumber_New(PaidVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblRentPaidUsdRemain.Text = Func.FormatNumber_New(tmpUsd);
                            lblRentPaidVndRemain.Text = Func.FormatNumber_New(tmpVnd);

                            if (tmpUsd > 0)
                            {
                                lblRentPaidUsd.Text = Func.FormatNumber_New(tmpUsd);
                            }
                            if (tmpVnd > 0)
                            {
                                lblRentPaidVnd.Text = Func.FormatNumber_New(tmpVnd);
                            }
                            break;
                        case "2":
                            //Manager
                            lblManagerUsd.Text = Func.FormatNumber_New(MoneyUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblManagerVnd.Text = Func.FormatNumber_New(MoneyVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblManagerPaidUsd.Text = Func.FormatNumber_New(PaidUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblManagerPaidVnd.Text = Func.FormatNumber_New(PaidVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblManagerPaidUsdRemain.Text = Func.FormatNumber_New(tmpUsd);
                            lblManagerPaidVndRemain.Text = Func.FormatNumber_New(tmpVnd);

                            if (tmpUsd > 0)
                            {
                                lblManagerPaidUsd.Text = Func.FormatNumber_New(tmpUsd);
                            }
                            if (tmpVnd > 0)
                            {
                                lblManagerPaidVnd.Text = Func.FormatNumber_New(tmpVnd);
                            }

                            break;
                        case "3":
                            //Parking
                            lblParkingUsd.Text = Func.FormatNumber_New(MoneyUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblParkingVnd.Text = Func.FormatNumber_New(MoneyVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblParkingPaidUsd.Text = Func.FormatNumber_New(PaidUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblParkingPaidVnd.Text = Func.FormatNumber_New(PaidVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblParkingPaidUsd.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUsd) - Func.ParseFloat(PaidUsd));
                            lblParkingPaidVnd.Text = Func.FormatNumber_New(Func.ParseDouble(MoneyVnd) - Func.ParseFloat(PaidVnd));

                            lblParkingPaidUsdRemain.Text = Func.FormatNumber_New(tmpUsd);
                            lblParkingPaidVndRemain.Text = Func.FormatNumber_New(tmpVnd);

                            if (tmpUsd > 0)
                            {
                                lblParkingPaidUsd.Text = Func.FormatNumber_New(tmpUsd);
                            }
                            if (tmpVnd > 0)
                            {
                                lblParkingPaidVnd.Text = Func.FormatNumber_New(tmpVnd);
                            }
                            break;
                        case "4":
                            lblExtraTimeUsd.Text = Func.FormatNumber_New(MoneyUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblExtraTimeVnd.Text = Func.FormatNumber_New(MoneyVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblExtraTimePaidUsd.Text = Func.FormatNumber_New(PaidUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblExtraTimePaidVnd.Text = Func.FormatNumber_New(PaidVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblExtraTimePaidUsd.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUsd) - Func.ParseFloat(PaidUsd));
                            lblExtraTimePaidVnd.Text = Func.FormatNumber_New(Func.ParseDouble(MoneyVnd) - Func.ParseFloat(PaidVnd));

                            lblExtraTimePaidUsdRemain.Text = Func.FormatNumber_New(tmpUsd);
                            lblExtraTimePaidVndRemain.Text = Func.FormatNumber_New(tmpVnd);

                            if (tmpUsd > 0)
                            {
                                lblExtraTimePaidUsd.Text = Func.FormatNumber_New(tmpUsd);
                            }
                            if (tmpVnd > 0)
                            {
                                lblExtraTimePaidVnd.Text = Func.FormatNumber_New(tmpVnd);
                            }
                            break;
                        case "5":
                            lblElecVnd.Text = Func.FormatNumber_New(MoneyVnd); // Where Fieldname is the name of fields from your database that you want to get
                            lblElecPaidVnd.Text = Func.FormatNumber_New(PaidVnd); // Where Fieldname is the name of fields from your database that you want to get
                            lblElecPaidVnd.Text = Func.FormatNumber_New(Func.ParseDouble(MoneyVnd) - Func.ParseFloat(PaidVnd));
                            lblElecPaidVndRemain.Text = Func.FormatNumber_New(tmpVnd);
                            if (tmpVnd > 0)
                            {
                                lblElecPaidVnd.Text = Func.FormatNumber_New(tmpVnd);
                            }
                            break;
                        case "6":
                            lblWaterVnd.Text = Func.FormatNumber_New(MoneyVnd); // Where Fieldname is the name of fields from your database that you want to get
                            lblWaterPaidVnd.Text = Func.FormatNumber_New(PaidVnd); // Where Fieldname is the name of fields from your database that you want to get

                            //lblWaterPaidUsd.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyUsd) - Func.ParseFloat(PaidUsd));
                            lblWaterPaidVnd.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyVnd) - Func.ParseFloat(PaidVnd));

                            //lblWaterPaidUsd.Text = Func.FormatNumber_New(tmpUsd);
                            lblWaterPaidVndRemain.Text = Func.FormatNumber_New(tmpVnd);

                            //if (tmpUsd > 0)
                            //{
                            //    lblWaterPaidUsd.Text = Func.FormatNumber_New(tmpUsd);
                            //}
                            if (tmpVnd > 0)
                            {
                                lblWaterPaidVnd.Text = Func.FormatNumber_New(tmpVnd);
                            }
                            break;
                        case "7":
                            lblServiceUsd.Text = Func.FormatNumber_New(MoneyUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblServiceVnd.Text = Func.FormatNumber_New(MoneyVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblServicePaidUsd.Text = Func.FormatNumber_New(PaidUsd); // Where Fieldname is the name of fields from your database that you want to get
                            lblServicePaidVnd.Text = Func.FormatNumber_New(PaidVnd); // Where Fieldname is the name of fields from your database that you want to get

                            lblServicePaidUsd.Text = Func.ParseString(Func.ParseFloat(MoneyUsd) - Func.ParseFloat(PaidUsd));
                            lblServicePaidVnd.Text = Func.FormatNumber_New(Func.ParseFloat(MoneyVnd) - Func.ParseFloat(PaidVnd));

                            lblServicePaidUsdRemain.Text = Func.FormatNumber_New(tmpUsd);
                            lblServicePaidVndRemain.Text = Func.FormatNumber_New(tmpVnd);

                            if (tmpUsd > 0)
                            {
                                lblServicePaidUsd.Text = Func.FormatNumber_New(tmpUsd);
                            }
                            if (tmpVnd > 0)
                            {
                                lblServicePaidVnd.Text = Func.FormatNumber_New(tmpVnd);
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.WriteError(ex);
            }
        }
예제 #7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(hidBillId.Value))
            {
                //Get and Insert Data
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetInsertObject(data);
                data.ModifiedBy = Page.User.Identity.Name;
                data.CreatedBy = Page.User.Identity.Name;
                data.Created = DateTime.Now.ToString("yyyyMMddHHmmss");
                data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss");
                data.DelFlag = "0";

                data.BuildingId = Func.ParseString(Session["__BUILDINGID__"]);
                data.CustomerId = txtCustomerId.Text.Trim();
                data.YearMonth = hidYearMonth.Value;
                data.Name = txtName.Text.Trim();
                data.ContactName = txtContactName.Text.Trim();
                data.Bank = txtBank.Text.Trim();
                data.Account = txtAccount.Text.Trim();
                data.AccountName = txtAccountName.Text.Trim();
                data.Office = txtOffice.Text.Trim();
                data.OfficePhone = txtOfficePhone.Text.Trim();
                data.BillDate = txtBillDate.Text.Trim();
                data.UsdExchangeDate = Func.FormatYYYYmmdd(txtUsdExchangeDate.Text.Trim());
                data.UsdExchange = txtUsdExchange.Text.Trim();

                Execute(tran);

                if (!HasError)
                {
                    OperationLogger.WriteInfo(Constants.LogOperationAlbumId, Constants.LogActionInsertId, addSuccess, Page.User.Identity.Name);
                    mvMessage.SetCompleteMessage(addSuccess);

                    using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
                    {
                        con.Open();
                        using (SqlCommand cm = new SqlCommand("sp_PaymentDetail", con))
                        {
                            try
                            {
                                cm.CommandType = CommandType.StoredProcedure;
                                cm.Parameters.AddWithValue("@BuildingId", data.BuildingId);
                                cm.Parameters.AddWithValue("@CustomerId", data.CustomerId);
                                cm.Parameters.AddWithValue("@YearMonth", data.YearMonth);
                                cm.Parameters.AddWithValue("@rent", rdoRentPaidUSD.Checked == true ? "0" : "1");
                                cm.Parameters.AddWithValue("@manager", rdoManagerPaidUSD.Checked == true ? "0" : "1");
                                cm.Parameters.AddWithValue("@parking", rdoParkingPaidUSD.Checked == true ? "0" : "1");
                                cm.Parameters.AddWithValue("@extratime", rdoExtraTimePaidUSD.Checked == true ? "0" : "1");
                                cm.Parameters.AddWithValue("@elec", rdoElecPaidUSD.Checked == true ? "0" : "1");
                                cm.Parameters.AddWithValue("@water", rdoWaterPaidUSD.Checked == true ? "0" : "1");
                                cm.Parameters.AddWithValue("@service", rdoServicePaidUSD.Checked == true ? "0" : "1");

                                cm.CommandTimeout = 9999;

                                int ret = cm.ExecuteNonQuery();
                            }
                            catch (Exception ex)
                            {
                                ApplicationLog.WriteError(ex);
                            }
                            finally
                            {
                                con.Close();
                            }
                        }
                    }

                    ScriptManager.RegisterClientScriptBlock(this.btnSave, this.GetType(), key, postback, true);
                }
                else
                {
                    OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionInsertId, addUnSuccess, Page.User.Identity.Name);
                    mvMessage.AddError(addUnSuccess);
                }
            }
            else
            {
                PaymentBillInfoData data = new PaymentBillInfoData();
                ITransaction tran = factory.GetLoadObject(data, hidBillId.Value);
                Execute(tran);
                if (!HasError)
                {
                    //Get Data
                    data = (PaymentBillInfoData)tran.Result;
                    data.ModifiedBy = Page.User.Identity.Name;
                    data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss");
                    data.DelFlag = "0";

                    data.BuildingId = Func.ParseString(Session["__BUILDINGID__"]);
                    data.CustomerId = txtCustomerId.Text.Trim();
                    data.YearMonth = hidYearMonth.Value;
                    data.Name = txtName.Text.Trim();
                    data.ContactName = txtContactName.Text.Trim();
                    data.Bank = txtBank.Text.Trim();
                    data.Account = txtAccount.Text.Trim();
                    data.AccountName = txtAccountName.Text.Trim();
                    data.Office = txtOffice.Text.Trim();
                    data.OfficePhone = txtOfficePhone.Text.Trim();
                    data.BillDate = txtBillDate.Text.Trim();
                    data.UsdExchangeDate = Func.FormatYYYYmmdd(Func.FormatYYYYmmdd(txtUsdExchangeDate.Text.Substring(0, 10)));
                    data.UsdExchange = txtUsdExchange.Text.Trim();

                    tran = factory.GetUpdateObject(data);

                    Execute(tran);

                    if (!HasError)
                    {
                        OperationLogger.WriteInfo(Constants.LogOperationAlbumId, Constants.LogActionUpdateId, updateSuccess, Page.User.Identity.Name);
                        mvMessage.SetCompleteMessage(updateSuccess);

                        using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
                        {
                            con.Open();
                            using (SqlCommand cm = new SqlCommand("sp_PaymentDetail", con))
                            {
                                try
                                {
                                    cm.CommandType = CommandType.StoredProcedure;
                                    cm.Parameters.AddWithValue("@BuildingId", data.BuildingId);
                                    cm.Parameters.AddWithValue("@CustomerId", data.CustomerId);
                                    cm.Parameters.AddWithValue("@YearMonth", data.YearMonth);
                                    cm.Parameters.AddWithValue("@rent", rdoRentPaidUSD.Checked == true ? "0" : "1");
                                    cm.Parameters.AddWithValue("@manager", rdoManagerPaidUSD.Checked == true ? "0" : "1");
                                    cm.Parameters.AddWithValue("@parking", rdoParkingPaidUSD.Checked == true ? "0" : "1");
                                    cm.Parameters.AddWithValue("@extratime", rdoExtraTimePaidUSD.Checked == true ? "0" : "1");
                                    cm.Parameters.AddWithValue("@elec", rdoElecPaidUSD.Checked == true ? "0" : "1");
                                    cm.Parameters.AddWithValue("@water", rdoWaterPaidUSD.Checked == true ? "0" : "1");
                                    cm.Parameters.AddWithValue("@service", rdoServicePaidUSD.Checked == true ? "0" : "1");

                                    cm.CommandTimeout = 9999;

                                    int ret = cm.ExecuteNonQuery();
                                }
                                catch (Exception ex)
                                {
                                    ApplicationLog.WriteError(ex);
                                }
                                finally
                                {
                                    con.Close();
                                }
                            }
                        }
                    }
                    else
                    {
                        OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionUpdateId, updateUnSuccess, Page.User.Identity.Name);
                        mvMessage.AddError(updateUnSuccess);
                    }
                }
            }
        }
예제 #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            hidId.Value = Func.ParseString(Request["id"]);
            hidYearMonth.Value = Func.ParseString(Request["yearmonth"]);

            if (!IsPostBack)
            {
                txtCustomerId.Text = hidId.Value;
                hidBillId.Value = DbHelper.GetScalar("Select id from PaymentBillInfo where customerid = '" + hidId.Value + "' and YearMonth = '" + hidYearMonth.Value + "' and BuildingId= '" + Func.ParseString(Session["__BUILDINGID__"]) + "'");
                if (Func.ParseInt(hidBillId.Value) > 0)
                {
                    PaymentBillInfoData data = new PaymentBillInfoData();
                    ITransaction tran = factory.GetLoadObject(data, hidBillId.Value);
                    Execute(tran);
                    if (!HasError)
                    {
                        data = (PaymentBillInfoData)tran.Result;
                        txtName.Text = data.Name;
                        txtContactName.Text = data.ContactName;
                        txtBank.Text = data.Bank;
                        txtAccount.Text = data.Account;
                        txtAccountName.Text = data.AccountName;
                        txtOffice.Text = data.Office;
                        txtOfficePhone.Text = data.OfficePhone;
                        txtBillDate.Text = data.BillDate;
                        txtUsdExchangeDate.Text = Func.FormatDMY(data.UsdExchangeDate);
                        txtUsdExchange.Text = data.UsdExchange;
                    }
                }

                if (String.IsNullOrEmpty(hidBillId.Value))
                {
                    CustomerData data = new CustomerData();
                    ITransaction tran = factory.GetLoadObject(data, hidId.Value);
                    Execute(tran);
                    if (!HasError)
                    {
                        //Get Data
                        data = (CustomerData)tran.Result;
                        txtCustomerId.Text = data.CustomerId;
                        txtName.Text = data.Name;
                        //txtComment.Text = data.Comment;
                        txtContactName.Text = data.ContactName;
                    }

                    Mst_BuildingData dataB = new Mst_BuildingData();
                    ITransaction tranB = factory.GetLoadObject(dataB, Func.ParseString(Session["__BUILDINGID__"]));
                    Execute(tranB);
                    if (!HasError)
                    {
                        //Get Data
                        dataB = (Mst_BuildingData)tranB.Result;
                        txtBank.Text = dataB.Bank;
                        txtAccount.Text = dataB.Account;
                        txtAccountName.Text = dataB.AccountName;
                        txtOffice.Text = dataB.Office;
                        txtOfficePhone.Text = dataB.OfficePhone;
                    }
                }
            }
        }