public USDDetailWindow(int Type, USDDetail ud = null, int usID = -1, int sID = -1)
        {
            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            InitializeComponent();
            this.type = Type;
            this.usID = usID;
            this.sID  = sID;
            if (ud != null)
            {
                this.USDetail = ud;
            }
            else
            {
                this.USDetail = new USDDetail();
            }

            this.DataContext = this.bindingUSDetail;
            if (type == EDITACTION)
            {
                switchToEditAction();
            }
            else if (type == ADDACTION)
            {
                switchToAddAction();
            }
            else
            {
                switchToInfoAction();
            }
            //this.DialogResult = false;
        }
        private void btnDeleteUSDDetails_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new RoomManagerEntities2())
                {
                    this.IsEnabled = false;
                    var screen = new ConfirmWindow($"Ban Co Chac Muon Xoa USDetail {USDetail.usID} {USDetail.sID} {USDetail.times}");
                    screen.ShowDialog();
                    if (screen.DialogResult == true)
                    {
                        var deleteItem = new USDDetail {
                            usID = USDetail.usID, sID = USDetail.sID, times = USDetail.times
                        };
                        db.USDDetails.Attach(deleteItem);
                        db.USDDetails.Remove(deleteItem);
                        db.SaveChanges();
                        //var oldRoom = db.Rooms.SingleOrDefault(b => b.Id == this.USDDetails.roomID);
                        //oldRoom.Status = 1;

                        //db.SaveChanges();
                        this.Close();
                    }
                    this.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                this.IsEnabled = true;
                MessageBox.Show("delete failure");
                switchToInfoAction();
            }
        }
 public void setDataToForm(USDDetail ud)
 {
     tbxUsID.Text  = ud.usID.ToString();
     tbxSID.Text   = ud.sID.ToString();
     tbxTimes.Text = ud.times.ToString();
     tbxPrice.Text = ud.price.ToString();
     //var dateString = ud.date.ToString();
     dpDate.SelectedDate = ud.date;
 }
        public USDDetail getDataFromForm()
        {
            USDDetail result = new USDDetail();

            //result.id = ;// int.Parse( tbxID.Text);
            result.usID  = int.Parse(tbxUsID.Text);
            result.sID   = int.Parse(tbxSID.Text);
            result.times = int.Parse(tbxTimes.Text);

            result.price = float.Parse(tbxPrice.Text);
            result.date  = dpDate.SelectedDate.Value;
            return(result);
        }
        //used services info detail
        private void dgUSDDetails_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            USDDetail ud = dgUSDDetails.SelectedItem as USDDetail;

            if (ud != null)
            {
                var screen = new USDDetailWindow(USDDetailWindow.INFOACTION, ud);
                this.IsEnabled = false;
                screen.ShowDialog();

                this.IsEnabled = true;
            }
            switchToInfoAction();
        }
        public void switchToInfoAction()
        {
            type                        = INFOACTION;
            lbTitle.Content             = "Info USDetail";
            spUSDDetailsInfo.Visibility = Visibility.Visible;
            spUSDDetailsAE.Visibility   = Visibility.Collapsed;

            //data
            if (type == INFOACTION)
            {
                USDDetail ud = getUSDDetailFromData(USDetail.usID, USDetail.sID, USDetail.times);
                tbUsID.Text  = ud.usID.ToString();
                tbSID.Text   = ud.sID.ToString();
                tbTimes.Text = ud.times.ToString();
                tbPrice.Text = ud.price.ToString();
                //var dateString = ud.date.ToString();
                tbDate.Text = ud.date.ToString();
            }
        }
        private void btnDeleteUsedServices_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new RoomManagerEntities2())
                {
                    this.IsEnabled = false;
                    var screen = new ConfirmWindow($"Ban Co Chac Muon Xoa Used Services {UsedServices.id}");
                    screen.ShowDialog();
                    if (screen.DialogResult == true)
                    {
                        var deleteItem = new UsedService()
                        {
                            id = UsedServices.id
                        };
                        var deleteDetailItem = new USDDetail()
                        {
                            usID = UsedServices.id
                        };
                        db.Entry(deleteDetailItem).State = EntityState.Modified;
                        db.USDDetails.Attach(deleteDetailItem);
                        db.USDDetails.Remove(deleteDetailItem);
                        db.SaveChanges();
                        switchToInfoAction();
                        //db.UsedServices.Attach(deleteItem);
                        //db.UsedServices.Remove(deleteItem);


                        //db.SaveChanges();
                        //this.Close();
                    }
                    this.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                this.IsEnabled = true;
                MessageBox.Show("delete failure");
                switchToInfoAction();
            }
        }
Exemple #8
0
        private void btnImportUsedServices_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                var wookbook = new Workbook(openFileDialog.FileName);
                var tabs     = wookbook.Worksheets;
                using (var db = new RoomManagerEntities2())
                {
                    foreach (var tab in tabs)
                    {
                        try
                        {
                            if (tab.Name == "Services")
                            {
                                var col  = 'B';
                                var row  = 2;
                                var cell = tab.Cells[$"{ col}{ row}"];
                                while (cell.Value != null)
                                {
                                    var newUService = new UsedService()
                                    {
                                        rentRoomID = tab.Cells[$"B{row}"].IntValue,

                                        date   = tab.Cells[$"C{row}"].DateTimeValue,
                                        status = tab.Cells[$"D{row}"].IntValue,
                                    };
                                    db.UsedServices.Add(newUService);

                                    db.SaveChanges();

                                    row++;
                                    cell = tab.Cells[$"{ col}{ row}"];
                                }
                                LoadServicesData();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    foreach (var tab in tabs)
                    {
                        try
                        {
                            if (tab.Name == "USDDetails")
                            {
                                var col  = 'B';
                                var row  = 2;
                                var cell = tab.Cells[$"{ col}{ row}"];
                                while (cell.Value != null)
                                {
                                    var newUSDDetail = new USDDetail()
                                    {
                                        usID  = tab.Cells[$"B{row}"].IntValue,
                                        sID   = tab.Cells[$"C{row}"].IntValue,
                                        times = tab.Cells[$"D{row}"].IntValue,
                                        price = tab.Cells[$"E{row}"].DoubleValue,
                                        date  = tab.Cells[$"F{row}"].DateTimeValue,
                                    };
                                    db.USDDetails
                                    .Add(newUSDDetail);

                                    db.SaveChanges();

                                    row++;
                                    cell = tab.Cells[$"{ col}{ row}"];
                                }
                                LoadServicesData();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }