Permalink
Browse files

增加按晶锭统计数量

  • Loading branch information...
1 parent e32802d commit 22b782b56f1999306b0d0887748a2f467e7bc846 Advansil committed Apr 20, 2012
Showing with 117 additions and 54 deletions.
  1. +23 −13 ExcelApplication/ExcelApplication/Form1.Designer.cs
  2. +94 −41 ExcelApplication/ExcelApplication/Form1.cs

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -19,65 +19,99 @@ public bool dataTotal(int col)
{
try
{
- dataGridView1.Sort(dataGridView1.Columns[col], ListSortDirection.Ascending);
+ if (col == 2 || col == 3 || col == 4 || col == 5)
+ {
+ dataGridView1.Sort(dataGridView1.Columns[col], ListSortDirection.Ascending);
- int columnCount = dataGridView1.ColumnCount;
- int rowCount = dataGridView1.RowCount;
+ int columnCount = dataGridView1.ColumnCount;
+ int rowCount = dataGridView1.RowCount;
- string tempA = (string)dataGridView1.Rows[rowCount - 2].Cells[col].Value;
- string tempB;
- int total = 0;
- for (int i = rowCount - 3; i >= 0; i--)
- {
- tempB = (string)dataGridView1.Rows[i].Cells[col].Value;
- if (tempA.GetHashCode() == tempB.GetHashCode())
+ string tempA = (string)dataGridView1.Rows[rowCount - 2].Cells[col].Value;
+ string tempB;
+ int total = 0;
+ for (int i = rowCount - 3; i >= 0; i--)
{
- for (int j = 6; j < 12; j++)
+ tempB = (string)dataGridView1.Rows[i].Cells[col].Value;
+ if (tempA.GetHashCode() == tempB.GetHashCode())
{
- if (j == 7) continue;
- total = int.Parse(dataGridView1.Rows[i].Cells[j].Value.ToString()) + int.Parse(dataGridView1.Rows[i + 1].Cells[j].Value.ToString());
- dataGridView1.Rows[i].Cells[j].Value = total.ToString();
+ for (int j = 6; j < 12; j++)
+ {
+ if (j == 7) continue;
+ total = int.Parse(dataGridView1.Rows[i].Cells[j].Value.ToString()) + int.Parse(dataGridView1.Rows[i + 1].Cells[j].Value.ToString());
+ dataGridView1.Rows[i].Cells[j].Value = total.ToString();
+ }
+ for (int j = 12; j < 50; j += 2)
+ {
+ if (j == 50) continue;
+ total = int.Parse(dataGridView1.Rows[i].Cells[j].Value.ToString()) + int.Parse(dataGridView1.Rows[i + 1].Cells[j].Value.ToString());
+ dataGridView1.Rows[i].Cells[j].Value = total.ToString();
+ }
+ dataGridView1.Rows.RemoveAt(i + 1);
}
- for (int j = 12; j < 50; j += 2)
+ else
{
- if (j == 50) continue;
- total = int.Parse(dataGridView1.Rows[i].Cells[j].Value.ToString()) + int.Parse(dataGridView1.Rows[i + 1].Cells[j].Value.ToString());
- dataGridView1.Rows[i].Cells[j].Value = total.ToString();
+ tempA = tempB;
}
- dataGridView1.Rows.RemoveAt(i + 1);
}
- else
+
+ columnCount = dataGridView1.ColumnCount;
+ rowCount = dataGridView1.RowCount;
+
+ for (int j = 0; j < rowCount - 1; j++)
{
- tempA = tempB;
+ int tempD = int.Parse(dataGridView1.Rows[j].Cells[6].Value.ToString());
+ int tempC = int.Parse(dataGridView1.Rows[j].Cells[12].Value.ToString());
+ if (tempD == 0)
+ dataGridView1.Rows[j].Cells[13].Value = "0";
+ else
+ dataGridView1.Rows[j].Cells[13].Value = (tempC * 10000 / tempD / 100.0).ToString();
}
- }
- columnCount = dataGridView1.ColumnCount;
- rowCount = dataGridView1.RowCount;
-
- for (int j = 0; j < rowCount - 1; j++)
- {
- int tempD = int.Parse(dataGridView1.Rows[j].Cells[6].Value.ToString());
- int tempC = int.Parse(dataGridView1.Rows[j].Cells[12].Value.ToString());
- if (tempD == 0)
- dataGridView1.Rows[j].Cells[13].Value = "0";
- else
- dataGridView1.Rows[j].Cells[13].Value = (tempC * 10000 / tempD / 100.0).ToString();
+ for (int i = 15; i < 50; i += 2)
+ {
+ for (int j = 0; j < rowCount - 1; j++)
+ {
+ int tempD = int.Parse(dataGridView1.Rows[j].Cells[9].Value.ToString());
+ int tempC = int.Parse(dataGridView1.Rows[j].Cells[i - 1].Value.ToString());
+ if (tempD == 0)
+ dataGridView1.Rows[j].Cells[i].Value = "0";
+ else
+ dataGridView1.Rows[j].Cells[i].Value = (tempC * 10000 / tempD / 100.0).ToString();
+ }
+ }
+ return true;
}
- for (int i = 15; i < 50; i += 2)
+ if (col == 999)
{
- for (int j = 0; j < rowCount - 1; j++)
+ dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Descending);
+
+ int columnCount = dataGridView1.ColumnCount;
+ int rowCount = dataGridView1.RowCount;
+
+ string tempA = (string)dataGridView1.Rows[rowCount - 2].Cells[0].Value;
+ string tempB;
+ int total = 0;
+ for (int i = rowCount - 3; i >= 0; i--)
{
- int tempD = int.Parse(dataGridView1.Rows[j].Cells[9].Value.ToString());
- int tempC = int.Parse(dataGridView1.Rows[j].Cells[i - 1].Value.ToString());
- if (tempD == 0)
- dataGridView1.Rows[j].Cells[i].Value = "0";
+ tempB = (string)dataGridView1.Rows[i].Cells[0].Value;
+ if (tempA.GetHashCode() == tempB.GetHashCode())
+ {
+ for (int j = 4; j < 6; j++)
+ {
+ total = int.Parse(dataGridView1.Rows[i].Cells[j].Value.ToString()) + int.Parse(dataGridView1.Rows[i + 1].Cells[j].Value.ToString());
+ dataGridView1.Rows[i].Cells[j].Value = total.ToString();
+ }
+ dataGridView1.Rows.RemoveAt(i + 1);
+ }
else
- dataGridView1.Rows[j].Cells[i].Value = (tempC * 10000 / tempD / 100.0).ToString();
+ {
+ tempA = tempB;
+ }
}
+ return true;
}
- return true;
+ return false;
}
catch (Exception ex)
{
@@ -183,6 +217,18 @@ private void btnLoadData_Click(object sender, EventArgs e)
}
dataGridView1.Columns[2].HeaderCell.Value = "铸锭编号";
}
+
+ if (dataGridView1.Columns[3].HeaderCell.Value.GetHashCode() == "塑料盒号".GetHashCode())
+ {
+ string[] rowValue = new string[dataGridView1.RowCount];
+ for (int i = 0; i < rowCount - 1; i++)
+ {
+ rowValue[i] = (string)dataGridView1.Rows[i].Cells[3].Value;
+ rowValue[i] = rowValue[i].TrimStart('M');
+ dataGridView1.Rows[i].Cells[0].Value = (rowValue[i].Length > 6) ? rowValue[i].Substring(0, 6) : rowValue[i];
+ }
+ dataGridView1.Columns[0].HeaderCell.Value = "晶锭编号";
+ }
}
catch (Exception ex)
{
@@ -339,6 +385,13 @@ private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
private void txtColumn_TextChanged(object sender, EventArgs e)
{
btnLoadData.Enabled = true;
+ }
+
+ private void boxToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ int selectCol = 999;
+ if (dataTotal(selectCol))
+ MessageBox.Show("Processed Data Success!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

0 comments on commit 22b782b

Please sign in to comment.