Ejemplo n.º 1
0
        private void ux_datagridviewOrderRequestItem_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;
            DataTable dt = (DataTable)((BindingSource)dgv.DataSource).DataSource;
            string columnName = dgv.CurrentCell.OwningColumn.Name;
            DataColumn dc = dt.Columns[columnName];
            DataRow dr;

            if (_sharedUtils.LookupTablesIsValidFKField(dc))
            {
                //string luTableName = dc.ExtendedProperties["foreign_key_resultset_name"].ToString().Trim();
                string luTableName = dc.ExtendedProperties["foreign_key_dataview_name"].ToString().Trim();
                dr = ((DataRowView)dgv.CurrentRow.DataBoundItem).Row;
                //GrinGlobal.Client.Data.LookupTablePicker ltp = new GrinGlobal.Client.Data.LookupTablePicker(lookupTables, localDBInstance, columnName, dr, dgv.CurrentCell.EditedFormattedValue.ToString());
                string suggestedFilter = "";

                //if (_lastDGVCharPressed > 0) suggestedFilter = _lastDGVCharPressed.ToString();
                if (dc.ColumnName.Trim().ToLower() != "inventory_id")
                {
                    if (dgv.CurrentRow != null &&
                       dgv.CurrentCell.EditedFormattedValue != null)
                    {
                        suggestedFilter = dgv.CurrentCell.EditedFormattedValue.ToString();
                    }

                    GRINGlobal.Client.Common.LookupTablePicker ltp = new GRINGlobal.Client.Common.LookupTablePicker(_sharedUtils, columnName, dr, suggestedFilter);
                    ltp.StartPosition = FormStartPosition.CenterParent;
                    if (DialogResult.OK == ltp.ShowDialog())
                    {
                        if (dr != null)
                        {
                            if (ltp.NewKey != null && dr[dgv.CurrentCell.ColumnIndex].ToString().Trim() != ltp.NewKey.Trim())
                            {
                                dr[dgv.CurrentCell.ColumnIndex] = ltp.NewKey.Trim();
                                dgv.CurrentCell.Value = ltp.NewValue.Trim();
                            }
                            else if (ltp.NewKey == null)
                            {
                                dr[dgv.CurrentCell.ColumnIndex] = DBNull.Value;
                                dgv.CurrentCell.Value = "";
                            }
                            dr.SetColumnError(dgv.CurrentCell.ColumnIndex, null);
            //RefreshDGVFormatting(dgv);
                        }
                    }
                }
                else
                {
                    if (dgv.CurrentRow != null &&
                       dgv.CurrentRow.Cells["accession_id"].EditedFormattedValue != null)
                    {
                        suggestedFilter = dgv.CurrentRow.Cells["accession_id"].EditedFormattedValue.ToString();
                    }

                    FKeyPicker fkp = new FKeyPicker(_sharedUtils, columnName, dr, suggestedFilter);
                    fkp.StartPosition = FormStartPosition.CenterParent;
                    if (DialogResult.OK == fkp.ShowDialog())
                    {
                        if (dr != null)
                        {
                            if (fkp.NewKey != null && dr[dgv.CurrentCell.ColumnIndex].ToString().Trim() != fkp.NewKey.Trim())
                            {
                                dr[dgv.CurrentCell.ColumnIndex] = fkp.NewKey.Trim();
                                dgv.CurrentCell.Value = fkp.NewValue.Trim();
                            }
                            else if (fkp.NewKey == null)
                            {
                                dr[dgv.CurrentCell.ColumnIndex] = DBNull.Value;
                                dgv.CurrentCell.Value = "";
                            }
                            dr.SetColumnError(dgv.CurrentCell.ColumnIndex, null);
            //RefreshDGVFormatting(dgv);
                        }
                    }
                }
                //_lastDGVCharPressed = (char)0;
                dgv.EndEdit();
            }
        }
