public void Auto_edit() { var waybill = Fixture <LocalWaybill>().Waybill; WpfTestHelper.WithWindow2(async w => { var model = new WaybillDetails(waybill.Id); var view = (WaybillDetailsView)Bind(model); w.Content = view; var grid = view.Descendants <DataGrid>().First(g => g.Name == "Lines"); await grid.WaitLoaded(); Assert.IsNotNull(grid.CellStyle); grid.SelectedItem = waybill.Lines[0]; grid.RaiseEvent(WpfTestHelper.TextArgs("1")); var column = grid.Columns.First(c => c.Header is TextBlock && ((TextBlock)c.Header).Text.Equals("Розничная наценка")); var cell = DataGridHelper.GetCell( (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.CurrentCell.Item), column, grid.Columns); Assert.IsTrue(cell.IsEditing); Assert.AreEqual("1", ((TextBox)cell.Content).Text); }); WpfTestHelper.CleanSafeError(); }
private void dataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { if (dataGrid.SelectedCells.Count == 0) { return; } Colhead = dataGrid.SelectedCells[0].Column.Header.ToString(); if (dataGrid.CurrentItem == null) { return; } SelectItem = this.dataGrid.CurrentItem as Test; RowIndex = dataGrid.Items.IndexOf(dataGrid.SelectedCells[0].Item); ColIndex = dataGrid.Columns.IndexOf(dataGrid.SelectedCells[0].Column); if (ColIndex < 0) { ColIndex = 0; } dataGrid.BeginEdit(); Cell = DataGridHelper.GetCell(dataGrid, RowIndex, ColIndex); //ppp.PlacementTarget = Cell; //ppp.IsOpen = false; //ppp.IsOpen = true; }
public void AddItemCallbackObatBeli(int id, string nama, int biayabeli) { dgObat.ItemsSource = null; rekapInkaso.Add(new InkasoObat { ID = id, QTY = 1, NamaObat = nama, HargaBeli = biayabeli }); dgObat.ItemsSource = rekapInkaso; dgObat.UpdateLayout(); double totalSub = 0; for (int x = 0; x < dgObat.Items.Count; x++) { DataGridCell cell = DataGridHelper.GetCell(dgObat, x, 4); TextBlock tb = cell.Content as TextBlock; totalSub += double.Parse(tb.Text); } txtSubTotal.Text = totalSub.ToString(); }
private void dgObat_BeginningEdit(object sender, DataGridBeginningEditEventArgs e) { DataGridCell cell = DataGridHelper.GetCell(dgObat, dgObat.SelectedIndex, 2); TextBlock tb = cell.Content as TextBlock; tempStokEdit = int.Parse(tb.Text); //MessageBox.Show(value); }
private void SelectNext(int row = -1, int Col = -1) { if (row == -1 || Col == -1) { if (dataGrid.CurrentItem == null) { return; } row = dataGrid.Items.IndexOf(dataGrid.CurrentItem); Col = dataGrid.Columns.IndexOf(dataGrid.CurrentColumn); if (dataGrid.CurrentCell.Column.Header.ToString() == "服务") { RowIndex = row + 1; ColIndex = 0; } else { RowIndex = row; ColIndex = Col + 1; } } else { RowIndex = row; ColIndex = Col; } if (dataGrid.Items.Count - 1 <= row) { AddNewRow(); } Cell = DataGridHelper.GetCell(dataGrid, RowIndex, ColIndex); if (Cell != null) { Cell.IsSelected = true; Cell.Focus(); dataGrid.BeginEdit(); SelectItem = dataGrid.CurrentItem as Test; ppp.PlacementTarget = Cell; ppp.IsOpen = false; ppp.IsOpen = true; } }
private void data_RowEditEnding_1(object sender, DataGridRowEditEndingEventArgs e) { if (e.EditAction == DataGridEditAction.Commit) { if (tabPressed && e.Row.Item == data.Items[data.Items.Count - 2]) { var rowToSelect = data.Items[data.Items.Count - 1]; int rowIndex = data.Items.IndexOf(rowToSelect); this.Dispatcher.BeginInvoke(new DispatcherOperationCallback((param) => { tabPressed = false; var cell = DataGridHelper.GetCell(data, rowIndex, 0); cell.Focus(); data.BeginEdit(); return(null); }), DispatcherPriority.Background, new object[] { null }); } } }
//< SaveAddAllParametrs_Button_Click > -> зберегти всі параметри метрик private void SaveAddAllParametrs_Button_Click(object sender, RoutedEventArgs e) { try { var cel1 = DataGridHelper.GetCell(AllValueParametrs_dataGrid, 0, 1); var content1 = cel1.Content as TextBlock; var parameter1 = content1.Text; mmtMetric.ChangeValue_OfParameter(0, double.Parse(parameter1, CultureInfo.InvariantCulture)); sctMetric.ChangeValue_OfParameter(0, double.Parse(parameter1, CultureInfo.InvariantCulture)); sdtMetric.ChangeValue_OfParameter(0, double.Parse(parameter1, CultureInfo.InvariantCulture)); sqcMetric.ChangeValue_OfParameter(2, double.Parse(parameter1, CultureInfo.InvariantCulture)); var cel2 = DataGridHelper.GetCell(AllValueParametrs_dataGrid, 1, 1); var content2 = cel2.Content as TextBlock; var parameter2 = content2.Text; mmtMetric.ChangeValue_OfParameter(1, double.Parse(parameter2, CultureInfo.InvariantCulture)); sctMetric.ChangeValue_OfParameter(1, double.Parse(parameter2, CultureInfo.InvariantCulture)); sdtMetric.ChangeValue_OfParameter(1, double.Parse(parameter2, CultureInfo.InvariantCulture)); var cel3 = DataGridHelper.GetCell(AllValueParametrs_dataGrid, 2, 1); var content3 = cel3.Content as TextBlock; var parameter3 = content3.Text; mmtMetric.ChangeValue_OfParameter(2, double.Parse(parameter3, CultureInfo.InvariantCulture)); sdtMetric.ChangeValue_OfParameter(2, double.Parse(parameter3, CultureInfo.InvariantCulture)); ((MainWindow)App.MainWin).TableInfoParametrs_MMT_dg.Items.Refresh(); ((MainWindow)App.MainWin).TableInfoParametrs_SCT_dg.Items.Refresh(); ((MainWindow)App.MainWin).TableInfoParametrs_SDT_dg.Items.Refresh(); ((MainWindow)App.MainWin).TableInfoParametrs_SQC_dg.Items.Refresh(); if (MessageBox.Show("Основні параметри метрик успішно внесені та збережені! Продовжіть свою роботу та доповніть метрики необхідними даними!", "Інформація:", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK) { this.Close(); } else { } } catch (Exception exc) { MessageBox.Show("Помилка збереження значень параметрів!" + exc, "Помилка:", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void dgObat_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { dgObat.ItemsSource = null; dgObat.ItemsSource = rekapInkaso; dgObat.UpdateLayout(); double totalSub = 0; for (int x = 0; x < dgObat.Items.Count; x++) { DataGridCell cell = DataGridHelper.GetCell(dgObat, x, 4); TextBlock tb = cell.Content as TextBlock; MessageBox.Show(tb.Text); totalSub += double.Parse(tb.Text); } txtSubTotal.Text = totalSub.ToString(); }
protected override void OnCurrentCellChanged(EventArgs e) { if (this.CurrentCell.Column != null) { if (this.CurrentCell.Column.DisplayIndex == 2) { if (this.CurrentCell.Item.ToString() == "--End Of List--") { this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down)); } } else if (this.CurrentCell.Column != null && this.CurrentCell.Column.DisplayIndex == this.Columns.Count() - 1) { PressKey(Key.Return); DataGridCell cell = DataGridHelper.GetCell(this.CurrentCell); int index = DataGridHelper.GetRowIndex(cell); DataGridRow dgrow = (DataGridRow)this.ItemContainerGenerator.ContainerFromItem(this.Items[index]); dgrow.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)); } } }
private void ShowAndFocus(int index) { if (index < 0) { return; } if (index > Items.Count - 1) { return; } var item = Items[index]; if (item == null) { return; } var row = ItemContainerGenerator.ContainerFromItem(item) as DataGridRow; if (row != null) { row.BringIntoView(); } else { ScrollIntoView(item); } if (CurrentColumn == null) { return; } var cellInfo = new DataGridCellInfo(item, CurrentColumn); var cell = DataGridHelper.GetCell(this, cellInfo); if (cell != null) { cell.Focus(); SelectedItem = item; } }
private static void AttachToCurrentCell(DataGrid grid, CompositeDisposable disposible, TextBox text) { var cell = DataGridHelper.GetCell(grid, grid.CurrentCell); if (cell == null) { return; } IDisposable lostFocusSubscription = null; lostFocusSubscription = Observable.FromEventPattern <RoutedEventArgs>(cell, "LostFocus") .Subscribe(_ => { text.Text = null; if (lostFocusSubscription != null) { disposible.Remove(lostFocusSubscription); lostFocusSubscription.Dispose(); } }); disposible.Add(lostFocusSubscription); }
private void btnHapusObat_Click(object sender, RoutedEventArgs e) { var button = (FrameworkElement)sender; var row = (DataGridRow)button.Tag; MessageBoxResult result = MessageBox.Show("Yakin menghapus item ini?", "Konfirmasi", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { DataObat v = ((DataObat)(dgObat.SelectedItem)); myDataItems.Remove(v); dgObat.ItemsSource = null; int TotalObat = 0; dgObat.ItemsSource = myDataItems; dgObat.UpdateLayout(); for (int x = 0; x < dgObat.Items.Count; x++) { //var row = (DataGridRow)dgObat.ItemContainerGenerator.ContainerFromIndex(x); //DataRowView v = (DataRowView)dgObat.Items[row.GetIndex()]; DataGridCell cell = DataGridHelper.GetCell(dgObat, x, 5); TextBlock tb = cell.Content as TextBlock; ///Console.WriteLine(cell); /// //MessageBox.Show(cell.ToString()); string value = tb.Text.Replace("Rp", "").Replace(".", "").Replace(",00", ""); TotalObat += int.Parse(value); } txtTotalObat.Text = TotalObat.ToString(); decimal TotalGrand = totalTerapi + totalObat; //txtGrandTotal.Text = TotalGrand.ToString(); txtGrandTotal.Text = HitungGrandTotal(Convert.ToDouble(TotalGrand), double.Parse(txtDiskon.Text), double.Parse(txtCard.Text)).ToString(); } }
private void AddItemCallbackAmbilDataObat(int id, int persen, string nama, int biaya) { int TotalObat = 0; dgObat.ItemsSource = null; myDataItems.Add(new DataObat { ID = id, QTY = 1, NamaObat = nama, Biaya = biaya }); //dgObat.Items.Add(new DataObat { QTY = 1, NamaObat = nama, Biaya = biaya }); dgObat.ItemsSource = myDataItems; //DataGridCell cell = DataGridHelper.GetCell(dgObat, 0, 5); //MessageBox.Show(cell.va); //MessageBox.Show(dgObat.Items.Count.ToString()); dgObat.UpdateLayout(); for (int x = 0; x < dgObat.Items.Count; x++) { //var row = (DataGridRow)dgObat.ItemContainerGenerator.ContainerFromIndex(x); //DataRowView v = (DataRowView)dgObat.Items[row.GetIndex()]; DataGridCell cell = DataGridHelper.GetCell(dgObat, x, 5); TextBlock tb = cell.Content as TextBlock; ///Console.WriteLine(cell); /// //MessageBox.Show(cell.ToString()); string value = tb.Text.Replace("Rp", "").Replace(".", "").Replace(",00", ""); //MessageBox.Show(value); TotalObat += int.Parse(value); //Console.WriteLine(tb.Text); } txtTotalObat.Text = TotalObat.ToString(); }
public void Get_cell() { WpfTestHelper.WithWindow2(async w => { var grid = new DataGrid { Columns = { new DataGridTextColumn { DisplayIndex = 1 }, new DataGridTextColumn { DisplayIndex = 0 } }, ItemsSource = new[] { 1, 2 } }; grid.CurrentItem = grid.Items[0]; grid.CurrentCell = new DataGridCellInfo(grid.CurrentItem, grid.Columns[1]); w.Content = grid; await grid.WaitLoaded(); var cell = DataGridHelper.GetCell(grid, grid.CurrentCell); Assert.AreEqual(grid.CurrentItem, cell.DataContext); Assert.AreEqual(grid.Columns[1], cell.Column); }); }
private DataGridCell TryFindCurrentCell() { return(DataGridHelper.GetCell(this, CurrentCell)); }
private void dgObat_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { //Cek Stock Obat try{ koneksi = new cds_MYSQLKonektor(new cds_KoneksiString(SettingHelper.host, SettingHelper.user, SettingHelper.pass, SettingHelper.port), true, System.Data.IsolationLevel.Serializable); // var rows = (DataGridRow)dgObat.ItemContainerGenerator.ContainerFromIndex(dgObat.SelectedIndex); //DataObat v = (DataObat)dgObat.Items[rows.GetIndex()]; DataObat v = ((DataObat)(dgObat.SelectedItem)); int select = dgObat.SelectedIndex; CmbxData = koneksi.GetDataTable("SELECT * FROM mydentist.tbl_obat WHERE mydentist.tbl_obat.id_obat =" + v.ID, null); if (v.QTY > (int)CmbxData.Rows[0]["stok_obat"]) { myDataItems.Remove(v); dgObat.ItemsSource = null; myDataItems.Add(new DataObat { ID = (int)CmbxData.Rows[0]["id_obat"], QTY = tempStokEdit, NamaObat = CmbxData.Rows[0]["nama_obat"].ToString(), Biaya = (int)CmbxData.Rows[0]["hargajual_obat"] }); dgObat.ItemsSource = myDataItems; dgObat.UpdateLayout(); MessageBox.Show("Maaf, stock tidak mencukupi"); int TotalObat = 0; dgObat.UpdateLayout(); for (int x = 0; x < dgObat.Items.Count; x++) { //var row = (DataGridRow)dgObat.ItemContainerGenerator.ContainerFromIndex(x); //DataRowView v = (DataRowView)dgObat.Items[row.GetIndex()]; DataGridCell cell = DataGridHelper.GetCell(dgObat, x, 5); TextBlock tb = cell.Content as TextBlock; ///Console.WriteLine(cell); /// //MessageBox.Show(cell.ToString()); string value = tb.Text.Replace("Rp", "").Replace(".", "").Replace(",00", ""); TotalObat += int.Parse(value); } dgObat.UpdateLayout(); tempStokEdit = 0; txtTotalObat.Text = TotalObat.ToString(); } else { int TotalObat = 0; dgObat.UpdateLayout(); for (int x = 0; x < dgObat.Items.Count; x++) { //var row = (DataGridRow)dgObat.ItemContainerGenerator.ContainerFromIndex(x); //DataRowView v = (DataRowView)dgObat.Items[row.GetIndex()]; DataGridCell cell = DataGridHelper.GetCell(dgObat, x, 5); TextBlock tb = cell.Content as TextBlock; ///Console.WriteLine(cell); /// //MessageBox.Show(cell.ToString()); string value = tb.Text.Replace("Rp", "").Replace(".", "").Replace(",00", ""); TotalObat += int.Parse(value); } txtTotalObat.Text = TotalObat.ToString(); } } catch (Exception ex) { } }