Exemplo n.º 1
0
        public Control GetCellEditor(DataGridColumn column, DataGridRow row, RoutedEventArgs args)
        {
            FrameworkElement     contentPresenter = column.GetCellContent(row);
            Control              editor           = null;
            MouseButtonEventArgs me = args as MouseButtonEventArgs;

            if (me != null)
            {
                HitTestResult result = VisualTreeHelper.HitTest(contentPresenter, me.GetPosition(contentPresenter));
                if (result != null)
                {
                    editor = WpfHelper.FindAncestor <TextBox>(result.VisualHit);
                    if (editor == null)
                    {
                        editor = WpfHelper.FindAncestor <DatePicker>(result.VisualHit);
                        if (editor == null)
                        {
                            editor = WpfHelper.FindAncestor <ComboBox>(result.VisualHit);
                        }
                    }
                }
            }
            else
            {
                // maybe it was the TAB key or something, so we have to find the first TextBox in the new column that we can focus on.
                List <Control> editors = new List <Control>();
                WpfHelper.FindEditableControls(contentPresenter, editors);
                if (editors.Count > 0)
                {
                    editor = editors[0];
                }
            }
            return(editor);
        }
Exemplo n.º 2
0
        public static void SetColumnValue(DataGridRow row, DataGridColumn column, int columnEditorIndex, string value)
        {
            FrameworkElement contentPresenter = column.GetCellContent(row.DataContext);

            if (row.IsEditing)
            {
                List <Control> editors = new List <Control>();
                WpfHelper.FindEditableControls(contentPresenter, editors);
                if (editors.Count > columnEditorIndex)
                {
                    Control editor = editors[columnEditorIndex];
                    TextBox box    = editor as TextBox;
                    if (box != null)
                    {
                        box.Text = value;
                    }
                    ComboBox combo = editor as ComboBox;
                    if (combo != null)
                    {
                        combo.Text = value;
                    }
                    DatePicker picker = editor as DatePicker;
                    if (picker != null)
                    {
                        picker.Text = value;
                    }
                }
            }
            else
            {
                // can't set the text value if itis not being edited
                throw new Exception("Row is not being edited");
            }
        }
Exemplo n.º 3
0
        private void queryDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            if (queryDataGrid.SelectionUnit == DataGridSelectionUnit.Cell)
            {
                foreach (var item in e.AddedCells)
                {
                    DataGridColumn col = item.Column;
                    colTitle = col.Header.ToString();
                    rowIndex = queryDataGrid.Items.IndexOf(queryDataGrid.SelectedCells[0].Item);

                    var cc = col.GetCellContent(item.Item);

                    if (cc is TextBlock)
                    {
                        selectedValue = ((TextBlock)cc).Text;
                    }
                    else if (cc is ComboBox)
                    {
                        selectedValue = ((ComboBox)cc).Text;
                    }
                    else if (cc is DatePicker)
                    {
                        selectedValue = ((DatePicker)cc).Text;
                    }
                }
            }
        }
        private void UpdateCell(Highlight highlight, string columnName)
        {
            DataGridColumn    column            = Columns.FirstOrDefault(c => c.Header.ToString() == columnName);
            TextBlock         cell              = column?.GetCellContent(highlight) as TextBlock;
            BindingExpression bindingExpression = cell?.GetBindingExpression(TextBlock.TextProperty);

            bindingExpression?.UpdateTarget();
        }
        private void OnHighlightCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            DataGridColumn    column            = Columns.FirstOrDefault(c => c.Header.ToString() == columnNameCount);
            TextBlock         cell              = column?.GetCellContent(rows.Keys.FirstOrDefault(f => f.Highlights == sender)) as TextBlock;
            BindingExpression bindingExpression = cell?.GetBindingExpression(TextBlock.TextProperty);

            bindingExpression?.UpdateTarget();
        }
        public static void AddCheckBoxColumnForMultiSelection <T>(this IContentItemProxy gridProxy, ObservableCollection <T> selectedItems) where T : class, IEntityObject
        {
            EventHandler <ControlAvailableEventArgs> gridProxy_ControlAvailable = null;

            gridProxy_ControlAvailable = (s1, e1) =>
            {
                DataGrid dataGrid         = e1.Control as DataGrid;
                var      contentItem      = dataGrid.DataContext as IContentItem;
                var      visualCollection = (contentItem.Value) as IVisualCollection;
                dataGrid.LoadingRow += new EventHandler <DataGridRowEventArgs>((s2, e2) =>
                {
                    DataGridColumn column = dataGrid.Columns[0];
                    var checkBox          = column.GetCellContent(e2.Row) as CheckBox;
                    T currentRowItem      = e2.Row.DataContext as T;
                    if (currentRowItem != null)
                    {
                        checkBox.IsChecked = selectedItems.Contains(currentRowItem);
                    }

                    RoutedEventHandler checkboxClick = null;
                    checkboxClick = (
                        (s3, e3) =>
                    {
                        var selectedItem = dataGrid.SelectedItem as T;
                        if (selectedItem == null)
                        {
                            return;
                        }
                        if (checkBox.IsChecked ?? false)
                        {
                            if (!selectedItems.Contains(selectedItem))
                            {
                                selectedItems.Add(selectedItem);
                            }
                        }
                        else
                        {
                            selectedItems.Remove(selectedItem);
                        }
                        TriggerCanExecute(visualCollection);
                    });
                    checkBox.Click += checkboxClick;
                });

                var col  = new DataGridTemplateColumn();
                var xaml =
                    @"<DataTemplate  xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
                    <CheckBox/>
                </DataTemplate>";
                var dataTemplate = XamlReader.Load(xaml) as DataTemplate;
                col.CellTemplate = dataTemplate;
                dataGrid.Columns.Insert(0, col);

                gridProxy.ControlAvailable -= gridProxy_ControlAvailable;
            };

            gridProxy.ControlAvailable += gridProxy_ControlAvailable;
        }