Ejemplo n.º 2
0
        private void ux_buttonNewOrderRequestItemRow_Click(object sender, EventArgs e)
        {
            string pkey = ((DataRowView)_orderRequestBindingSource.Current)[_orderRequest.PrimaryKey[0].ColumnName].ToString();
            DataRow newOrderRequestItem = _orderRequestItem.NewRow();
            newOrderRequestItem["order_request_id"] = pkey;
            //_orderRequestItem.Rows.Add(newOrderRequestItem);

            // Set the current cell at the beginning of this new record...
            int newRowIndex = ux_datagridviewOrderRequestItem.Rows.GetLastRow(System.Windows.Forms.DataGridViewElementStates.Displayed);
            int newColIndex = ux_datagridviewOrderRequestItem.Columns.GetFirstColumn(System.Windows.Forms.DataGridViewElementStates.Displayed).Index;
            // Find the row index of the new record...
            for (int i = 0; i < ux_datagridviewOrderRequestItem.Rows.Count; i++)
            {
                if (ux_datagridviewOrderRequestItem["order_request_item_id", i].Value.Equals(newOrderRequestItem["order_request_item_id"])) newRowIndex = i;
            }
            // Find the left-most visible column index...
            foreach (DataGridViewColumn dgvc in ux_datagridviewOrderRequestItem.Columns)
            {
                if (dgvc.DisplayIndex == 0)
                {
                    newColIndex = dgvc.Index;
                    break;
                }
            }
            // Set the current cell to the new records left-most column...
            if (newColIndex > -1 && newRowIndex > -1) ux_datagridviewOrderRequestItem.CurrentCell = ux_datagridviewOrderRequestItem[newColIndex, newRowIndex];

            GRINGlobal.Client.Common.FKeyPicker ftp = new GRINGlobal.Client.Common.FKeyPicker(_sharedUtils, "inventory_id", newOrderRequestItem, "");
            ftp.StartPosition = FormStartPosition.CenterParent;
            if (DialogResult.OK == ftp.ShowDialog())
            {
                //if (newOrderRequestItem != null)
                //{
                //    if (ftp.NewKey != null && newOrderRequestItem["inventory_id"].ToString().Trim() != ftp.NewKey.Trim())
                //    {
                //        newOrderRequestItem["inventory_id"] = ltp.NewKey.Trim();
                //        ux_datagridviewOrderRequestItem["inventory_id", newRowIndex].Value = ltp.NewValue.Trim();

                //        DataSet ds = _sharedUtils.GetWebServiceData("get_inventory", ":inventoryid=" + ftp.NewKey.Trim(), 0, 0);
                //        if (ds.Tables.Contains("get_inventory") &&
                //            ds.Tables["get_inventory"].Rows.Count > 0)
                //        {
                //            DataRow dr = ds.Tables["get_inventory"].Rows[0];
                //            newOrderRequestItem["sequence_number"] = 99;
                //            newOrderRequestItem["name"] = dr["plant_name"];
                //            newOrderRequestItem["quantity_shipped"] = dr["distribution_default_quantity"];
                //            newOrderRequestItem["quantity_shipped_unit_code"] = dr["distribution_unit_code"];
                //            newOrderRequestItem["distribution_form_code"] = dr["distribution_default_form_code"];
                //            newOrderRequestItem["status_code"] = "NEW";
                //            newOrderRequestItem["status_date"] = DBNull.Value;
                //            newOrderRequestItem["inventory_id"] = dr["inventory_id"];
                //            newOrderRequestItem["accession_id"] = dr["accession_id"];
                //            newOrderRequestItem["external_taxonomy"] = _sharedUtils.GetLookupDisplayMember("taxonomy_species_lookup", dr["taxonomy_species_id"].ToString(), "", "");
                //        }
                //    }
                //    else if (ftp.NewKey == null)
                //    {
                //        newOrderRequestItem["inventory_id"] = DBNull.Value;
                //        ux_datagridviewOrderRequestItem["inventory_id", newRowIndex].Value = "";
                //    }
                //    newOrderRequestItem.SetColumnError("inventory_id", null);
                //    RefreshDGVFormatting(ux_datagridviewOrderRequestItem);
                //}
                if (_orderRequestItem != null)
                {
                    string newKey = "";
                    if(!string.IsNullOrEmpty(ftp.NewKey)) newKey = ftp.NewKey.Trim();
                    newOrderRequestItem = BuildOrderRequestItemRow(newKey, _orderRequestItem);
                    //newOrderRequestItem.SetColumnError("inventory_id", null);
                    _orderRequestItem.Rows.Add(newOrderRequestItem);
                }
                RefreshDGVFormatting(ux_datagridviewOrderRequestItem);
            }
        }