Ejemplo n.º 1
0
        private void SaveDataToDatabase()
        {
            if (!checkData())
            {
                return;
            }
            if (roomSelectsDataTable.Rows.Count <= 0)
            {
                XtraCustomMessageBox.Show("Bạn chưa chọn phòng!", "Thông báo", false, 4);
                return;
            }
            try
            {
                if (m_IsAdd)
                {
                    String   customerID     = lkCustomer.EditValue.ToString();
                    String   staffID        = "NV000001";//Utils.standardNamePerson(frmHomePage.staffLogin.StaffID);
                    DateTime orderOfDate    = DateTime.Now;
                    int      numberOfPeople = (int)spinTotalPeople.Value;
                    int      estimate       = (int)spintotalEstimate.Value;
                    int      deposit        = (int)spinDeposit.Value;
                    int      total          = 0;
                    int      orderStatus    = (int)ORDERSTATUS.UNPAID;
                    dtoOrder = new DTOOrder("DP0000000",
                                            customerID,
                                            staffID,
                                            orderOfDate,
                                            numberOfPeople,
                                            estimate,
                                            deposit,
                                            total,
                                            orderStatus);

                    if (orderBUS.InsertOrder(dtoOrder))
                    {
                        //XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true, 1);
                        String   orderMaxID     = orderBUS.GetOrderMaxID();
                        DateTime dateStartValue = dateStart.DateTime;
                        DateTime dateEndValue   = dateEnd.DateTime;
                        String   roomID         = "";
                        int      estimateValue  = 0;
                        int      serviceMoney   = 0;
                        foreach (DataRow row in roomSelectsDataTable.Rows)
                        {
                            roomID = row["RoomID"].ToString();
                            try
                            {
                                estimateValue = int.Parse(row["Monetized"].ToString().Trim());
                            }
                            catch (Exception)
                            {
                                estimateValue = 0;
                                throw;
                            }
                            serviceMoney = 0;

                            DTOOrderDetail dtoOderDetail = new DTOOrderDetail("CDP0000000",
                                                                              orderMaxID,
                                                                              roomID,
                                                                              dateStartValue,
                                                                              dateEndValue,
                                                                              estimateValue,
                                                                              serviceMoney);
                            if (!orderDetailBUS.InsertOrderDetails(dtoOderDetail))
                            {
                                //Khi them chi tiet that bai
                                //Xoa du lieu hien tai
                                orderDetailBUS.DeleteOrderDetails(orderMaxID);
                                orderBUS.DeteleOrder(orderMaxID);
                                XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true, 4);

                                return;
                            }
                        }
                        //Update button view
                        btnChangeToView.Enabled = true;
                        XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true, 1);
                    }
                    else
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true, 4);
                    }
                }
                else
                {
                    String   orderID        = "";
                    String   customerID     = lkCustomer.EditValue.ToString();
                    String   staffID        = "NV000001";// frmHomePage.staffLogin.StaffID;
                    DateTime orderOfDate    = DateTime.Now;
                    int      numberOfPeople = (int)spinTotalPeople.Value;
                    int      estimate       = (int)spintotalEstimate.Value;
                    int      deposit        = (int)spinDeposit.Value;
                    int      total          = estimate;
                    int      orderStatus    = (int)ORDERSTATUS.UNPAID;
                    dtoOrder = new DTOOrder(orderID,
                                            customerID,
                                            staffID,
                                            orderOfDate,
                                            numberOfPeople,
                                            estimate,
                                            deposit,
                                            total,
                                            orderStatus);

                    if (orderBUS.UpdateOrder(dtoOrder))
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true, 1);
                    }
                    else
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true, 4);
                    }
                }
            }
            catch (System.Exception ex)
            {
                XtraCustomMessageBox.Show(ex.ToString(), "Lỗi", true, 3);
            }
            finally
            {
                updateEnableButtonAndResetValueOfControl(ref btnSave);
            }
        }