Exemplo n.º 7
0
        private void OnDoubleClickDataTable(object sender, MouseButtonEventArgs e)
        {
            int iCurRow = cl_DataTable.SelectedIndex;

            if (iCurRow != -1)
            {
                DataGridColumn clDescCol        = cl_DataTable.ColumnFromDisplayIndex(0);
                DataGridColumn clChallanNoCol   = cl_DataTable.ColumnFromDisplayIndex(1);
                DataGridColumn clChallanDateCol = cl_DataTable.ColumnFromDisplayIndex(2);
                DataGridColumn clSACCodeCol     = cl_DataTable.ColumnFromDisplayIndex(3);
                DataGridColumn clQuantityCol    = cl_DataTable.ColumnFromDisplayIndex(4);
                DataGridColumn clRateCol        = cl_DataTable.ColumnFromDisplayIndex(5);
                DataGridColumn clAmountCol      = cl_DataTable.ColumnFromDisplayIndex(6);

                Object clCurItem            = cl_DataTable.Items.GetItemAt(iCurRow);
                var    clDescTextBox        = clDescCol.GetCellContent(clCurItem) as TextBlock;
                var    clChallanNoTextBox   = clChallanNoCol.GetCellContent(clCurItem) as TextBlock;
                var    clChallanDateTextBox = clChallanDateCol.GetCellContent(clCurItem) as TextBlock;
                var    clSACCodeTextBox     = clSACCodeCol.GetCellContent(clCurItem) as TextBlock;
                var    clQuantityTextBox    = clQuantityCol.GetCellContent(clCurItem) as TextBlock;
                var    clRateTextBox        = clRateCol.GetCellContent(clCurItem) as TextBlock;

                cl_DescriptionToAdd.Text = clDescTextBox.Text;
                cl_ChallanNoToAdd.Text   = clChallanNoTextBox.Text;
                cl_ChallanDateToAdd.Text = clChallanDateTextBox.Text;
                cl_SACCodeToAdd.Text     = clSACCodeTextBox.Text;
                cl_QuantityToAdd.Text    = clQuantityTextBox.Text;
                cl_RateToAdd.Text        = clRateTextBox.Text;

                string strQuantity = cl_QuantityToAdd.Text;
                string strRate     = cl_RateToAdd.Text;

                double dQuantity = 0.0;
                double.TryParse(strQuantity, out dQuantity);

                double dRate = 0.0;
                double.TryParse(strRate, out dRate);
                string strAmount = (dQuantity * dRate).ToString();

                double dTotalAmountToDel = (dQuantity * dRate);

                double dOldSubTotal = 0.0;
                double.TryParse(cl_Subtotal.Text, out dOldSubTotal);

                dOldSubTotal -= dTotalAmountToDel;

                cl_Subtotal.Text  = dOldSubTotal.ToString("F");
                cl_CGSTTotal.Text = (dOldSubTotal * 0.025).ToString("F");
                cl_SGSTTotal.Text = (dOldSubTotal * 0.025).ToString("F");
                cl_Total.Text     = (dOldSubTotal + (dOldSubTotal * 0.05)).ToString("F");

                cl_DataTable.Items.RemoveAt(iCurRow);
            }
        }
