/// ------------------------------------------------------------------------------------ public void InitializeGrid(DataGridView grid) { foreach (var col in Columns) { if (!grid.Columns.Contains(col.Id)) continue; grid.Columns[col.Id].Visible = col.Visible; if (col.Width >= 0) grid.Columns[col.Id].Width = col.Width; if (col.DisplayIndex < 0) grid.Columns[col.Id].DisplayIndex = 0; else if (col.DisplayIndex >= grid.ColumnCount) grid.Columns[col.Id].DisplayIndex = grid.ColumnCount - 1; else grid.Columns[col.Id].DisplayIndex = col.DisplayIndex; } if (!string.IsNullOrEmpty(SortedColumn) && grid.Columns.Contains(SortedColumn)) grid.Sort(grid.Columns[SortedColumn], SortOrder == SortOrder.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending); // If the column header height or the former dpi settings are different, // then auto. calculate the height of the column headings. if (ColumnHeaderHeight <= 0 || DPI != m_currDpi) grid.AutoResizeColumnHeadersHeight(); else grid.ColumnHeadersHeight = ColumnHeaderHeight; }
private void QuestionSetEditor_Load(object sender, EventArgs e) { ds = new Dataset(); ds = (Dataset)dbObject.FullDataset.Copy(); for (int i = 0; i < ds.QuestionsEx.Count; i++) { if (ds.QuestionsEx[i].RowState == DataRowState.Deleted) { continue; } if (ds.QuestionsEx[i].SetId != Id) { ds.QuestionsEx[i].Delete(); continue; } if (ds.QuestionsEx[i].SubtypeId == 3) { ds.QuestionsEx[i].Delete(); continue; } } pasId = new int[ds.PassagesToQuestionsEx.Count]; questionSetsDataGrid.DataSource = ds; Idpas.DataSource = ds; questionSetsDataGrid.Update(); RefreshSetInfo(); ListSortDirection direction; direction = ListSortDirection.Ascending; questionSetsDataGrid.Sort(questionSetsDataGrid.Columns[questionOrderDataGridViewTextBoxColumn.Index], direction); }
private void PopulateForm(string folderPath) { try { DirectoryInfo di = new DirectoryInfo(folderPath); FileInfo[] fi = di.GetFiles("*.drtxt"); foreach (FileInfo fiTemp in fi) { string strFileName = fiTemp.Name; int intFileNameLength = strFileName.Length - 6; strFileName = fiTemp.Name.Substring(0, intFileNameLength); using (StreamReader sr = new StreamReader(folderPath + fiTemp.Name)) { sr.ReadLine(); sr.ReadLine(); string line = sr.ReadLine(); line = line.Substring(19); int strLineLength = line.Length - 1; line = line.Substring(0, strLineLength); line = line.Replace("", " \n"); dataGridView1.Rows.Add(new string[] { strFileName, line }); } } int i = dataGridView1.SelectedCells[0].RowIndex; dataGridView1.Rows[i].Selected = true; dataGridView1.Sort(colFileName, ListSortDirection.Ascending); } catch { } }
private string fillSQLOption(List <String> possibleQ, System.Windows.Forms.DataGridView grid_view) { //setup grid grid_view.AllowUserToAddRows = false; grid_view.Rows.Clear(); grid_view.ColumnCount = 2; //grid_view.Columns[0].au; grid_view.Visible = true; grid_view.ColumnHeadersVisible = true; DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle(); columnHeaderStyle.BackColor = Color.Beige; columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold); grid_view.ColumnHeadersDefaultCellStyle = columnHeaderStyle; grid_view.Columns[0].Name = "Query Options"; grid_view.Columns[1].Name = "Query Time (sec)"; float fin = 10000; string result = ""; foreach (string str in possibleQ) { string[] add = { "", "" }; if (queryTime.Keys.Contains(str)) { add[0] = str; add[1] = queryTime[str].ToString(); } else { add[0] = str; string arg = "/C " + path + "sqlite3 " + path + database + " \"" + str + "\" > " + path + "out.txt"; DateTime dt1 = DateTime.Now; float t1 = dt1.Second + (float)((float)dt1.Millisecond / 1000); run_command(arg); dt1 = DateTime.Now; float t2 = dt1.Second + (float)((float)dt1.Millisecond / 1000); add[1] = (t2 - t1).ToString(); if ((t2 - t1) < fin) { fin = (t2 - t1); result = str; } if ((t2 - t1) == fin) { if (str.Length < result.Length) { result = str; } } } grid_view.Rows.Add(add); } grid_view.Sort(grid_view.Columns[1], ListSortDirection.Ascending); grid_view.AutoResizeColumns(); return(result); }
public static void DataGridSort(DataGridView dgv, int column) { DataGridViewCustomSorter dgvSorter = null; if (dgv.Tag == null || !(dgv.Tag is IComparer)) { dgvSorter = new DataGridViewCustomSorter(dgv); dgv.Tag = dgvSorter; } else { dgvSorter = (DataGridViewCustomSorter)dgv.Tag; } dgvSorter.SortColumn = column; dgv.Sort(dgvSorter); }
void LoadGrid(DataGridView grid, Dictionary<int, int> stats) { grid.Rows.Clear(); grid.Columns.Clear(); grid.Columns.Add("Total", "Total"); grid.Columns.Add("Count", "Count"); foreach (int total in stats.Keys) { int rowIndex = grid.Rows.Add(); grid[0, rowIndex].Value = total; grid[1, rowIndex].Value = stats[total]; grid.Rows[rowIndex].Tag = total; PaintRow(grid, rowIndex); } grid.Sort(grid.Columns[0], ListSortDirection.Ascending); }
public void AddDataToGrid(DataGridView _messageGridView) { SqlCeConnection conn = new SqlCeConnection( Properties.Settings.Default.SIM900ConnectionString); conn.Open(); using (SqlCeDataAdapter adapter = new SqlCeDataAdapter( "SELECT * FROM MessageTable", conn)) { DataSet dataSource = new DataSet(); adapter.Fill(dataSource, "Message_table"); _messageGridView.DataSource = dataSource; _messageGridView.DataMember = "Message_table"; _messageGridView.Sort(_messageGridView.Columns[1], ListSortDirection.Descending); } conn.Close(); }
public override void DoDefaultAction() { DataGridViewColumnHeaderCell owner = (DataGridViewColumnHeaderCell)base.Owner; DataGridView dataGridView = owner.DataGridView; if (owner.OwningColumn != null) { if (owner.OwningColumn.SortMode == DataGridViewColumnSortMode.Automatic) { ListSortDirection ascending = ListSortDirection.Ascending; if ((dataGridView.SortedColumn == owner.OwningColumn) && (dataGridView.SortOrder == SortOrder.Ascending)) { ascending = ListSortDirection.Descending; } dataGridView.Sort(owner.OwningColumn, ascending); } else if ((dataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect) || (dataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect)) { owner.OwningColumn.Selected = true; } } }
public override void DoDefaultAction() { DataGridViewColumnHeaderCell dataGridViewCell = (DataGridViewColumnHeaderCell)Owner; DataGridView dataGridView = dataGridViewCell.DataGridView; if (dataGridViewCell.OwningColumn != null) { if (dataGridViewCell.OwningColumn.SortMode == DataGridViewColumnSortMode.Automatic) { ListSortDirection listSortDirection = ListSortDirection.Ascending; if (dataGridView.SortedColumn == dataGridViewCell.OwningColumn && dataGridView.SortOrder == SortOrder.Ascending) { listSortDirection = ListSortDirection.Descending; } dataGridView.Sort(dataGridViewCell.OwningColumn, listSortDirection); } else if (dataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect || dataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect) { dataGridViewCell.OwningColumn.Selected = true; } } }
private void subsumKosSales(int colnum, DataGridView dgv, int begin) { Double sum = 0, sum2 = 0, sum3 = 0; Double msum = 0, msum2 = 0, msum3 = 0; for (int j = 0; j < dgv.Rows.Count; j++) { DataGridViewRow row = new DataGridViewRow(); row = dgv.Rows[j]; if ((row.DefaultCellStyle.BackColor == bbgreen1) || (row.DefaultCellStyle.BackColor == bbgreen3)) { dgv.Rows.Remove(row); j--; } } if ((subsumKS == colnum) || (dgv.Rows.Count == 0)) { subsumKS = 0; return; } dgv.Sort(dgv.Columns[colnum], ListSortDirection.Ascending); String s1 = dgv.Rows[0].Cells[colnum].Value.ToString(); int i = 0; foreach (DataGridViewRow row in dgv.Rows) { if ((row.Cells[colnum].Value.ToString() != s1) && (s1 != "")) { s1 = dgv.Rows[i].Cells[colnum].Value.ToString(); if (begin == 11) dgv.Rows.Insert(i, "", "", "", "", "", "", "", "", "", "", "", sum, sum2, sum3); else dgv.Rows.Insert(i, "", "", "", "", "", "", "", "", "", "", "", "", sum, sum2, sum3); dgv.Rows[i].DefaultCellStyle.BackColor = bbgreen3; msum += sum; msum2 += sum2; msum3 += sum3; sum = 0; sum2 = 0; sum3 = 0; } else if (s1 != "") { if (row.Cells[begin].Value.ToString() != String.Empty) sum += Convert.ToDouble(row.Cells[begin].Value.ToString()); if (row.Cells[begin + 1].Value.ToString() != String.Empty) sum2 += Convert.ToDouble(row.Cells[begin + 1].Value.ToString()); if (row.Cells[begin + 2].Value.ToString() != String.Empty) sum3 += Convert.ToDouble(row.Cells[begin + 2].Value.ToString()); } i++; } msum += sum; msum2 += sum2; msum3 += sum3; if (begin == 11) { dgv.Rows.Add("", "", "", "", "", "", "", "", "", "", "", sum, sum2, sum3); dgv.Rows.Add("", "", "", "", "", "", "", "", "", "", "", msum, msum2, msum3); } else { dgv.Rows.Add("", "", "", "", "", "", "", "", "", "", "", "", sum, sum2, sum3); dgv.Rows.Add("", "", "", "", "", "", "", "", "", "", "", "", msum, msum2, msum3); } dgv.Rows[i].DefaultCellStyle.BackColor = bbgreen3; dgv.Rows[i + 1].DefaultCellStyle.BackColor = bbgreen1; subsumKS = colnum; }
// Fonction qui trie les produits de chaque tableaux en fonction de la quantité private void trierColonneQte(DataGridView unTableau, DataGridView unTableau1, DataGridView unTableau2) { unTableau.Sort(unTableau.Columns["qteMateriel"], ListSortDirection.Ascending); unTableau1.Sort(unTableau1.Columns["qteMateriel"], ListSortDirection.Ascending); unTableau2.Sort(unTableau2.Columns["qteMateriel"], ListSortDirection.Ascending); // Affichage contenu des 2 dernières colonnes de fournisseurs et catégories des datagridview //getContenuDerColonnes(tableauMateriel, tableauMateriel1, tableauMateriel2); }
public void SortExtendedProperties() { propertiesGrid.Sort(propertiesGrid.Columns["Key"], ListSortDirection.Ascending); }
/// <summary> /// This function loads the items details information. /// </summary> private void LoadOrderDetails() { g_FoodDataGridView.Rows.Clear(); g_BeverageDataGridView.Rows.Clear(); FillRMSDataGridView(); g_FoodDataGridView.ClearSelection(); g_BeverageDataGridView.ClearSelection(); if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) { COrderManager tempOrderManager = new COrderManager(); List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.OrderDetailsByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) tempOrderDetailsList = (List<COrderDetails>)oResult.Data; for (int itemIndex = 0; itemIndex < tempOrderDetailsList.Count; itemIndex++) { Int64 tempProductID = tempOrderDetailsList[itemIndex].ProductID; int tempCategoryLevel = tempOrderDetailsList[itemIndex].CategoryLevel; string tempProductName = ""; if (tempCategoryLevel == 3) { DataRow[] tempDataRowArr = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempProductID); if (tempDataRowArr.Length > 0) //Added by Baruri .This was a bug previously when no row found. { tempProductName = tempDataRowArr[0]["cat3_name"].ToString(); } } else if (tempCategoryLevel == 4) { DataRow[] tempDataRowArr = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID); int tempCat3_id = 0; if (tempDataRowArr.Length > 0) { tempCat3_id = Convert.ToInt32("0" + tempDataRowArr[0]["cat3_id"]); } tempProductName = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID)[0]["cat4_name"].ToString(); tempDataRowArr = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCat3_id); if (tempDataRowArr.Length > 0)//If rows found { tempProductName += " " + tempDataRowArr[0]["cat3_name"].ToString(); } } else if (tempCategoryLevel == 0) { tempProductName = tempOrderDetailsList[itemIndex].OrderRemarks; } int tempFoodType = 1; if (tempCategoryLevel == 3) { tempFoodType = int.Parse(Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempProductID)[0].GetParentRow(Program.initDataSet.Relations["category2_to_category3"])["cat2_type"].ToString()); } else if (tempCategoryLevel == 4) { int tempCat3_id = int.Parse(Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID)[0].GetParentRow(Program.initDataSet.Relations["category3_to_category4"])["cat3_id"].ToString()); tempFoodType = int.Parse(Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCat3_id)[0].GetParentRow(Program.initDataSet.Relations["category2_to_category3"])["cat2_type"].ToString()); } else { tempFoodType = -1; } DataGridView tempDataGridView = new DataGridView(); if (tempFoodType == 1)//Food Type { tempDataGridView = g_FoodDataGridView; } else if (tempFoodType == 0)//Nonfood Type { tempDataGridView = g_BeverageDataGridView; } else if (tempFoodType == -1) { if (tempOrderDetailsList[itemIndex].OrderFoodType == "Food") { tempDataGridView = g_FoodDataGridView; } else { tempDataGridView = g_BeverageDataGridView; } } //if remarks exists append it... otherwise append nothing... bool sele = false; string appendString = ""; if (tempCategoryLevel != 0) appendString = (tempOrderDetailsList[itemIndex].OrderRemarks.Equals("")) ? ("") : (" (" + tempOrderDetailsList[itemIndex].OrderRemarks + ")"); string[] tempDataGridViewRow = { tempProductName+appendString, tempOrderDetailsList[itemIndex].OrderQuantity.ToString(), ((double)tempOrderDetailsList[itemIndex].VatTotal).ToString("F02"), ((double)tempOrderDetailsList[itemIndex].OrderAmount).ToString("F02"), tempOrderDetailsList[itemIndex].ProductID.ToString(), tempOrderDetailsList[itemIndex].CategoryLevel.ToString(), (Int64.MaxValue-1)+"",//max rank tempOrderDetailsList[itemIndex].OrderDetailsID.ToString(), tempOrderDetailsList[itemIndex].PrintedQuantity.ToString(), tempOrderDetailsList[itemIndex].UnitPrice.ToString("F2"), }; //not misc item... rank is specified if (tempCategoryLevel != 0) { try { tempDataGridViewRow[6] = Program.initDataSet.Tables["Category" + tempCategoryLevel].Select("cat" + tempCategoryLevel + "_id = " + tempProductID)[0]["cat" + tempCategoryLevel + "_rank"].ToString(); } catch { } } try { tempDataGridView.Rows.Add(tempDataGridViewRow); } catch (Exception ex) { // MessageBox.Show(ex.ToString()); } ConvertRank(); if (tempDataGridView.Columns["Order_details_id"] !=null) tempDataGridView.Sort(tempDataGridView.Columns["Order_details_id"], ListSortDirection.Descending); if (tempDataGridView.Columns["dataGridViewTextBoxColumn5"] != null) tempDataGridView.Sort(tempDataGridView.Columns["dataGridViewTextBoxColumn5"], ListSortDirection.Descending); //this.FillCategory1OrderNumber();//New //tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending); tempDataGridView.Update(); } //get discount COrderDiscount tempOrderDiscount = new COrderDiscount(); oResult = tempOrderManager.OrderDiscountGetByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDiscount = (COrderDiscount)oResult.Data; m_dDiscountAmount = Convert.ToDecimal(tempOrderDiscount.Discount.ToString("F02")); } } else { //Loading the online orders information //g_FoodDataGridView.RowCount = 0; COrderManager tempOrderManager = new COrderManager(); string remarks = ""; string itemName = ""; List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.GetOnlineOrderDetailsByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) tempOrderDetailsList = (List<COrderDetails>)oResult.Data; for (int counter = 0; counter < tempOrderDetailsList.Count; counter++) { remarks = tempOrderDetailsList[counter].OrderRemarks.ToString(); itemName = tempOrderDetailsList[counter].ItemName.ToString(); if (remarks.Length > 0) { itemName = itemName + "(" + remarks + ")"; } string[] tempDataGridViewRow = { itemName, tempOrderDetailsList[counter].OrderQuantity.ToString(), tempOrderDetailsList[counter].OrderAmount.ToString("F02"), tempOrderDetailsList[counter].CategoryID.ToString(), tempOrderDetailsList[counter].CategoryLevel.ToString(), tempOrderDetailsList[counter].Rank.ToString(), tempOrderDetailsList[counter].OrderDetailsID.ToString(), tempOrderDetailsList[counter].PrintedQuantity.ToString(), tempOrderDetailsList[counter].UnitPrice.ToString("F2"), }; if (tempOrderDetailsList[counter].OrderFoodType.Replace(" ", "").ToUpper() == "Food".Replace(" ", "").ToUpper()) { g_FoodDataGridView.Rows.Add(tempDataGridViewRow); g_FoodDataGridView.Sort(g_FoodDataGridView.Columns[5], ListSortDirection.Ascending); } else { g_BeverageDataGridView.Rows.Add(tempDataGridViewRow); //If drinks g_BeverageDataGridView.Sort(g_BeverageDataGridView.Columns[5], ListSortDirection.Ascending); } } //get discount COrderDiscount tempOrderDiscount = new COrderDiscount(); oResult = tempOrderManager.OrderDiscountGetByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDiscount = (COrderDiscount)oResult.Data; m_dDiscountAmount = Convert.ToDecimal(tempOrderDiscount.Discount.ToString("F02")); } } this.TotalAmountCalculation(); g_FoodDataGridView.ClearSelection(); g_BeverageDataGridView.ClearSelection(); try { this.SetPrintedItemBackColor(); //set the back color } catch { } }
private void MoverFilas(DataGridView origen, DataGridView destino) { foreach (DataGridViewRow fila in origen.SelectedRows) { destino.Rows.Add(fila.Cells[0].Value, fila.Cells[1].Value); origen.Rows.Remove(fila); } destino.Sort(destino.Columns[1], ListSortDirection.Ascending); }
public void XMLToDataGridView(ArrayList tempList, string xmlFilePath) { ArrayList textResourceID = (ArrayList)tempList[0]; ArrayList textString = (ArrayList)tempList[1]; ArrayList dataGridViewTextResourceID = new ArrayList(); uint convert = 0; int searchIndex = 0; if (dataGridView1.Rows.Count >= 0) { DataTable dataTable = new DataTable(); DataColumn dc; DataRow dr; dc = new DataColumn(dataGridView1.Columns[0].HeaderText); dataTable.Columns.Add(dc); dc = new DataColumn(dataGridView1.Columns[1].HeaderText); dataTable.Columns.Add(dc); for (int i = 0; i < textResourceID.Count; i++) { dr = dataTable.NewRow(); dr[0] = "0x" + ((uint)textResourceID[i]).ToString("X8"); dr[1] = textString[i]; dataTable.Rows.Add(dr); progressBar1.Value = progressBar1.Maximum * i / textString.Count; } dataGridView1.Columns.Clear(); dataGridView1.DataSource = dataTable; RestoreDataGridViewSettings(); } else { int lastProgressBarValue = 0; DataGridView tempDataGridView = new DataGridView(); tempDataGridView.Columns.Add("Column1", "Text ID"); tempDataGridView.Columns.Add("Column2", "Display Text"); tempDataGridView.Columns.Add("Column3", "Line Number"); tempDataGridView.AllowUserToAddRows = false; tempDataGridView.AllowUserToDeleteRows = false; tempDataGridView.Rows.Add(dataGridView1.Rows.Count); for (int i = 0; i < dataGridView1.Rows.Count; i++) { tempDataGridView.Rows[i].Cells[0].Value = ((string)dataGridView1.Rows[i].Cells[0].Value).Replace("0x", ""); tempDataGridView.Rows[i].Cells[1].Value = dataGridView1.Rows[i].Cells[1].Value; tempDataGridView.Rows[i].Cells[2].Value = i.ToString("D6"); progressBar1.Value = progressBar1.Maximum / 4 * i / dataGridView1.Rows.Count; } lastProgressBarValue = progressBar1.Value; tempDataGridView.Rows[0].Cells[0].Selected = true; tempDataGridView.Sort(tempDataGridView.Columns[0], ListSortDirection.Ascending); for (int i = 0; i < tempDataGridView.Rows.Count; i++) { convert = Convert.ToUInt32((string)tempDataGridView.Rows[i].Cells[0].Value, 16); dataGridViewTextResourceID.Add(convert); progressBar1.Value = lastProgressBarValue + progressBar1.Maximum / 4 * i / tempDataGridView.Rows.Count; } lastProgressBarValue = progressBar1.Value; for (int i = 0; i < textString.Count; i++) { searchIndex = dataGridViewTextResourceID.BinarySearch(textResourceID[i]); if (searchIndex >= 0) { tempDataGridView.Rows[searchIndex].Cells[1].Value = textString[i]; } else { tempDataGridView.Rows.Add(); tempDataGridView.Rows[(tempDataGridView.Rows.Count - 1)].Cells[0].Value = ((uint)textResourceID[i]).ToString(); tempDataGridView.Rows[(tempDataGridView.Rows.Count - 1)].Cells[1].Value = textString[i]; tempDataGridView.Rows[(tempDataGridView.Rows.Count - 1)].Cells[2].Value = i.ToString("D6"); } progressBar1.Value = lastProgressBarValue + progressBar1.Maximum / 4 * i / textString.Count; } lastProgressBarValue = progressBar1.Value; tempDataGridView.Rows[0].Cells[2].Selected = true; tempDataGridView.Sort(tempDataGridView.Columns[2], ListSortDirection.Ascending); //dataGridView1.Rows.Clear(); //dataGridView1.Rows.Add(tempDataGridView.Rows.Count); DataTable dataTable = new DataTable(); DataColumn dc; DataRow dr; dc = new DataColumn(dataGridView1.Columns[0].HeaderText); dataTable.Columns.Add(dc); dc = new DataColumn(dataGridView1.Columns[1].HeaderText); dataTable.Columns.Add(dc); for (int i = 0; i < textResourceID.Count; i++) { dr = dataTable.NewRow(); dr[0] = "0x" + tempDataGridView.Rows[i].Cells[0].Value; dr[1] = tempDataGridView.Rows[i].Cells[1].Value; dataTable.Rows.Add(dr); progressBar1.Value = lastProgressBarValue + progressBar1.Maximum / 4 * i / tempDataGridView.Rows.Count; } dataGridView1.Columns.Clear(); dataGridView1.DataSource = dataTable; RestoreDataGridViewSettings(); for (int i = 0; i < tempDataGridView.Rows.Count; i++) { dataGridView1.Rows[i].Cells[0].Value = "0x" + tempDataGridView.Rows[i].Cells[0].Value; dataGridView1.Rows[i].Cells[1].Value = tempDataGridView.Rows[i].Cells[1].Value; progressBar1.Value = lastProgressBarValue + progressBar1.Maximum / 4 * i / tempDataGridView.Rows.Count; } } foreach (DataGridViewRow row in dataGridView1.Rows) { row.HeaderCell.Value = (row.Index + 1).ToString(); } progressBar1.Value = progressBar1.Maximum; }
private void NewsAllCompletedFillTable(DataGridView dgv) { dgv.DataSource = dtNews; dgv.Columns[0].Width = 37; dgv.Columns[1].Width = 311; dgv.Columns[2].Width = 41; dgv.Columns[3].Width = 67; dgv.Sort(dgv.Columns[0], System.ComponentModel.ListSortDirection.Descending); }
private void Category3Button_Click(object sender, EventArgs e) { try { CCategoryButton tempCategory3Button = (CCategoryButton)sender; int tempCategory3ID = tempCategory3Button.CategoryID; if (m_bItemDescriptionClicked) { string tempItemDescription = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCategory3ID)[0]["description"].ToString(); CMessageBox tempMessageBox = new CMessageBox("Item Description", tempItemDescription); tempMessageBox.ShowDialog(); m_bItemDescriptionClicked = false; return; } int tempFoodType = int.Parse(Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCategory3ID)[0].GetParentRow(Program.initDataSet.Relations["category2_to_category3"])["cat2_type"].ToString()); DataGridView tempDataGridView = new DataGridView(); tempDataGridView = g_FoodDataGridView; DataRow[] tempDataRowArray = Program.initDataSet.Tables["Category4"].Select("cat3_id = " + tempCategory3ID.ToString()); category4ButtonList.Clear(); if (tempDataRowArray.Length != 0) { foreach (DataRow tempDataRow in tempDataRowArray) { CCategoryButton tempCategoryButton = new CCategoryButton(); tempCategoryButton.CategoryID = int.Parse(tempDataRow["cat4_id"].ToString()); tempCategoryButton.CategoryOrder = int.Parse(tempDataRow["cat4_order"].ToString()); tempCategoryButton.CategoryLevel = 4; tempCategoryButton.Text = tempDataRow["cat4_name"].ToString(); tempCategoryButton.BackColor = tempCategory3Button.BackColor; category4ButtonList.Add(tempCategoryButton); } CCategory4Form tempCategory4Form = new CCategory4Form(tempCategory3ID, category4ButtonList, tempCategory3Button.Text); tempCategory4Form.ShowDialog(); CCategoryButton tempCategory4Button = CCategory4Form.m_cbResult; if (tempCategory4Button == null) return; else //insert into table and datagridview { NewOrder(); DataRow[] temp2DataRowArray = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempCategory4Button.CategoryID.ToString()); if (temp2DataRowArray.Length != 0) { //category4 + categpry3 string ItemName = temp2DataRowArray[0]["cat4_name"].ToString() + " " + tempCategory3Button.Text; string tableTypePrice = string.Empty; tableTypePrice = temp2DataRowArray[0]["bar_price"].ToString(); int tempSearchResult = DataGridViewSearch(tempDataGridView, ItemName); COrderManager tempOrderManager = new COrderManager(); COrderDetails tempOrderDetails = new COrderDetails(); if (tempSearchResult != -1) { int tempRowIndex = tempSearchResult; int qty = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[1].Value.ToString()) + m_iSavedOrderedQty; tempDataGridView.Rows[tempRowIndex].Cells[1].Value = qty; tempDataGridView.Rows[tempRowIndex].Cells[2].Value = ((double)(Double.Parse(tableTypePrice) * qty)).ToString("F02"); //update Order_details table tempOrderDetails.OrderID = orderID; tempOrderDetails.OrderDetailsID = Int64.Parse(tempDataGridView.Rows[tempRowIndex].Cells[6].Value.ToString()); tempOrderDetails.ProductID = tempCategory4Button.CategoryID; tempOrderDetails.CategoryLevel = tempCategory4Button.CategoryLevel; tempOrderDetails.OrderQuantity = qty; tempOrderDetails.OrderAmount = tempOrderDetails.OrderQuantity * Double.Parse(tableTypePrice); tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood"); tempOrderDetails.ItemOrderTime = DateTime.Now.Ticks; tempOrderManager.UpdateOrderDetails(tempOrderDetails); } else { //Insert into Order_details table tempOrderDetails.OrderID = orderID; tempOrderDetails.ProductID = tempCategory4Button.CategoryID; tempOrderDetails.CategoryLevel = tempCategory4Button.CategoryLevel; tempOrderDetails.OrderQuantity = m_iSavedOrderedQty; tempOrderDetails.OrderAmount = tempOrderDetails.OrderQuantity * Double.Parse(tableTypePrice); tempOrderDetails.ItemOrderTime = DateTime.Now.Ticks; tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood"); CResult oResult = tempOrderManager.InsertOrderDetails(tempOrderDetails); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDetails = (COrderDetails)oResult.Data; } string[] tempDataGridViewRow = new string[] { ItemName, m_iSavedOrderedQty.ToString(), ((double)(Double.Parse(tableTypePrice)*m_iSavedOrderedQty)).ToString("F02"), tempCategory4Button.CategoryID.ToString(), "4", temp2DataRowArray[0]["cat4_rank"].ToString(), tempOrderDetails.OrderDetailsID.ToString() }; tempDataGridView.Rows.Add(tempDataGridViewRow); } ConvertRank(); tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending); tempDataGridView.Update(); TotalAmountCalculation(); } } } else //There is no category4 { NewOrder(); DataGridViewRow tempDataGridViewRow = new DataGridViewRow(); tempDataGridViewRow.CreateCells(tempDataGridView); DataRow[] temp2DataRowArray = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCategory3Button.CategoryID.ToString()); if (temp2DataRowArray.Length != 0) { string tableTypePrice = string.Empty; tableTypePrice = temp2DataRowArray[0]["bar_price"].ToString(); COrderManager tempOrderManager = new COrderManager(); COrderDetails tempOrderDetails = new COrderDetails(); int tempResult = DataGridViewSearch(tempDataGridView, temp2DataRowArray[0]["cat3_name"].ToString()); if (tempResult != -1) { //update Order_details table int tempRowIndex = tempResult; int qty=int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[1].Value.ToString()) + m_iSavedOrderedQty; tempDataGridView.Rows[tempRowIndex].Cells[1].Value = qty; tempDataGridView.Rows[tempRowIndex].Cells[2].Value = ((double)(Double.Parse(tableTypePrice) * qty)).ToString("F02"); tempOrderDetails.OrderDetailsID = Int64.Parse(tempDataGridView.Rows[tempRowIndex].Cells[6].Value.ToString()); tempOrderDetails.OrderID = orderID; tempOrderDetails.ProductID = tempCategory3Button.CategoryID; tempOrderDetails.CategoryLevel = tempCategory3Button.CategoryLevel; tempOrderDetails.OrderQuantity = qty; tempOrderDetails.OrderAmount = tempOrderDetails.OrderQuantity * Double.Parse(tableTypePrice); tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood"); tempOrderManager.UpdateOrderDetails(tempOrderDetails); } else { //Insert into Order_details table tempOrderDetails.OrderID = orderID; tempOrderDetails.ProductID = tempCategory3Button.CategoryID; tempOrderDetails.CategoryLevel = tempCategory3Button.CategoryLevel; tempOrderDetails.OrderQuantity = m_iSavedOrderedQty; tempOrderDetails.OrderAmount = tempOrderDetails.OrderQuantity * Double.Parse(tableTypePrice); tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood"); tempOrderDetails.ItemOrderTime = DateTime.Now.Ticks; CResult oResult = tempOrderManager.InsertOrderDetails(tempOrderDetails); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDetails = (COrderDetails)oResult.Data; } string[] temp2DataGridViewRow = new string[] { temp2DataRowArray[0]["cat3_name"].ToString(), m_iSavedOrderedQty.ToString(), ((double)(Double.Parse(tableTypePrice)*m_iSavedOrderedQty)).ToString("F02"), tempCategory3Button.CategoryID.ToString(), "3", temp2DataRowArray[0]["cat3_rank"].ToString(), tempOrderDetails.OrderDetailsID.ToString() }; tempDataGridView.Rows.Add(temp2DataGridViewRow); } ConvertRank(); tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending); tempDataGridView.Update(); TotalAmountCalculation(); } } m_iSavedOrderedQty = 1; g_FoodDataGridView.ClearSelection(); } catch (Exception exp) { throw exp; } }
/// <summary> /// グリッドのソート設定 /// </summary> /// <param name="iGrid">グリッド</param> /// <param name="iColName">列名</param> /// <param name="iSortOrder">ソート順</param> private void setGridSort(DataGridView iGrid, string iColName, SortOrder iSortOrder) { if (iColName != string.Empty) { ListSortDirection sortDirection = ListSortDirection.Ascending; if (iSortOrder == SortOrder.Ascending) { sortDirection = ListSortDirection.Ascending; } else if (iSortOrder == SortOrder.Descending) { sortDirection = ListSortDirection.Descending; } iGrid.Sort(iGrid.Columns[iColName], sortDirection); } }
public static void fillGridOfDay_Group(int dayNumber, int groupNumber, ref DataGridView grid, ref ds_db db, bool partTime = false) { grid.Columns[0].ValueType = typeof(int); grid.Sort(grid.Columns[0], ListSortDirection.Ascending); grid.Rows.Clear(); for (int i = 0; i < 8; ++i) { grid.Rows.Add(); grid[0, i].Value = i + 1; grid[4, i].Value = grid[5, i].Value = false; } if (partTime) { var dayTimeTable = from row in db.pt_timetable where row.Day == dayNumber && row.GroupNumber == groupNumber orderby row.Number select row; foreach (var curRow in dayTimeTable) { int newrow = (int)curRow["Number"]; if (curRow[2] == DBNull.Value) continue; foreach (var row in dayTimeTable) { int indOfrow = (int)row["Number"] - 1; if (row[3] == DBNull.Value) continue; grid[1, indOfrow].Value = row.LessonsRow.Title; grid[2, indOfrow].Value = String.Format("{0} {1} {2}", row.TeachersRow.LastName, row.TeachersRow.FirstName, row.TeachersRow.Patronymic); grid[4, indOfrow].Value = (bool)row[5]; grid[5, indOfrow].Value = (bool)row[6]; grid[6, indOfrow].Value = row[7]; } } } else { var dayTimeTable = from row in db.ft_timetable where row.Day == dayNumber && row.GroupNumber == groupNumber orderby row.Number select row; foreach (var row in dayTimeTable) { int indOfrow = (int)row["Number"] - 1; if (row[3] == DBNull.Value) continue; grid[1, indOfrow].Value = row.LessonsRow.Title; grid[2, indOfrow].Value = String.Format("{0} {1} {2}", row.TeachersRow.LastName, row.TeachersRow.FirstName, row.TeachersRow.Patronymic); grid[4, indOfrow].Value = (bool)row[5]; grid[5, indOfrow].Value = (bool)row[6]; grid[6, indOfrow].Value = row[7]; } } }
private void FillNonFoods() { g_FoodDataGridView.RowCount = 0; COrderManager tempOrderManager = new COrderManager(); List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.OrderDetailsByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDetailsList = (List<COrderDetails>)oResult.Data; } for (int detailsCounter = 0; detailsCounter < tempOrderDetailsList.Count; detailsCounter++) { Int64 tempProductID = tempOrderDetailsList[detailsCounter].ProductID; int tempCategoryLevel = tempOrderDetailsList[detailsCounter].CategoryLevel; string tempProductName = ""; if (tempCategoryLevel == 3) { DataRow[] tempDataRowArr = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempProductID); tempProductName = tempDataRowArr[0]["cat3_name"].ToString(); } else if (tempCategoryLevel == 4) { //Latest name is at first int tempCat3_id = int.Parse(Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID)[0].GetParentRow(Program.initDataSet.Relations["category3_to_category4"])["cat3_id"].ToString()); tempProductName += Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID)[0]["cat4_name"].ToString(); tempProductName += " " + Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCat3_id)[0]["cat3_name"].ToString(); } else if (tempCategoryLevel == 0) tempProductName = tempOrderDetailsList[detailsCounter].OrderRemarks; int tempFoodType = 0; DataGridView tempDataGridView = new DataGridView(); tempDataGridView = g_FoodDataGridView; string[] tempDataGridViewRow = { tempProductName, tempOrderDetailsList[detailsCounter].OrderQuantity.ToString(), ((double)tempOrderDetailsList[detailsCounter].OrderAmount).ToString("F02"), tempOrderDetailsList[detailsCounter].ProductID.ToString(), tempOrderDetailsList[detailsCounter].CategoryLevel.ToString(), (Int64.MaxValue-1)+"",//max rank tempOrderDetailsList[detailsCounter].OrderDetailsID.ToString() }; //not misc item... rank is specified if (tempCategoryLevel != 0) tempDataGridViewRow[5] = Program.initDataSet.Tables["Category" + tempCategoryLevel].Select("cat" + tempCategoryLevel + "_id = " + tempProductID)[0]["cat" + tempCategoryLevel + "_rank"].ToString(); tempDataGridView.Rows.Add(tempDataGridViewRow); ConvertRank(); tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending); tempDataGridView.Update(); g_FoodDataGridView.ClearSelection(); } //get discount COrderDiscount tempOrderDiscount = new COrderDiscount(); oResult = tempOrderManager.OrderDiscountGetByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDiscount = (COrderDiscount)oResult.Data; m_dDiscountAmount = tempOrderDiscount.Discount; } if (category2ButtonList.Count > CATEGORY2PANEL_CAPACITY) g_NextButton.Enabled = true; else g_NextButton.Enabled = false; g_PreviousButton.Enabled = false; TotalAmountCalculation(); LoadStatusBar(); }
/// <summary> /// Refresh list of components /// </summary> /// <param name="grid"></param> public void fillComponents(DataGridView grid) { grid.Rows.Clear(); foreach(IComponent c in bootloader.Registered) { Type type = c.GetType(); if(!Inspector.isComponent(type)) { continue; } bool enabled = c.Enabled; string className = c.GetType().Name; Configuration.Component[] cfg = Settings.Cfg.Components; if(cfg != null && cfg.Length > 0) { Configuration.Component v = cfg.Where(p => p.ClassName == className).FirstOrDefault(); if(v != null) { enabled = v.Enabled; } } cInfo[className] = new List<INodeInfo>(); bool withoutAttr = true; foreach(Attribute attr in type.GetCustomAttributes(true)) { if(attr.GetType() == typeof(ComponentAttribute) || attr.GetType() == typeof(DefinitionAttribute)) { withoutAttr = false; } if(attr.GetType() == typeof(ComponentAttribute) && ((ComponentAttribute)attr).Parent == null) { fillComponents((ComponentAttribute)attr, enabled, className, grid); } else if(attr.GetType() == typeof(DefinitionAttribute) && ((DefinitionAttribute)attr).Parent == null) { DefinitionAttribute def = (DefinitionAttribute)attr; grid.Rows.Add(DomIcon.definition, enabled, def.Name, className, def.Description); } else if(((DefinitionAttribute)attr).Parent != null) { cInfo[className].Add(new NodeInfo((DefinitionAttribute)attr)); } else if(((ComponentAttribute)attr).Parent != null) { cInfo[className].Add(new NodeInfo((ComponentAttribute)attr)); } } if(withoutAttr) { grid.Rows.Add(DomIcon.package, enabled, String.Empty, className, String.Empty); } cInfo[className].AddRange(new List<INodeInfo>(domElemsBy(className))); } grid.Sort(grid.Columns[2], System.ComponentModel.ListSortDirection.Descending); }
public DataGridView MemberAssignmentBox(DataGridView data, Member selectedMember) { List<Assignment> assignments = manager.AssignmentsByCongregationId(selectedMember.CongregationId); List<MemberAssignment> ma = manager.MemberAssignmentsByMemberId(selectedMember.Id); data.Rows.Clear(); data.Refresh(); foreach (Assignment a in assignments) { bool isAssigned; if (ma.Any(z => z.AssignmentId == a.Id)) { isAssigned = true; } else { isAssigned = false; } data.Rows.Add(a.Id.ToString(), a.PositionOnSchedule, isAssigned, a.Label, a.Description, a.AmountPerMeeting); } data.Sort(data.Columns["SchedulePosition"], System.ComponentModel.ListSortDirection.Ascending); return data; }
private void Category3Button_Click(object sender, EventArgs e) { //get item qty CCategoryButton tempCategory3Button = (CCategoryButton)sender; RMSGlobal.m_sellinginvalue = tempCategory3Button.SellingQuantityorWeight; //Used to identify the product whether sold in quantity or weight int tempCategory3ID = tempCategory3Button.CategoryID; if (m_bItemDescriptionClicked) { string tempItemDescription = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCategory3ID)[0]["description"].ToString(); if (!tempItemDescription.Equals("")) { CMessageBox tempMessageBox = new CMessageBox("Item Description", tempItemDescription); tempMessageBox.ShowDialog(); } else { CMessageBox tempMessageBox = new CMessageBox("Item Description", "No information available."); tempMessageBox.ShowDialog(); } m_bItemDescriptionClicked = false; return; } int tempFoodType = int.Parse(Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCategory3ID)[0].GetParentRow(Program.initDataSet.Relations["category2_to_category3"])["cat2_type"].ToString()); DataGridView tempDataGridView = new DataGridView(); if (tempFoodType == 0) { tempDataGridView = g_BeverageDataGridView; } else { tempDataGridView = g_FoodDataGridView; } DataRow[] tempDataRowArray = Program.initDataSet.Tables["Category4"].Select("cat3_id = " + tempCategory3ID.ToString()); category4ButtonList.Clear(); COrderInfoDAO aOrderInfoDao = new COrderInfoDAO(); COrderInfo aCOrderInfo = aOrderInfoDao.GetOrderInfoByOrderID(orderID); if (tempDataRowArray.Length != 0) { foreach (DataRow tempDataRow in tempDataRowArray) { if (Int32.Parse(tempDataRow["status"].ToString()) == 0) { continue; } CCategoryButton tempCategoryButton = new CCategoryButton(); tempCategoryButton.CategoryID = int.Parse(tempDataRow["cat4_id"].ToString()); tempCategoryButton.CategoryOrder = int.Parse(tempDataRow["cat4_order"].ToString()); tempCategoryButton.CategoryLevel = 4; tempCategoryButton.Text = tempDataRow["cat4_name"].ToString(); tempCategoryButton.BackColor = tempCategory3Button.BackColor; category4ButtonList.Add(tempCategoryButton); } keyboardForm.Hide(); CCategory4Form tempCategory4Form = new CCategory4Form(tempCategory3ID, category4ButtonList, tempCategory3Button.Text); tempCategory4Form.ShowDialog(); CCategoryButton tempCategory4Button = CCategory4Form.m_cbResult; m_iSavedOrderedQty = CCategory4Form.ItemQTY; if (tempCategory4Button == null) { return; } else //insert into table and datagridview { DataRow[] temp2DataRowArray = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempCategory4Button.CategoryID.ToString()); if (temp2DataRowArray.Length != 0) { //category4 + categpry3 string ItemName = temp2DataRowArray[0]["cat4_name"].ToString() + " " + tempCategory3Button.Text; string tableTypePrice = string.Empty; if (m_iType == m_cCommonConstants.TableType) { tableTypePrice = temp2DataRowArray[0]["table_price"].ToString(); } else if (m_iType == m_cCommonConstants.TakeAwayType) { tableTypePrice = temp2DataRowArray[0]["tw_price"].ToString(); } int tempSearchResult = FindExistingItem(tempDataGridView, ItemName); // vat_included double vatRate = 0; bool vat_included = false; double vatAmountRate = 0; try { vatRate = Convert.ToDouble(temp2DataRowArray[0]["vat_Rate"].ToString()); vat_included = Convert.ToBoolean(temp2DataRowArray[0]["vat_included"].ToString()); if (vat_included) { vatAmountRate = (Double.Parse(tableTypePrice) * vatRate) / 100; // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString(); tableTypePrice = Convert.ToDouble(tableTypePrice).ToString(); } else { vatAmountRate = 0.00; } } catch (Exception ex) { } COrderManager tempOrderManager = new COrderManager(); COrderDetails tempOrderDetails = new COrderDetails(); if (tempSearchResult != -1) { int tempRowIndex = tempSearchResult; int qty = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[1].Value.ToString()) + m_iSavedOrderedQty; tempDataGridView.Rows[tempRowIndex].Cells[1].Value = qty; tempDataGridView.Rows[tempRowIndex].Cells[3].Value = ((double)(Double.Parse(tableTypePrice) * qty)).ToString("F02"); //update Order_details table tempOrderDetails.OrderID = orderID; tempOrderDetails.OrderDetailsID = Int64.Parse(tempDataGridView.Rows[tempRowIndex].Cells[7].Value.ToString()); tempOrderDetails.ProductID = tempCategory4Button.CategoryID; tempOrderDetails.CategoryLevel = tempCategory4Button.CategoryLevel; tempOrderDetails.OrderQuantity = qty; tempOrderDetails.UnitPrice = Convert.ToDouble(tableTypePrice); tempOrderDetails.OrderAmount = tempOrderDetails.OrderQuantity * Double.Parse(tableTypePrice); tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood"); tempOrderDetails.OnlineItemSequenceNumber = Int64.Parse(tempDataGridView.Rows[tempRowIndex].Cells[6].Value.ToString()); tempOrderDetails.PrintedQuantity = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[8].Value.ToString()); if (aCOrderInfo.VatComplementory) vatRate =vatAmountRate= 0; if (vat_included) { // tempOrderDetails.VatTotal = tempOrderDetails.OrderAmount * vatAmountRate; tempOrderDetails.VatTotal = qty * vatAmountRate; tempDataGridView.Rows[tempRowIndex].Cells[2].Value = qty * vatAmountRate; } else { tempOrderDetails.VatTotal = tempOrderDetails.OrderAmount * (vatRate / 100); } if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) { tempOrderManager.UpdateOrderDetails(tempOrderDetails); } else { tempOrderManager.UpdateOnlineOrderDetails(tempOrderDetails);//for online orders } } else { //Insert into Order_details table tempOrderDetails.OrderID = orderID; tempOrderDetails.ProductID = tempCategory4Button.CategoryID; tempOrderDetails.CategoryLevel = tempCategory4Button.CategoryLevel; tempOrderDetails.OrderQuantity = m_iSavedOrderedQty; tempOrderDetails.OrderAmount = tempOrderDetails.OrderQuantity * Double.Parse(tableTypePrice); tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood"); tempOrderDetails.ItemOrderTime = DateTime.Now.Ticks; tempOrderDetails.UnitPrice = Convert.ToDouble(tableTypePrice); // tempOrderDetails.Product_Name = temp2DataRowArray[0]["cat3_name"].ToString(); if (aCOrderInfo.VatComplementory) vatRate = 0; if (vat_included) { tempOrderDetails.VatTotal = 0; tempOrderDetails.VatTotal = tempOrderDetails.OrderAmount * (vatRate / 100); // tempOrderDetails.VatTotal = tempOrderDetails.OrderAmount * vatAmountRate; } else { tempOrderDetails.VatTotal = tempOrderDetails.OrderAmount * (vatRate / 100); } tempOrderDetails.Amount_with_vat = tempOrderDetails.OrderAmount + tempOrderDetails.VatTotal; string category1ID = this.GetCategory1ID(tempOrderDetails.ProductID, tempOrderDetails.CategoryLevel); //Int32 cat1Order = this.GetCategory1OrderNumber(Convert.ToInt32(category1ID)); // Change by Mithu if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) { tempOrderDetails = (COrderDetails)tempOrderManager.InsertOrderDetails(tempOrderDetails).Data; string[] tempDataGridViewRow = new string[] { ItemName, m_iSavedOrderedQty.ToString(), ((double)tempOrderDetails.VatTotal).ToString("F02"), ((double)(Double.Parse(tableTypePrice)*m_iSavedOrderedQty)).ToString("F02"), tempCategory4Button.CategoryID.ToString(), "4", temp2DataRowArray[0]["cat4_rank"].ToString(), tempOrderDetails.OrderDetailsID.ToString(), "0", tempOrderDetails.UnitPrice.ToString("F2") }; tempDataGridView.Rows.Add(tempDataGridViewRow); } else //For online orders { tempOrderDetails.ItemName = ItemName; tempOrderDetails = (COrderDetails)tempOrderManager.InsertOnlineOrderDetails(tempOrderDetails).Data; string[] tempDataGridViewRow = new string[] { ItemName, m_iSavedOrderedQty.ToString(), ((double)tempOrderDetails.VatTotal).ToString("F02"), ((double)(Double.Parse(tableTypePrice)*m_iSavedOrderedQty)).ToString("F02"), tempCategory4Button.CategoryID.ToString(), "4", tempOrderDetails.OnlineItemSequenceNumber.ToString(), tempOrderDetails.OrderDetailsID.ToString(),"0", tempOrderDetails.UnitPrice.ToString("F2") }; tempDataGridView.Rows.Add(tempDataGridViewRow); } } if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) //If local orders are considered { this.ConvertRank(); } tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending); tempDataGridView.Update(); TotalAmountCalculation(); } } } else //There is no category4 { keyboardForm.Hide(); try { CCalculatorForm tempCalculatorForm = new CCalculatorForm("Order Quantity", "Item Quantity"); tempCalculatorForm.ShowDialog(); if (CCalculatorForm.inputResult.Equals("Cancel")) return; string str = CCalculatorForm.inputResult; str = (str == "") ? "1" : str; if (Int32.Parse(str) == 0) { CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!"); tempMessageBox.ShowDialog(); return; } int tempOrderedQty = Int32.Parse(str); m_iSavedOrderedQty = tempOrderedQty; } catch (Exception exp) { MessageBox.Show(exp.Message, RMSGlobal.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } DataGridViewRow tempDataGridViewRow = new DataGridViewRow(); tempDataGridViewRow.CreateCells(tempDataGridView); DataRow[] temp2DataRowArray = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCategory3Button.CategoryID.ToString()); if (temp2DataRowArray.Length != 0) { string tableTypePrice = string.Empty; if (m_iType == m_cCommonConstants.TableType) { tableTypePrice = temp2DataRowArray[0]["table_price"].ToString(); } else if (m_iType == m_cCommonConstants.TakeAwayType) { tableTypePrice = temp2DataRowArray[0]["tw_price"].ToString(); } // vat_included double vatRate = 0; bool vat_included = false; double vatAmountRate = 0; try { vatRate = Convert.ToDouble(temp2DataRowArray[0]["vat_Rate"].ToString()); vat_included = Convert.ToBoolean(temp2DataRowArray[0]["vat_included"].ToString()); if (vat_included) { vatAmountRate = (Double.Parse(tableTypePrice) * vatRate) / 100; // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString(); tableTypePrice = Convert.ToDouble(tableTypePrice).ToString(); } else { vatAmountRate = 0.00; } } catch (Exception ex) { } COrderManager tempOrderManager = new COrderManager(); COrderDetails tempOrderDetails = new COrderDetails(); int tempResult = FindExistingItem(tempDataGridView, temp2DataRowArray[0]["cat3_name"].ToString()); if (tempResult != -1) { //update Order_details table int tempRowIndex = tempResult; int qty = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[1].Value.ToString()) + m_iSavedOrderedQty; tempDataGridView.Rows[tempRowIndex].Cells[1].Value = qty; tempDataGridView.Rows[tempRowIndex].Cells[3].Value = ((double)(Double.Parse(tableTypePrice) * qty)).ToString("F02"); tempOrderDetails.OrderDetailsID = Int64.Parse(tempDataGridView.Rows[tempRowIndex].Cells[7].Value.ToString()); tempOrderDetails.OrderID = orderID; tempOrderDetails.ProductID = tempCategory3Button.CategoryID; tempOrderDetails.CategoryLevel = tempCategory3Button.CategoryLevel; tempOrderDetails.UnitPrice = Convert.ToDouble(tableTypePrice); tempOrderDetails.OrderQuantity = qty; tempOrderDetails.OrderAmount = tempOrderDetails.OrderQuantity * Double.Parse(tableTypePrice); tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood"); tempOrderDetails.OnlineItemSequenceNumber = Convert.ToInt64("0" + tempDataGridView.Rows[tempRowIndex].Cells[6].Value.ToString()); tempOrderDetails.PrintedQuantity = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[8].Value.ToString()); if (aCOrderInfo.VatComplementory) vatAmountRate = 0; if (vat_included) { tempOrderDetails.VatTotal = qty * vatAmountRate; tempDataGridView.Rows[tempRowIndex].Cells[2].Value = tempOrderDetails.VatTotal; } else { tempOrderDetails.VatTotal = 0.00; } if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) { tempOrderManager.UpdateOrderDetails(tempOrderDetails); } else { tempOrderManager.UpdateOnlineOrderDetails(tempOrderDetails); } } else { //Insert into Order_details table tempOrderDetails.OrderID = orderID; tempOrderDetails.ProductID = tempCategory3Button.CategoryID; tempOrderDetails.CategoryLevel = tempCategory3Button.CategoryLevel; tempOrderDetails.UnitPrice = Convert.ToDouble(tableTypePrice); tempOrderDetails.OrderQuantity = m_iSavedOrderedQty; tempOrderDetails.OrderAmount = tempOrderDetails.OrderQuantity * Double.Parse(tableTypePrice); tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood"); tempOrderDetails.ItemOrderTime = DateTime.Now.Ticks; tempOrderDetails.Product_Name = temp2DataRowArray[0]["cat3_name"].ToString(); tempOrderDetails.UOM = temp2DataRowArray[0]["uom"].ToString(); tempOrderDetails.Product_Type = temp2DataRowArray[0]["productType"].ToString(); if (aCOrderInfo.VatComplementory) vatRate = vatAmountRate = 0; try { if (vat_included) { tempOrderDetails.VatTotal = 0; tempOrderDetails.VatTotal = tempOrderDetails.OrderAmount * (vatRate / 100); // tempOrderDetails.VatTotal = tempOrderDetails.OrderAmount * vatAmountRate; } else { tempOrderDetails.VatTotal = tempOrderDetails.OrderAmount * (vatRate / 100); } } catch { } try { tempOrderDetails.Amount_with_vat = tempOrderDetails.OrderAmount + tempOrderDetails.VatTotal; } catch { } string category1ID = this.GetCategory1ID(tempOrderDetails.ProductID, tempOrderDetails.CategoryLevel); Int32 cat1Order = this.GetCategory1OrderNumber(Convert.ToInt32(category1ID)); if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) { tempOrderDetails = (COrderDetails)tempOrderManager.InsertOrderDetails(tempOrderDetails).Data; string[] temp2DataGridViewRow = new string[] { temp2DataRowArray[0]["cat3_name"].ToString(), m_iSavedOrderedQty.ToString(), tempOrderDetails.VatTotal.ToString("F2"), ((double)(Double.Parse(tableTypePrice)*m_iSavedOrderedQty)).ToString("F02"), tempCategory3Button.CategoryID.ToString(), "3", temp2DataRowArray[0]["cat3_rank"].ToString(), tempOrderDetails.OrderDetailsID.ToString(),"0", tempOrderDetails.UnitPrice.ToString("F2") }; tempDataGridView.Rows.Add(temp2DataGridViewRow); } else { tempOrderDetails.ItemName = temp2DataRowArray[0]["cat3_name"].ToString(); tempOrderDetails = (COrderDetails)tempOrderManager.InsertOnlineOrderDetails(tempOrderDetails).Data; string[] temp2DataGridViewRow = new string[] {temp2DataRowArray[0]["cat3_name"].ToString(), m_iSavedOrderedQty.ToString(), tempOrderDetails.VatTotal.ToString(), ((double)(Double.Parse(tableTypePrice)*m_iSavedOrderedQty)).ToString("F02"), tempCategory3Button.CategoryID.ToString(), "3", tempOrderDetails.OnlineItemSequenceNumber.ToString(),//For online order sequence number is category rank. tempOrderDetails.OrderDetailsID.ToString(),"0", //0 For first time. tempOrderDetails.UnitPrice.ToString("F2") }; tempDataGridView.Rows.Add(temp2DataGridViewRow); } } if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) { this.ConvertRank(); } tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending); try { tempDataGridView.Update(); } catch { } TotalAmountCalculation(); } } g_FoodDataGridView.ClearSelection(); g_BeverageDataGridView.ClearSelection(); m_iSavedOrderedQty = 1; keyboardForm.Hide(); this.SetPrintedItemBackColor(); }
public async Task UpdateWeaponTextFields(Dictionary<string, Weapon> weapons, DataGridView gridView) { if (weapons == null) return; // Maintain the sort order of the sorted column after a refresh. DataGridViewColumn oldSortedColumn = gridView.SortedColumn; System.ComponentModel.ListSortDirection direction; // If oldColumn is null, then the DataGridView is not currently sorted. if (oldSortedColumn != null) { // Sort the same column again, reversing the SortOrder. if (gridView.SortOrder == SortOrder.Ascending) { direction = System.ComponentModel.ListSortDirection.Ascending; } else { // Sort a new column and remove the old SortGlyph. direction = System.ComponentModel.ListSortDirection.Descending; } } else { direction = System.ComponentModel.ListSortDirection.Descending; } gridView.Columns.Clear(); gridView.Columns.Add("nameCol", "Name"); gridView.Columns.Add("killsCol", "Kills"); gridView.Columns.Add("hsPercentCol", "HS%"); gridView.Columns.Add("accuracyCol", "Acc"); gridView.Columns.Add("headShotCol", "HS"); gridView.Columns.Add("fireCountCol", "Fired"); gridView.Columns.Add("hitsCount", "Hits"); // Setting the first column to a fill weight and minimum width // while setting the other columns to conform to all cells allows // the first stats to show up and be scrolled, but all columns will stretch // to the size of the gridview even when resizing. gridView.Columns[0].FillWeight = 15; gridView.Columns[0].MinimumWidth = 100; // Sort the new gridview. int sortedIndex = 1; for (int i = 1; i < gridView.ColumnCount; i++) { // Resize columns. gridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; if (oldSortedColumn != null) { if (gridView.Columns[i].HeaderText == oldSortedColumn.HeaderText) { sortedIndex = i; } } } // Set the HSR/ACC column to wrap text. gridView.Columns[2].DefaultCellStyle.WrapMode = DataGridViewTriState.True; gridView.Columns[3].DefaultCellStyle.WrapMode = DataGridViewTriState.True; // Resize the rows. gridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells; // Add all rows before iterating through them. if (weapons.Count == 0) return; gridView.Rows.Add(weapons.Count); for (int i = 0; i < weapons.Count; i++) { Weapon weapon = weapons.ElementAt(i).Value; string bestID = m_statTracker.GetBestWeaponID(weapon); // Will get either item or vehicle name. gridView.Rows[i].Cells[0].Value = await m_statTracker.GetItemName(m_statTracker.GetBestWeaponID(weapon)); gridView.Rows[i].Cells[1].Value = weapon.kills; // Calculate acc change. float currentACC = weapon.hitsCount / weapon.fireCount; string accStr = currentACC.ToString("#0.###%"); // Calculate hsr change. float currentHSR = weapon.headShots / weapon.kills; string hsrStr = currentHSR.ToString("#0.###%"); if (gridView.Name == "sessionWeaponsGridView" && (m_statTracker.SessionStarted() || m_statTracker.CountingEvents())) { string bestWeaponID = m_statTracker.GetBestWeaponID(weapon); // HSR float[] absHSR = m_statTracker.GetWeaponHSR(bestWeaponID, m_statTracker.GetSessionStats().startPlayer.weapons); float oldTotalHSR = absHSR[0] / (absHSR[1] == 0.0f ? 1 : absHSR[1]); float[] startHSR = m_statTracker.GetWeaponHSR(bestWeaponID, m_statTracker.GetSessionStats().startSesWeapons); absHSR[0] += weapon.headShots - startHSR[0]; absHSR[1] += weapon.kills - startHSR[1]; float newTotalHSR = absHSR[0] / (absHSR[1] == 0.0f ? 1 : absHSR[1]); float hsrDif = newTotalHSR - oldTotalHSR; hsrStr += "\n" + newTotalHSR.ToString("#0.###%") + " " + hsrDif.ToString("+#0.###%; -#0.###%"); if (hsrDif < 0) gridView.Rows[i].Cells[2].Style.ForeColor = m_lowColor; else if (hsrDif > 0) gridView.Rows[i].Cells[2].Style.ForeColor = m_highColor; else gridView.Rows[i].Cells[2].Style.ForeColor = Color.Black; // ACC float[] absACC = m_statTracker.GetWeaponACC(bestWeaponID, m_statTracker.GetSessionStats().startPlayer.weapons); float oldTotalACC = absACC[0] / (absACC[1] == 0.0f ? 1 : absACC[1]); absACC[0] += weapon.hitsCount; absACC[1] += weapon.fireCount; float newTotalACC = absACC[0] / (absACC[1] == 0.0f ? 1 : absACC[1]); float accDif = newTotalACC - oldTotalACC; accStr += "\n" + newTotalACC.ToString("#0.###%") + " " + accDif.ToString("+#0.###%; -#0.###%"); if (accDif < 0) gridView.Rows[i].Cells[3].Style.ForeColor = m_lowColor; else if (accDif > 0) gridView.Rows[i].Cells[3].Style.ForeColor = m_highColor; else gridView.Rows[i].Cells[3].Style.ForeColor = Color.Black; } gridView.Rows[i].Cells[2].Value = hsrStr; gridView.Rows[i].Cells[3].Value = accStr; gridView.Rows[i].Cells[4].Value = weapon.headShots; gridView.Rows[i].Cells[5].Value = weapon.fireCount; gridView.Rows[i].Cells[6].Value = weapon.hitsCount; } gridView.Sort(gridView.Columns[sortedIndex], direction); gridView.Columns[sortedIndex].HeaderCell.SortGlyphDirection = direction == System.ComponentModel.ListSortDirection.Ascending ? SortOrder.Ascending : SortOrder.Descending; gridView.ClearSelection(); }
private void insertarNuevosValores_trueFalse(DataGridView dgv) { int tipo = int.Parse(tb1_txtTipo.Text); int var = int.Parse(tb1_txtVar.Text); OleDbCommand comm = new OleDbCommand(); comm.Connection = conexion; string field = ""; string sql = "INSERT INTO tCampos (TipoEtiqueta, varEtiqueta, EtiquetasPorHoja, TipoCodigoBarra,"; foreach (DataGridViewRow row in tb1_dgv.Rows) { field = row.Cells[0].Value.ToString(); if (Convert.ToBoolean(row.Cells[2].Value) == true) { sql += field + ","; } } sql = sql.Remove(sql.Length - 1); sql += ") VALUES (" + tipo + "," + var + "," + tb1_cmbEtqHoja.Text + ", " + tb1_cmbCodigo.Text + " ,"; foreach (DataGridViewRow row in tb1_dgv.Rows) { field = row.Cells[0].Value.ToString(); if (Convert.ToBoolean(row.Cells[2].Value) == true) { sql += "TRUE,"; } } sql = sql.Remove(sql.Length - 1); sql += ")"; int idioma = 0; if (tb1_cmbIdioma.SelectedIndex == 0) idioma = 1; else if (tb1_cmbIdioma.SelectedIndex == 1) idioma = 2; try { conexion.Open(); //insertar los valores booleanos de los campos de la etiqueta en tCampos comm.CommandText = sql; comm.ExecuteNonQuery(); //insertar lotes de la etiqueta en tNombresLotes sql = "INSERT INTO tNombresLotes (tipo,var,LoteProduccion, LoteDespacho) VALUES" + "(" + tipo + ", " + var + ", '" + tb1_txtLotProd.Text + "', '" + tb1_txtLotDesp.Text + "')"; comm.CommandText = sql; comm.ExecuteNonQuery(); //insertar el idioma de la etiqueta en tIdiomasEtiquetas sql = "INSERT INTO tIdiomasEtiquetas (tipoEtiqueta,variacionEtiqueta,idiomaEtiqueta) VALUES ("+tipo+", "+var+", "+idioma+" )"; comm.CommandText = sql; comm.ExecuteNonQuery(); conexion.Close(); } catch (Exception ex) { if (conexion.State == ConnectionState.Open) conexion.Close(); MessageBox.Show(ex.Message); return; } MessageBox.Show("Se actualizaron los campos para la etiqueta tipo " + tipo.ToString() + " variación " + var + ". ", "Éxito", MessageBoxButtons.OK); dgv.Sort(dgv.Columns[2], ListSortDirection.Descending); foreach (DataGridViewRow row in dgv.Rows) row.DefaultCellStyle.BackColor = Color.White; tb2_pbar.Value = 0; }
[Test] // bug #442181 public void RemoveNewRowClear () { DataGridView dgv = new DataGridView (); dgv.Columns.Add ("A", "A"); dgv.Rows.Clear (); Assert.AreEqual (1, dgv.Rows.Count, "A1"); // This was crashing in the bug dgv.Sort (dgv.Columns[0], ListSortDirection.Ascending); }
private void actualizarDGV(DataGridView dgv, string nuevo) { string[] split = nuevo.Split('|'); dgv.Rows.Add(1); dgv.Rows[dgv.RowCount - 1].Cells[0].Value = split[0]; dgv.Rows[dgv.RowCount - 1].Cells[1].Value = split[1]; dgv.Rows[dgv.RowCount - 1].Cells[2].Value = true; dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.BackColor = Color.LightGreen; dgv.Columns[2].SortMode = DataGridViewColumnSortMode.Automatic; dgv.Sort(dgv.Columns[2], ListSortDirection.Descending); }
internal static void ShowTags_Click(object sender, EventArgs e, User i_LoggedInUser, DataGridView i_dataGridViewFriends) { i_dataGridViewFriends.Rows.Clear(); i_dataGridViewFriends.Tag = k_PhotosGridTag; i_dataGridViewFriends.Columns[0].HeaderText = k_NameColumnHeader; i_dataGridViewFriends.Columns[1].HeaderText = k_SharedPhotosColumnHeader; i_dataGridViewFriends.Columns[2].Visible = false; Dictionary<string, UserRank<Photo>> allUsersWithTagsOnPhotos = FetchTags(i_LoggedInUser); foreach (UserRank<Photo> userDetails in allUsersWithTagsOnPhotos.Values) { int index = i_dataGridViewFriends.Rows.Add(userDetails.Name, userDetails.GetObjectCount(), userDetails); i_dataGridViewFriends.Rows[index].ReadOnly = true; } i_dataGridViewFriends.Sort(i_dataGridViewFriends.Columns[1], ListSortDirection.Descending); }
private void actualizarNuevosValores_trueFalse(DataGridView dgv) { BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.ProgressChanged += new ProgressChangedEventHandler(actualizarPorcentajeQuery); int tipo = int.Parse(tb2_txtTipo.Text); int var = int.Parse(tb2_txtVar.Text); OleDbCommand comm = new OleDbCommand(); comm.Connection = conexion; string field = ""; foreach (DataGridViewRow row in tb2_dgv.Rows) { field = row.Cells[0].Value.ToString(); if (Convert.ToBoolean(row.Cells[2].Value) == true) { comm.CommandText = "UPDATE tCampos SET " + field + " = TRUE WHERE TipoEtiqueta=" + tipo + " AND varEtiqueta = " + var + ""; try { conexion.Open(); comm.ExecuteNonQuery(); conexion.Close(); } catch (Exception ex) { if (conexion.State == ConnectionState.Open) conexion.Close(); MessageBox.Show(ex.Message); return; } } else { comm.CommandText = "UPDATE tCampos SET " + field + " = FALSE WHERE TipoEtiqueta=" + tipo + " AND varEtiqueta = " + var + ""; try { conexion.Open(); comm.ExecuteNonQuery(); conexion.Close(); } catch (Exception ex) { if (conexion.State == ConnectionState.Open) conexion.Close(); MessageBox.Show(ex.Message); return; } } worker.ReportProgress(row.Index + 1); } try { comm.CommandText = "UPDATE tCampos SET EtiquetasPorHoja = " + int.Parse(tb2_cmbEtqHoja.Text.ToString()) + " WHERE TipoEtiqueta = "+tipo+" AND varEtiqueta = "+var+""; conexion.Open(); comm.ExecuteNonQuery(); conexion.Close(); conexion.Open(); comm.CommandText = "UPDATE tCampos SET TipoCodigoBarra = "+int.Parse(tb2_cmbTipoCod.Text) + " WHERE TipoEtiqueta = " + tipo + " AND varEtiqueta = " + var + ""; comm.ExecuteNonQuery(); conexion.Close(); conexion.Open(); comm.CommandText = "UPDATE tIdiomasEtiquetas SET idiomaEtiqueta=" + (tb2_cmbIdiomaEtq.SelectedIndex + 1) + " WHERE tipoEtiqueta = '" + tipo + "' AND variacionEtiqueta = '" + var + "'"; comm.ExecuteNonQuery(); conexion.Close(); conexion.Open(); comm.CommandText = "UPDATE tNombresLotes SET LoteDespacho='" + tb2_txtLoteDesp.Text + "' WHERE tipo = " + tipo + " AND var = " + var + ""; comm.ExecuteNonQuery(); conexion.Close(); conexion.Open(); comm.CommandText = "UPDATE tNombresLotes SET LoteProduccion='" + tb2_txtLoteProd.Text + "' WHERE tipo = " + tipo + " AND var = " + var + ""; comm.ExecuteNonQuery(); conexion.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } MessageBox.Show("Se actualizaron los campos para la etiqueta tipo " + tipo.ToString() + " variación " + var + ". ", "Éxito", MessageBoxButtons.OK); dgv.Sort(dgv.Columns[2], ListSortDirection.Descending); foreach (DataGridViewRow row in dgv.Rows) row.DefaultCellStyle.BackColor = Color.White; tb2_pbar.Value = 0; }
void Sort() { dataGridView.Sort(nameColumn, ListSortDirection.Ascending); }
private void ReDrawEveryThing(DataTable dt, DataGridView dgv, ComboBox cmb) { dgv.DataSource = dt; dgv.Columns[0].Width = dgv.Width - 75; dgv.Sort(dgv.Columns[0], System.ComponentModel.ListSortDirection.Ascending); cmb.Items.Clear(); cmb.Sorted = true; cmb.Items.Add(".: انتخاب گالري مورد نظر :."); string[] items = new string[dt.Rows.Count]; for (int i = 0; i < items.Length; i++) items[i] = dt.Rows[i][0].ToString().Trim(); cmb.Items.AddRange(items); cmb.SelectedIndex = 0; }
/// <summary>Создать вкладку со статистикой по заданной теме /// </summary> /// <param name="themeName">тема вкладки</param> /// <param name="weights">слово, вес слова в теме, количество слов в тексте</param> private void SetThemeStatistics(string themeName, Dictionary<string, Tuple<double, Int64>> weights) { var tp = new TabPage { Tag = themeName }; var dgv = new DataGridView { Dock = DockStyle.Fill, AllowUserToAddRows = false, AllowUserToDeleteRows = false, AllowUserToOrderColumns = false, AllowUserToResizeColumns = false, AllowDrop = false, AllowUserToResizeRows = false, MultiSelect = false }; tp.Controls.Add(dgv); tabControlThemes.TabPages.Add(tp); dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "FullText", AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, HeaderText = "Слово", ReadOnly = true }); dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "Status", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, HeaderText = "Статус", ReadOnly = true }); dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "Stem", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, HeaderText = "Основа слова", ReadOnly = true }); dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "Weight", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, HeaderText = "Вес слова в теме", ReadOnly = true }); dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "Count", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, HeaderText = "Количество слов в тексте", ReadOnly = true }); dgv.Columns.Add(new DataGridViewTextBoxColumn { Name = "Sum", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, HeaderText = "Суммарный вес", ReadOnly = true }); dgv.CellValueChanged += dgv_CellValueChanged; foreach (var weight in weights) { var rowIdx = dgv.Rows.Add(); var row = dgv.Rows[rowIdx]; row.Cells["FullText"].Value = _tc.GetFirstFullText(weight.Key); row.Cells["Stem"].Value = weight.Key; row.Cells["Weight"].Value = weight.Value.Item1; row.Cells["Count"].Value = weight.Value.Item2; row.Cells["Sum"].Value = weight.Value.Item1 * weight.Value.Item2; } dgv.Sort(dgv.Columns["Sum"], ListSortDirection.Descending); dgv.MouseClick += dgv_MouseClick; }
/// <summary> /// Loads the environment variables. /// </summary> /// <param name="dgv">The Data Grid View.</param> /// <param name="target">The target.</param> private void LoadEnvironmentVariables( DataGridView dgv, EnvironmentVariableTarget target) { EnvVarValueValidator validator = new EnvVarValueValidator(); int currentRowIndex = dgv.CurrentRow != null ? dgv.CurrentRow.Index : 0; dgv.Rows.Clear(); int rowIndex = 0; IDictionary environmentVariables = this.variableManger.GetEnvVariables(target); foreach (DictionaryEntry de in environmentVariables) { string[] row = { de.Key.ToString(), de.Value.ToString() }; rowIndex = dgv.Rows.Add(row); // validate variable value and show row in red if invalid if (!validator.Validate(de.Value.ToString())) { dgv.Rows[rowIndex].Cells[0].Style.ForeColor = Color.Red; dgv.Rows[rowIndex].Cells[1].Style.ForeColor = Color.Red; } } dgv.Sort(dgv.Columns[0], ListSortDirection.Ascending); try { dgv.CurrentCell = dgv[0, currentRowIndex]; dgv.FirstDisplayedScrollingRowIndex = currentRowIndex; } catch { // if row was deleted this will set it to first one // TODO: Implement this by searching for var name in the grid. // Catching Exceptions makes program slow if (dgv.Rows.Count != 0) { dgv.CurrentCell = dgv[0, 0]; dgv.FirstDisplayedScrollingRowIndex = 0; } } }
private void creaDataGridView_tb2(List<string> listaTodos, List<string> listaUsados, DataGridView dgv) { if (dgv.RowCount > 0) dgv.RowCount = 0; if (dgv.ColumnCount > 0) dgv.ColumnCount = 0; dgv.ColumnCount = 2; dgv.Columns[0].Name = "Nombre del campo"; dgv.Columns[1].Name = "Significado"; dgv.RowCount = listaTodos.Count; DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn(); chk.Name = "Activo"; dgv.Columns.Add(chk); Dictionary<string, string> dicc = new Dictionary<string, string>(); this.llenarDiccionario(dicc); int fila = 0; foreach (string c in listaTodos) { dgv.Rows[fila].Cells[0].Value = c; dgv.Rows[fila].Cells[1].Value = dicc[c]; fila++; } this.tb2_palomearActvios(listaUsados, dgv); dgv.Columns[2].SortMode = DataGridViewColumnSortMode.Automatic; dgv.Sort(dgv.Columns[2], ListSortDirection.Descending); dgv.Columns[0].ReadOnly = true; dgv.Columns[1].ReadOnly = true; dgv.AllowUserToOrderColumns = false; //dgv.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; dgv.Columns[0].SortMode = DataGridViewColumnSortMode.Automatic; dgv.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; dgv.Columns[2].SortMode = DataGridViewColumnSortMode.Automatic; this.actualizarInstrucciones(tb2_txtInstrucciones, 1); }
private void button12_Click(object sender, EventArgs e) { if (Statistics.Columns.Count == 3) { PrintDialog MyPrintDialog = new PrintDialog(); MyPrintDialog.AllowCurrentPage = false; MyPrintDialog.AllowPrintToFile = false; MyPrintDialog.AllowSelection = false; MyPrintDialog.AllowSomePages = false; MyPrintDialog.PrintToFile = false; MyPrintDialog.ShowHelp = false; MyPrintDialog.ShowNetwork = false; if (MyPrintDialog.ShowDialog() != DialogResult.OK) return; pd = new System.Drawing.Printing.PrintDocument(); pd.DocumentName = "������ �����"; //pd.PrinterSettings = MyPrintDialog.PrinterSettings; pd.DefaultPageSettings = pd.PrinterSettings.DefaultPageSettings; pd.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(20, 20, 20, 20); pd.DefaultPageSettings.Landscape = false; pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage); string tit = "���������� ����������/��������� \n�� ������ � "+MyDateSpan.start.ToShortDateString() + " �� " + MyDateSpan.end.ToShortDateString() + "."; prin = new DataGridViewPrinter(Statistics, pd, true, true, tit, new Font("Tahoma", 18), Color.Black, false); pd.Print(); } else { //����������� ���������� ListSortDirection SO = ListSortDirection.Ascending; dgw2 = new DataGridView(); //DataGridViewRow[] arr = new DataGridViewRow[Statistics.SelectedRows.Count]; DataGridViewColumn[] arr1 = new DataGridViewColumn[Statistics.Columns.Count]; //Statistics.SelectedRows.CopyTo(arr, 0); Statistics.Columns.CopyTo(arr1, 0); dgw2.AutoGenerateColumns = false; dgw2.Columns.Clear(); dgw2.Font = new Font("Times New Roman", 10); //dgw2.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; //dgw2.RowTemplate.DefaultCellStyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True; //dgw2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; dgw2.AllowUserToAddRows = false; //dgw2.Columns.AddRange(arr1); foreach (DataGridViewColumn col in arr1) { //dgw2.Columns.Add((DataGridViewColumn)col.Clone()); dgw2.Columns.Add("",""); } int i = 0; for (int ri = 0; ri < Statistics.Rows.Count; ri++) { dgw2.Rows.Add();// (DataGridViewRow)Statistics.SelectedRows[ri].Clone(); DataGridViewRow clonedRow = dgw2.Rows[i]; for (Int32 index = 0; index < Statistics.Rows[ri].Cells.Count; index++) { dgw2.Rows[i].Cells[index].Value = Statistics.Rows[ri].Cells[index].Value; } //dgw2.Rows.Add(clonedRow); i++; } dgw2.AutoSize = false; dgw2.RowTemplate.DefaultCellStyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dgw2.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.True; dgw2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dgw2.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; //Statistics.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; dgw2.Columns[0].Width = 35; dgw2.Columns[1].Width = 470; dgw2.Columns[2].Width = 215; dgw2.Columns[2].Visible = true; dgw2.Columns[3].Width = 70; dgw2.Columns[4].Visible = false; dgw2.Columns[5].Visible = false; dgw2.Columns[6].Visible = false; dgw2.Columns[7].Width = 70; dgw2.Columns[8].Width = 100; dgw2.Columns[9].Visible = false; dgw2.Columns[10].Width = 70; dgw2.Columns[11].Width = 70; dgw2.Columns[1].HeaderText = "��������"; dgw2.Columns[2].HeaderText = "�����"; dgw2.Columns[3].HeaderText = "���. �����"; dgw2.Columns[4].HeaderText = "��������������"; dgw2.Columns[7].HeaderText = "����� ������"; dgw2.Columns[8].HeaderText = "���"; dgw2.Columns[10].HeaderText = "���� ������"; dgw2.Columns[10].ValueType = typeof(DateTime); dgw2.Columns[11].HeaderText = "���� ��������"; if (Statistics.SortedColumn != null) { if (Statistics.Columns[Statistics.SortedColumn.Index].HeaderCell.SortGlyphDirection == System.Windows.Forms.SortOrder.Ascending) { SO = ListSortDirection.Ascending; } if (Statistics.Columns[Statistics.SortedColumn.Index].HeaderCell.SortGlyphDirection == System.Windows.Forms.SortOrder.Descending) { SO = ListSortDirection.Descending; } dgw2.Sort(dgw2.Columns[Statistics.SortedColumn.Index], SO); } //dgw2 autoinc(dgw2); if (SetupThePrinting()) pd.Print(); } }