Ejemplo n.º 2
0
        private void SaveDataToDatabase()
        {
            if (!checkData())
            {
                return;
            }
            if (roomSelectsDataTable.Rows.Count <= 0)
            {
                XtraCustomMessageBox.Show("Bạn chưa chọn phòng!", "Thông báo", false, 4);
                return;
            }
            try
            {
                if (m_IsAdd)
                {
                    String customerID = lkCustomer.EditValue.ToString();
                    String staffID = "NV000001";//Utils.standardNamePerson(frmHomePage.staffLogin.StaffID);
                    DateTime orderOfDate = DateTime.Now;
                    int numberOfPeople = (int)spinTotalPeople.Value;
                    int estimate = (int)spintotalEstimate.Value;
                    int deposit = (int)spinDeposit.Value;
                    int total = 0;
                    int orderStatus = (int)ORDERSTATUS.UNPAID;
                    dtoOrder = new DTOOrder("DP0000000",
                                            customerID,
                                            staffID,
                                            orderOfDate,
                                            numberOfPeople,
                                            estimate,
                                            deposit,
                                            total,
                                            orderStatus);

                    if (orderBUS.InsertOrder(dtoOrder))
                    {
                        //XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true, 1);
                        String orderMaxID = orderBUS.GetOrderMaxID();
                        DateTime dateStartValue = dateStart.DateTime;
                        DateTime dateEndValue = dateEnd.DateTime;
                        String roomID = "";
                        int estimateValue = 0;
                        int serviceMoney = 0;
                        foreach (DataRow row in roomSelectsDataTable.Rows)
                        {
                            roomID = row["RoomID"].ToString();
                            try
                            {
                                estimateValue = int.Parse(row["Monetized"].ToString().Trim());
                            }
                            catch (Exception)
                            {
                                estimateValue = 0;
                                throw;
                            }
                            serviceMoney = 0;

                            DTOOrderDetail dtoOderDetail = new DTOOrderDetail("CDP0000000",
                                                                                orderMaxID,
                                                                                roomID,
                                                                                dateStartValue,
                                                                                dateEndValue,
                                                                                estimateValue,
                                                                                serviceMoney);
                            if (!orderDetailBUS.InsertOrderDetails(dtoOderDetail))
                            {
                                //Khi them chi tiet that bai
                                //Xoa du lieu hien tai
                                orderDetailBUS.DeleteOrderDetails(orderMaxID);
                                orderBUS.DeteleOrder(orderMaxID);
                                XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true, 4);

                                return;
                            }
                        }
                        //Update button view
                        btnChangeToView.Enabled = true;
                        XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true, 1);
                    }
                    else
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true, 4);
                    }
                }
                else
                {
                    String orderID = "";
                    String customerID = lkCustomer.EditValue.ToString();
                    String staffID = "NV000001";// frmHomePage.staffLogin.StaffID;
                    DateTime orderOfDate = DateTime.Now;
                    int numberOfPeople = (int)spinTotalPeople.Value;
                    int estimate = (int)spintotalEstimate.Value;
                    int deposit = (int)spinDeposit.Value;
                    int total = estimate;
                    int orderStatus = (int)ORDERSTATUS.UNPAID;
                    dtoOrder = new DTOOrder(orderID,
                                            customerID,
                                            staffID,
                                            orderOfDate,
                                            numberOfPeople,
                                            estimate,
                                            deposit,
                                            total,
                                            orderStatus);

                    if (orderBUS.UpdateOrder(dtoOrder))
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true, 1);
                    }
                    else
                    {
                        XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true, 4);
                    }
                }

            }
            catch (System.Exception ex)
            {
                XtraCustomMessageBox.Show(ex.ToString(), "Lỗi", true, 3);
            }
            finally
            {
                updateEnableButtonAndResetValueOfControl(ref btnSave);
            }
        }