Exemplo n.º 8
0
        public static FrameworkElement GetCellContent(this DataGrid dataGrid, int rowIndex, int colIndex)
        {
            DataGridRow row = GetRow(dataGrid, rowIndex);

            if (row != null)
            {
                DataGridColumn col     = dataGrid.Columns[colIndex];
                var            content = col.GetCellContent(row);
                if (content == null)
                {
                    dataGrid.ScrollIntoView(row, dataGrid.Columns[colIndex]);
                    content = col.GetCellContent(row);
                }
                return(content);
            }
            else
            {
                throw new Exception("Can not get row at index:" + rowIndex);
            }
        }
Exemplo n.º 9
0
        private static T GetCellItem <T>(object item, DataGridColumn column) where T : class
        {
            if (item == null)
            {
                return(null);
            }

            var cellData = (column.GetCellContent(item) as T);

            if (cellData == null)
            {
                //for our custom columns
                var gridData = (column.GetCellContent(item) as Panel);
                if (gridData != null)
                {
                    cellData = (gridData.Children.Where(x => x.GetType() == typeof(T)).FirstOrDefault() as T);
                }
            }
            return(cellData);
        }
Exemplo n.º 10
0
        private void Constants_DataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            string    constantColumnContents = ((Constants_DataGrid.ItemsSource as List <ConstantsTableData>)[e.Row.GetIndex()].Constant);
            string    toolTipMessage         = "";
            TextBlock cell = new TextBlock();

            switch (constantColumnContents)
            {
            case "Cp (kJ/mol-C)":
            {
                DataGridColumn elementColumn = Constants_DataGrid.Columns[0];
                cell           = elementColumn.GetCellContent(e.Row) as TextBlock;
                toolTipMessage = String.Format("This represents the heat capacity for {0}.", getCompoundComboBoxSelectedItemAsString());
            }
            break;

            case "Hf (kJ/mol)":
            {
                DataGridColumn elementColumn = Constants_DataGrid.Columns[0];
                cell           = elementColumn.GetCellContent(e.Row) as TextBlock;
                toolTipMessage = String.Format("This represents the heat of formation for {0}.", getCompoundComboBoxSelectedItemAsString());
            }
            break;

            case "Hv (kJ/mol)":
            {
                DataGridColumn elementColumn = Constants_DataGrid.Columns[0];
                cell           = elementColumn.GetCellContent(e.Row) as TextBlock;
                toolTipMessage = String.Format("This represents the heat of vaporization for {0}.", getCompoundComboBoxSelectedItemAsString());
            }
            break;

            case "Tb (C)":
            {
                DataGridColumn elementColumn = Constants_DataGrid.Columns[0];
                cell           = elementColumn.GetCellContent(e.Row) as TextBlock;
                toolTipMessage = String.Format("This represents the boiling point for {0}.", getCompoundComboBoxSelectedItemAsString());
            }
            break;

            case "Tm (C)":
            {
                DataGridColumn elementColumn = Constants_DataGrid.Columns[0];
                cell           = elementColumn.GetCellContent(e.Row) as TextBlock;
                toolTipMessage = String.Format("This represents the melting point for {0}.", getCompoundComboBoxSelectedItemAsString());
            }
            break;
            }
            ToolTipService.SetToolTip(cell, toolTipMessage);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Get the uncommitted value of the given column in the currently selected row.
        /// </summary>
        /// <param name="sortMemberPath">The way to find the column</param>
        /// <param name="columnEditorIndex">The index of the edit in the column (some columns can have more than one editor)</param>
        /// <returns>The uncommitted TextBlock value</returns>
        public string GetUncommittedColumnText(DataGridRow row, string sortMemberPath, int columnEditorIndex = 0)
        {
            DataGridColumn column = this.FindColumn(sortMemberPath);

            if (column != null)
            {
                FrameworkElement contentPresenter = column.GetCellContent(row.DataContext);
                if (row.IsEditing)
                {
                    List <Control> editors = new List <Control>();
                    WpfHelper.FindEditableControls(contentPresenter, editors);
                    if (editors.Count > columnEditorIndex)
                    {
                        Control editor = editors[columnEditorIndex];
                        TextBox box    = editor as TextBox;
                        if (box != null)
                        {
                            return(box.Text);
                        }
                        ComboBox combo = editor as ComboBox;
                        if (combo != null)
                        {
                            return(combo.Text);
                        }
                        DatePicker picker = editor as DatePicker;
                        if (picker != null)
                        {
                            return(picker.Text);
                        }
                    }
                    else
                    {
                        // Row might not yet be committed to Transaction and edited value
                        // is stored in a TextBlock.
                        List <TextBlock> blocks = new List <TextBlock>();
                        WpfHelper.FindTextBlocks(contentPresenter, blocks);
                        if (blocks.Count > columnEditorIndex)
                        {
                            TextBlock block = blocks[columnEditorIndex];
                            if (block != null)
                            {
                                return(block.Text);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 12
0
    private void ColorCell(DataGridColumn column, DataGridRow item, Color color)
    {
        var content = column.GetCellContent(item);

        if (content == null)
        {
            return;
        }
        var parent = GetParent <DataGridCell>(content);

        if (parent != null)
        {
            parent.Background = new SolidColorBrush(color);
        }
    }
Exemplo n.º 13
0
        private void OnAddNewRow(object sender, RoutedEventArgs e)
        {
            string strDescription = cl_DescriptionToAdd.Text;
            string strChallanNo   = cl_ChallanNoToAdd.Text;
            string strChallanDate = cl_ChallanDateToAdd.Text;
            string strSACCode     = cl_SACCodeToAdd.Text;
            string strQuantity    = cl_QuantityToAdd.Text;
            string strRate        = cl_RateToAdd.Text;

            double dQuantity = 0.0;

            double.TryParse(strQuantity, out dQuantity);

            double dRate = 0.0;

            double.TryParse(strRate, out dRate);
            string strAmount = (dQuantity * dRate).ToString();

            cl_DataTable.Items.Add(new { clDescripitonCol = strDescription, clChallanNoCol = strChallanNo, clChallanDateCol = strChallanDate, clSACCodeCol = strSACCode, clQuantityCol = strQuantity, clRateCol = strRate, clAmountCol = strAmount });

            DataGridColumn clAmountCol  = cl_DataTable.ColumnFromDisplayIndex(6);
            double         dTotalAmount = (dQuantity * dRate);
            int            iRowCount    = cl_DataTable.Items.Count;

            for (int iRowLoop = 0; iRowLoop < iRowCount - 1; iRowLoop++)
            {
                Object clCurItem       = cl_DataTable.Items.GetItemAt(iRowLoop);
                var    clAmountTextBox = clAmountCol.GetCellContent(clCurItem) as TextBlock;

                if (clAmountTextBox != null)
                {
                    double dAmount = 0.0;
                    double.TryParse(clAmountTextBox.Text, out dAmount);
                    dTotalAmount += dAmount;
                }
            }
            cl_Subtotal.Text  = dTotalAmount.ToString("F");
            cl_CGSTTotal.Text = (dTotalAmount * 0.025).ToString("F");
            cl_SGSTTotal.Text = (dTotalAmount * 0.025).ToString("F");
            cl_Total.Text     = (dTotalAmount + (dTotalAmount * 0.05)).ToString("F");

            cl_DescriptionToAdd.Text = "";
            cl_ChallanNoToAdd.Text   = "";
            cl_ChallanDateToAdd.Text = "";
            cl_SACCodeToAdd.Text     = "998821";
            cl_QuantityToAdd.Text    = "";
            cl_RateToAdd.Text        = "";
        }
Exemplo n.º 14
0
        public virtual FrameworkElement GetValueCellContent(object dataItem)
        {
            if (dataItem == null)
            {
                throw new ArgumentNullException("dataItem");
            }

            DataGridColumn col = GetValueColumn();

            if (col == null)
            {
                return(null);
            }

            return(col.GetCellContent(dataItem));
        }
        void gridRemarks_HyperLinkOrderNumbers()
        {
            //nugget: hyperlink any Form# matches in the Remarks - nice! unforunately any column sorting applied after this blows away the hyperlinks so i'll have to come back later and figure out a workaround
            DataGridColumn remarksCol = gridRemarks.Columns.FirstOrDefault(c => c.SortMemberPath == "Remarks");

            if (remarksCol == null)
            {
                return;
            }

            //the regex looks like this: (.*?)([NE]F[12]-[A-Z]{2}-[0-9]{2}-[0-9]{5,6})
            //there are two capture groups (group[0] is always the full match):
            //group[1]: preliminary text
            //group[2]: OrderNumber
            //this way we can match multiple OrderNumbers in the text
            //each match gets the content between OrderNumbers
            //the very last bit tacks on any text that falls after the last OrderNumber
            //e.g. blah1 OrderNumber1 blah2 OrderNumber2 blah3
            //match[0]: blah1 OrderNumber1
            //match[1]: blah2 OrderNumber2
            foreach (object r in gridRemarks.Items)
            {
                //this did work but then when i started using WPFHelpders.GridSort logic it would always return null:
                TextBlock       lblRemarks = remarksCol.GetCellContent(r) as TextBlock;
                string          original   = lblRemarks.Text;
                MatchCollection matches    = OrderNumberRegEx.Matches(original);
                if (matches.Count == 0)
                {
                    continue;
                }

                lblRemarks.Inlines.Clear();
                string removestr = "";
                foreach (Match match in matches)
                {
                    Hyperlink link = new Hyperlink();
                    link.Command          = RoutedCommands.OpenTaxForm;
                    link.CommandParameter = match.Groups[2].Value; //this is the OrderNumber... and then the magic of RoutedCommands makes it elegant to fire open the order tab
                    link.Inlines.Add(match.Groups[2].Value);
                    lblRemarks.Inlines.Add(match.Groups[1].Value);
                    lblRemarks.Inlines.Add(link);
                    removestr += match.Value;
                }
                lblRemarks.Inlines.Add(original.Replace(removestr, "")); //tack on any text following the last OrderNumber match
            }
        }
Exemplo n.º 16
0
        public static string GetColumnValue(DataGridRow row, DataGridColumn column, int columnEditorIndex = 0)
        {
            FrameworkElement contentPresenter = column.GetCellContent(row.DataContext);

            if (row.IsEditing)
            {
                List <Control> editors = new List <Control>();
                WpfHelper.FindEditableControls(contentPresenter, editors);
                if (editors.Count > columnEditorIndex)
                {
                    Control editor = editors[columnEditorIndex];
                    TextBox box    = editor as TextBox;
                    if (box != null)
                    {
                        return(box.Text);
                    }
                    ComboBox combo = editor as ComboBox;
                    if (combo != null)
                    {
                        return(combo.Text);
                    }
                    DatePicker picker = editor as DatePicker;
                    if (picker != null)
                    {
                        return(picker.Text);
                    }
                }
                else
                {
                    List <TextBlock> blocks = new List <TextBlock>();
                    WpfHelper.FindTextBlocks(contentPresenter, blocks);
                    if (blocks.Count > columnEditorIndex)
                    {
                        TextBlock block = blocks[columnEditorIndex];
                        if (block != null)
                        {
                            return(block.Text);
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 17
0
        private static void OnDataGridRowMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row = sender as DataGridRow;

            if (null == row)
            {
                return;
            }

            DataGridControl datagrid = VisualTreeHelperExtended.GetAncestor(row, typeof(DataGridControl)) as DataGridControl;

            if (null == datagrid)
            {
                return;
            }

            if (CollectionView.NewItemPlaceholder == row.Item)
            {
                ControlTemplate template = GetTemplate(datagrid);
                if (row.Template == template)
                {
                    row.Template = GetDefaultTemplate(datagrid);
                    row.UpdateLayout();

                    datagrid.CurrentItem = row.Item;

                    // 3/23/2010 - Get the first non-read only column (http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=4710)
                    DataGridColumn column = datagrid.Columns.FirstOrDefault(col => !col.IsReadOnly);
                    if (column != null)
                    {
                        DataGridCell cell = VisualTreeHelperExtended.GetAncestor(column.GetCellContent(row), typeof(DataGridCell)) as DataGridCell;

                        if (cell != null)
                        {
                            cell.Focus();
                        }
                    }

                    datagrid.BeginEdit();
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// 设置当前单元格控件的方向提供者
        /// </summary>
        /// <param name="column"></param>
        /// <param name="row"></param>
        private void SetCurrentProvider(DataGridColumn column, object row)
        {
            if (row == null)
            {
                return;
            }
            var control = column.GetCellContent(row);

            if (providerCollection[control] == null)
            {
                var orientationProvider = ManagerOrientationProvider.InitControlPrivider(control);

                if (orientationProvider != null)
                {
                    orientationProvider.SetOrientationProvider(control);

                    orientationProvider.Behavior = this;

                    providerCollection.Add(orientationProvider);
                }
            }
        }
        private void UpdateCell(MediaFile mediaFile, string columnName)
        {
            if (Thread.CurrentThread == Dispatcher.Thread)
            {
                DataGridColumn    column            = Columns.FirstOrDefault(c => c.Header.ToString() == columnName);
                TextBlock         cell              = column?.GetCellContent(mediaFile) as TextBlock;
                BindingExpression bindingExpression = cell?.GetBindingExpression(TextBlock.TextProperty);

                bindingExpression?.UpdateTarget();
            }
            else
            {
                Dispatcher.Invoke(
                    () =>
                {
                    DataGridColumn column = Columns.FirstOrDefault(c => c.Header.ToString() == columnName);
                    TextBlock cell        = column?.GetCellContent(mediaFile) as TextBlock;
                    BindingExpression bindingExpression = cell?.GetBindingExpression(TextBlock.TextProperty);

                    bindingExpression?.UpdateTarget();
                });
            }
        }
 private void GenerateAutomationElementIdForCells(DataGrid dataGrid)
 {
     if (dataGrid == null)
     {
         return;
     }
     for (int index = 0; index < dataGrid.Columns.Count; ++index)
     {
         DataGridColumn dataGridColumn = dataGrid.Columns[index];
         foreach (DataStorePropertyEntry storePropertyEntry in (IEnumerable <DataStorePropertyEntry>) this.properties)
         {
             FrameworkElement cellContent = dataGridColumn.GetCellContent((object)storePropertyEntry);
             if (cellContent != null)
             {
                 DataGridCell dataGridCell = cellContent.Parent as DataGridCell;
                 if (dataGridCell != null)
                 {
                     AutomationElement.SetId((DependencyObject)dataGridCell, "Cell_" + storePropertyEntry.PropertyName + "_" + ConfigureDataStorePropertiesModel.columnNames[index]);
                 }
             }
         }
     }
 }
Exemplo n.º 21
0
        private void OnPrintBtnClicked(object sender, RoutedEventArgs e)
        {
            Cursor clOldCursor = Mouse.OverrideCursor;

            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            string clCurReportFilePath = System.IO.Path.Combine(AssemblyDirectory, "Bill.rdlc");

            if (!File.Exists(clCurReportFilePath))
            {
                Mouse.OverrideCursor = clOldCursor;
                MessageBox.Show("Error occurs while printing.\nContact Developer.", "Error");
                return;
            }

            LocalReport report = new LocalReport()
            {
                ReportPath = clCurReportFilePath
            };

            try
            {
                DataGridColumn clDescCol        = cl_DataTable.ColumnFromDisplayIndex(0);
                DataGridColumn clChallanNoCol   = cl_DataTable.ColumnFromDisplayIndex(1);
                DataGridColumn clChallanDateCol = cl_DataTable.ColumnFromDisplayIndex(2);
                DataGridColumn clSACCodeCol     = cl_DataTable.ColumnFromDisplayIndex(3);
                DataGridColumn clQuantityCol    = cl_DataTable.ColumnFromDisplayIndex(4);
                DataGridColumn clRateCol        = cl_DataTable.ColumnFromDisplayIndex(5);
                DataGridColumn clAmountCol      = cl_DataTable.ColumnFromDisplayIndex(6);

                DataTable clBillTable = new DataTable("BillInfo");
                clBillTable.Columns.Add("SrNo", typeof(string));
                clBillTable.Columns.Add("Description", typeof(string));
                clBillTable.Columns.Add("ChallanNo", typeof(string));
                clBillTable.Columns.Add("ChallanDate", typeof(string));
                clBillTable.Columns.Add("SACCode", typeof(string));
                clBillTable.Columns.Add("Quantity", typeof(Decimal));
                clBillTable.Columns.Add("Unit", typeof(string));
                clBillTable.Columns.Add("Rate", typeof(string));
                clBillTable.Columns.Add("Amount", typeof(Double));

                double dTotalAmount = 0;
                int    iRowCount    = cl_DataTable.Items.Count;

                clBillTable.Rows.Clear();

                for (int iRowLoop = 0; iRowLoop < iRowCount; iRowLoop++)
                {
                    Object clCurItem            = cl_DataTable.Items.GetItemAt(iRowLoop);
                    var    clDescTextBox        = clDescCol.GetCellContent(clCurItem) as TextBlock;
                    var    clChallanNoTextBox   = clChallanNoCol.GetCellContent(clCurItem) as TextBlock;
                    var    clChallanDateTextBox = clChallanDateCol.GetCellContent(clCurItem) as TextBlock;
                    var    clSACCodeTextBox     = clSACCodeCol.GetCellContent(clCurItem) as TextBlock;
                    var    clQuantityTextBox    = clQuantityCol.GetCellContent(clCurItem) as TextBlock;
                    var    clRateTextBox        = clRateCol.GetCellContent(clCurItem) as TextBlock;
                    var    clAmountTextBox      = clAmountCol.GetCellContent(clCurItem) as TextBlock;

                    int iQuantity = 0;
                    int.TryParse(clQuantityTextBox.Text, out iQuantity);

                    double dAmount = 0.0;
                    double.TryParse(clAmountTextBox.Text, out dAmount);

                    clBillTable.Rows.Add((iRowLoop + 1).ToString(),
                                         clDescTextBox.Text,
                                         clChallanNoTextBox.Text,
                                         clChallanDateTextBox.Text,
                                         clSACCodeTextBox.Text,
                                         iQuantity,
                                         "Nos",
                                         clRateTextBox.Text,
                                         dAmount
                                         );

                    dTotalAmount += dAmount;
                }

                string clAddress = cl_Address.Text;
                clAddress.Replace('\n', ',');
                report.SetParameters(new ReportParameter("strBuyerName", cl_BuyerName.Text));
                report.SetParameters(new ReportParameter("strBuyerAddress", clAddress));
                report.SetParameters(new ReportParameter("strBuyerCity", cl_City.Text));
                report.SetParameters(new ReportParameter("strBuyerGSTIN", cl_BuyerGSTIN.Text));
                report.SetParameters(new ReportParameter("strInvoiceNo", cl_InvoiceNo.Text));
                report.SetParameters(new ReportParameter("strInvoiceDate", cl_InvoiceDate.Text));
                report.SetParameters(new ReportParameter("strOtherDetails", cl_OtherDetails.Text));
                report.SetParameters(new ReportParameter("strSubTotal", dTotalAmount.ToString("F")));
                report.SetParameters(new ReportParameter("strCGST", (dTotalAmount * 0.025).ToString("F")));
                report.SetParameters(new ReportParameter("strSGST", (dTotalAmount * 0.025).ToString("F")));
                dTotalAmount += (dTotalAmount * 0.05);
                int iForRounding = (int)(dTotalAmount + 0.49);
                dTotalAmount = iForRounding;
                report.SetParameters(new ReportParameter("strRsInWords", ConvertMyword((int)dTotalAmount)));
                report.SetParameters(new ReportParameter("strTotalAmount", dTotalAmount.ToString("F")));
                report.SetParameters(new ReportParameter("strFirmName", "HARDIK ART"));
                report.SetParameters(new ReportParameter("strBankName", "State Bank Of India"));
                report.SetParameters(new ReportParameter("strAccountNo", "36729467959"));
                report.SetParameters(new ReportParameter("strIFSCCode", "SBIN0005722"));

                report.SetParameters(new ReportParameter("strBillType", "Original"));

                report.DataSources.Clear();

                var reportDataSource1 = new ReportDataSource();
                reportDataSource1.Name  = "BillInfo";
                reportDataSource1.Value = clBillTable;

                report.DataSources.Add(reportDataSource1);

                report.PrintToPrinter();

                if (cl_TriplicateBillCheckBox.IsChecked == true)
                {
                    report.SetParameters(new ReportParameter("strBillType", "Duplicate"));
                    report.PrintToPrinter();

                    report.SetParameters(new ReportParameter("strBillType", "Triplicate"));
                    report.PrintToPrinter();
                }

                if (MessageBox.Show(this, "Bill sent to printer. You want to clear bill data ?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    fnClearData();
                }
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = clOldCursor;
                MessageBox.Show("Error occurs while exporting.\n If you think it's not your error, Contact Developer.\n\nError Message :- " + ex.Message, "Error");
            }

            Mouse.OverrideCursor = clOldCursor;
        }
Exemplo n.º 22
0
        public void btnExport_Click(DataGrid Grille)
        {
            appExcel         = new XL.Application();
            wbk              = appExcel.Workbooks.Add();
            sheet            = wbk.Worksheets.Add();
            appExcel.Visible = true;
            int colExcel = 1;
            int rowExcel = 1;

            XL.Range rng = null;
            // Headers  Colonnes
            foreach (DataGridColumn ob in Grille.Columns)
            {
                rng       = this.sheet.Cells[rowExcel, colExcel];
                rng.Value = ob.Header.ToString();
                colExcel++;
            }
            //Contenu Colonnes
            //Contenu caste -vers TextBlock - car nous utilisons DataGridTextColumn
            rowExcel++;
            for (int i = 0; i < Grille.Items.Count; i++)
            {
                DataGridRow dRow = (DataGridRow)Grille.ItemContainerGenerator.ContainerFromIndex(i);
                if (dRow == null)
                {
                    continue;
                }
                for (int j = 0; j < Grille.Columns.Count; j++)
                {
                    colExcel = j + 1;
                    DataGridColumn dCol = Grille.Columns[j];
                    rng       = sheet.Cells[rowExcel, colExcel];
                    rng.Value = ((TextBlock)dCol.GetCellContent(dRow)).Text;
                }
                rowExcel++;
            }
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "Execl files (*.xls)|*.xls";

            saveFileDialog.FilterIndex = 0;

            saveFileDialog.RestoreDirectory = true;

            saveFileDialog.CreatePrompt = true;

            saveFileDialog.Title = "Export Excel File To";


            wbk.SaveCopyAs(saveFileDialog.FileName);


            if (this.appExcel != null)
            {
                if (this.sheet != null)
                {
                    Marshal.ReleaseComObject(this.sheet);
                }
                if (this.wbk != null)
                {
                    Marshal.ReleaseComObject(this.wbk);
                }
                this.appExcel.Quit();
                Marshal.ReleaseComObject(this.appExcel);
            }
        }
Exemplo n.º 23
0
        private void GridRemarksSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //nugget: hyperlink any Form# matches in the Remarks - nice!
            //nugget: unfortunately any kind of code driven or user driven sorting blows away custom DataGridColumn.GetCellContent() modifications like this
            //nugget: see here: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/63974f4f-d9ee-45af-8499-42f29cbc22ae?prof=required

            //so, just wound up doing this when the grid is clicked... still pretty practical and works great... much more convenient than opening this form through alternative means

            DataGridColumn remarksCol = gridRemarks.Columns.FirstOrDefault(c => c.SortMemberPath == "Remarks");

            if (remarksCol == null)
            {
                return;
            }

            //the regex looks like this: (.*?)([NE]F[12]-[A-Z]{2}-[0-9]{2}-[0-9]{5,6})
            //there are two capture groups (group[0] is always the full match):
            //group[1]: preliminary text
            //group[2]: OrderNumber
            //this way we can match multiple OrderNumbers in the text
            //each match gets the content between OrderNumbers
            //the very last bit tacks on any text that falls after the last OrderNumber
            //e.g. blah1 OrderNumber1 blah2 OrderNumber2 blah3
            //match[0]: blah1 OrderNumber1
            //match[1]: blah2 OrderNumber2

            var lblRemarks = remarksCol.GetCellContent(gridRemarks.CurrentItem) as TextBlock; //this basically works but any kind of grid sorting must virtualize this info since it always returns null after that

            if (lblRemarks == null)
            {
                return;
            }

            Hyperlink dummy;

            if (lblRemarks.TryFindChild(out dummy))
            {
                return;                               //if this column is already hyperlinked, bail out
            }
            var original = lblRemarks.Text;
            var matches  = OrderNumberRegEx.Matches(original);

            if (matches.Count == 0)
            {
                return;
            }

            lblRemarks.Inlines.Clear();
            var removestr = "";

            foreach (Match match in matches)
            {
                var link = new Hyperlink {
                    Command = RoutedCommands.OpenTaxForm, CommandParameter = match.Groups[2].Value
                };
                //this is the OrderNumber... and then the magic of RoutedCommands makes it elegant to fire open the order tab
                link.Inlines.Add(match.Groups[2].Value);
                lblRemarks.Inlines.Add(match.Groups[1].Value);
                lblRemarks.Inlines.Add(link);
                removestr += match.Value;
            }
            lblRemarks.Inlines.Add(original.Replace(removestr, "")); //tack on any text following the last OrderNumber match
        }
Exemplo n.º 24
0
        /// <summary>
        /// 指定されたカラム及びRowの情報からDataGridのCellを取得する
        /// </summary>
        /// <param name="col">DataGridのColumn情報</param>
        /// <param name="grow">DataGridのRowオブジェクト</param>
        /// <returns></returns>
        public static DataGridCell GetDataGridCell(DataGridColumn col, DataGridRow grow)
        {
            DataGridCell cell = FindVisualParent <DataGridCell>(col.GetCellContent(grow));

            return(cell);
        }