private void dataGridView1_CellContentClick(object sender, KeyEventArgs e) { dataGridView1.Columns[2].DefaultCellStyle.Format = "N0"; dataGridView1.Columns[5].DefaultCellStyle.Format = "N0"; dataGridView1.Columns[6].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGridView1.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGridView1.Columns[5].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGridView1.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; if (e.KeyCode == Keys.F2) { vorur gl4 = new vorur(); //gl4.Foreldri1 = this; if (gl4.ShowDialog() == DialogResult.OK) { dataGridView1.CurrentRow.Cells[0].Value = gl4.valid; dataGridView1.CurrentRow.Cells[1].Value = gl4.lysing; dataGridView1.CurrentRow.Cells[2].Value = Convert.ToInt32(gl4.einverd); l_vsk[dataGridView1.CurrentRow.Index] = gl4.vsk; lina_vskf[dataGridView1.CurrentRow.Index] = gl4.vskf; } gl4.Close(); } if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab) { int n = 0; double lafsl = 0; usamtals = 0; u1vsk = 0; u2vsk = 0; uafsl = 0; while (n < dataGridView1.RowCount) { if (Convert.ToString(dataGridView1.Rows[n].Cells[0].Value) != "" && Convert.ToString(dataGridView1.Rows[n].Cells[1].Value) == "") { MySqlConnection connection = new MySqlConnection(MetSala.MyConString); MySqlCommand command = connection.CreateCommand(); MySqlDataReader Reader; connection.Open(); //command.CommandText = "select vnafn,verd from vorur WHERE vitem = '"+dataGridView1.CurrentRow.Cells[0].Value+"'"; command.CommandText = "vorurvsk"; command.CommandType = CommandType.StoredProcedure; //Þarf að sækja id eftir að búið er að velja vskm command.Parameters.Add("?spr", dataGridView1.CurrentRow.Cells[0].Value); command.Parameters["?spr"].Direction = ParameterDirection.Input; Reader = command.ExecuteReader(); while (Reader.Read()) { dataGridView1.CurrentRow.Cells[1].Value = Reader.GetString(0); dataGridView1.CurrentRow.Cells[2].Value = Reader.GetString(1); l_vsk[dataGridView1.CurrentRow.Index] = Reader.GetFloat(2); lina_vskf[dataGridView1.CurrentRow.Index] = Reader.GetString(3); } Reader.Close(); connection.Close(); } if (Convert.ToString(dataGridView1.Rows[n].Cells[3].Value) != "") { // Hér er verðið sett inn ein verð * magn - afsl sem er i prósentu lafsl = ((Convert.ToDouble(dataGridView1.Rows[n].Cells[2].Value) * (Convert.ToDouble(dataGridView1.Rows[n].Cells[3].Value)) * (Convert.ToDouble(dataGridView1.Rows[n].Cells[4].Value) / 100))); dataGridView1.Rows[n].Cells[5].Value = (Convert.ToDouble(dataGridView1.Rows[n].Cells[2].Value) * (Convert.ToDouble(dataGridView1.Rows[n].Cells[3].Value)) - lafsl); //Cells 0 ITEM - 1 Texti - 2 verð - 3 magn - 4 afsl - 5 samtals - 6 samtals + vsk - 7 vask flokkur vsk_f //usamtals er upphæð á nótu samtals án vsk usamtals = Math.Round(usamtals + Convert.ToInt32(dataGridView1.Rows[n].Cells[5].Value), 0); //Hér er síðan reiknað út verð á línu með vsk l_vsk[númerlínu] hefur að geyma vask % dataGridView1.Rows[n].Cells[6].Value = (Convert.ToInt32(dataGridView1.Rows[n].Cells[5].Value) * (1 + (l_vsk[n] / 100))).ToString("N0"); //Hér þarf að fá samtals upphæð vsk pr. línu if (l_vsk[n] == 25.5D) { sl1_vsk[n] = Convert.ToDouble(dataGridView1.Rows[n].Cells[5].Value) * (l_vsk[n] / 100); } else { sl2_vsk[n] = Convert.ToDouble(dataGridView1.Rows[n].Cells[5].Value) * (l_vsk[n] / 100); } //Vask upphæð á nótu verður á línuupphæð summeruð u1vsk = Math.Round(u1vsk + sl1_vsk[n]); u2vsk = Math.Round(u2vsk + sl2_vsk[n]); s1vsk.Text = u1vsk.ToString("N0"); s2vsk.Text = u2vsk.ToString("N0"); sanvsk.Text = usamtals.ToString("N0"); sl_vsk[n] = sl1_vsk[n] + sl2_vsk[n]; smvsk.Text = (usamtals + u1vsk + u2vsk).ToString("N0"); uafsl = uafsl + Convert.ToDouble(dataGridView1.Rows[n].Cells[5].Value) - ((Convert.ToDouble(dataGridView1.Rows[n].Cells[2].Value) * Convert.ToDouble(dataGridView1.Rows[n].Cells[3].Value))); textAfsl.Text = uafsl.ToString("N0"); } n++; } } }
private void dataGridView1_CellContentClick(object sender, KeyEventArgs e) { dataGridView1.Columns[2].DefaultCellStyle.Format = "N0"; dataGridView1.Columns[5].DefaultCellStyle.Format = "N0"; //dataGridView1.Columns[6].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGridView1.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGridView1.Columns[5].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGridView1.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; if (e.KeyCode == Keys.F2) { vorur gl4 = new vorur(); //gl4.Foreldri1 = this; if (gl4.ShowDialog() == DialogResult.OK) { dataGridView1.CurrentRow.Cells[0].Value = gl4.valid; dataGridView1.CurrentRow.Cells[1].Value = gl4.lysing; dataGridView1.CurrentRow.Cells[2].Value = Convert.ToInt32(gl4.einverd); lina_vskp[dataGridView1.CurrentRow.Index] = gl4.vsk; lina_vskf[dataGridView1.CurrentRow.Index] = gl4.vskf; } gl4.Close(); } if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab) { // Ef vörunúmer ekki tómt og Vörunafn er tómt if (Convert.ToString(dataGridView1.CurrentRow.Cells[0].Value) != "") //if (Convert.ToString(dataGridView1.Rows[n].Cells[0].Value) != "" && Convert.ToString(dataGridView1.Rows[n].Cells[1].Value) == "") { MySqlConnection connection = new MySqlConnection(MetSala.MyConString); MySqlCommand command = connection.CreateCommand(); MySqlDataReader Reader; connection.Open(); //command.CommandText = "select vnafn,verd from vorur WHERE vitem = '"+dataGridView1.CurrentRow.Cells[0].Value+"'"; command.CommandText = "vorurvsk"; command.CommandType = CommandType.StoredProcedure; //Þarf að sækja id eftir að búið er að velja vskm command.Parameters.Add("?spr", dataGridView1.CurrentRow.Cells[0].Value); command.Parameters["?spr"].Direction = ParameterDirection.Input; Reader = command.ExecuteReader(); while (Reader.Read()) { dataGridView1.CurrentRow.Cells[1].Value = Reader.GetString(0); if (Convert.ToString(dataGridView1.CurrentRow.Cells[2].Value) == "") { dataGridView1.CurrentRow.Cells[2].Value = Reader.GetDouble(1); } lina_vskp[dataGridView1.CurrentRow.Index] = Reader.GetFloat(2); lina_vskf[dataGridView1.CurrentRow.Index] = Reader.GetString(3); } Reader.Close(); connection.Close(); } if (Convert.ToString(dataGridView1.CurrentRow.Cells[3].Value) != "") //Ef magn er ekki tómt { // Hér er verðið sett inn ein verð * magn - afsl sem er i prósentu lina_afsl[dataGridView1.CurrentRow.Index] = ((Convert.ToDouble(dataGridView1.CurrentRow.Cells[2].Value) * ((Convert.ToDouble(dataGridView1.CurrentRow.Cells[3].Value))) * (Convert.ToDouble(dataGridView1.CurrentRow.Cells[4].Value) / 100))); dataGridView1.CurrentRow.Cells[5].Value = (Convert.ToDouble(dataGridView1.CurrentRow.Cells[2].Value) * (Convert.ToDouble(dataGridView1.CurrentRow.Cells[3].Value)) - lina_afsl[dataGridView1.CurrentRow.Index]); //Cells 0 ITEM - 1 Texti - 2 verð - 3 magn - 4 afsl - 5 samtals - 6 samtals + vsk - 7 vask flokkur vsk_f //usamtals er upphæð á nótu samtals án vsk // Margeir usamtals = usamtals + Convert.ToInt32(dataGridView1.CurrentRow.Cells[5].Value); //Hér er síðan reiknað út verð á línu með vsk l_vsk[númerlínu] hefur að geyma vask % //Ekki verið að sýna það hér en þarf að reikan og hafa //dataGridView1.Rows[n].Cells[6].Value = (Convert.ToInt32(dataGridView1.Rows[n].Cells[5].Value) * (1 + (l_vsk[n] / 100))).ToString("N0"); //Hér þarf að fá samtals upphæð vsk pr. línu if (lina_vskf[dataGridView1.CurrentRow.Index] == "S1") { sl_vsk1[dataGridView1.CurrentRow.Index] = (Convert.ToDouble(dataGridView1.CurrentRow.Cells[5].Value) * (lina_vskp[dataGridView1.CurrentRow.Index]) / 100); reportData.Text = lina_vskp[dataGridView1.CurrentRow.Index].ToString() + "|" + sl_vsk1[dataGridView1.CurrentRow.Index] + " | " + dataGridView1.CurrentRow.Index; } else { sl_vsk2[dataGridView1.CurrentRow.Index] = Convert.ToDouble(dataGridView1.CurrentRow.Cells[5].Value) * (lina_vskp[dataGridView1.CurrentRow.Index] / 100); reportData.Text = lina_vskp[dataGridView1.CurrentRow.Index].ToString(); } } } if (e.KeyCode == Keys.F4) { int t = 0; double samtals = 0; double vsk1 = 0; double vsk2 = 0; double afsl = 0; while (t < dataGridView1.RowCount) { samtals = samtals + Math.Round(Convert.ToDouble(dataGridView1.Rows[t].Cells[5].Value), 0); vsk1 = vsk1 + Math.Round(sl_vsk1[t], 0); vsk2 = vsk2 + Math.Round(sl_vsk2[t], 0); afsl = afsl + Math.Round(lina_afsl[t], 0); tsamtals.Text = samtals.ToString("N0"); t1vsk.Text = vsk1.ToString("N0"); t2vsk.Text = vsk2.ToString("N0"); textafsl.Text = afsl.ToString("N0"); tmvsk.Text = (samtals + vsk1 + vsk2).ToString("N0"); t++; } } if (e.KeyCode == Keys.F5) { double vsk1 = 0; double vsk2 = 0; MySqlConnection connection = new MySqlConnection(MetSala.MyConString); MySqlCommand command = connection.CreateCommand(); //MySqlDataReader Reader; connection.Open(); command.CommandText = "DELETE FROM sam_item WHERE id_reikn = '" + vnum + "'"; command.ExecuteNonQuery(); for (int i = 0; i < (dataGridView1.Rows.Count); i++) { if (dataGridView1.Rows[i].Cells[0].Value == null) { break; } double lverd = Convert.ToDouble(dataGridView1[2, i].Value); double sl_verd = Convert.ToDouble(dataGridView1[5, i].Value); double tlvsk = sl_vsk1[i] + sl_vsk2[i]; vsk1 = vsk1 + sl_vsk1[i]; vsk2 = vsk2 + sl_vsk2[i]; command.Parameters.Add("?qty", Convert.ToDouble(dataGridView1[3, i].Value)); command.Parameters.Add("?lafsl", Convert.ToDouble(dataGridView1[4, i].Value)); command.CommandText = "INSERT INTO sam_item (id,id_reikn,lysing,item,qty,uverd,verd,vsk,lafsl,vfl) VALUES (NULL,'" + vnum + "','" + (string)dataGridView1[1, i].Value + "','" + (string)dataGridView1[0, i].Value + "',?qty,'" + lverd + "','" + Math.Round(sl_verd) + "','" + Math.Round(tlvsk) + "',?lafsl,'" + lina_vskf[i] + "')"; command.ExecuteNonQuery(); command.Parameters.Clear(); } command.CommandText = "UPDATE samningar SET stofnd='" + DateTime.Now.ToString("yyyy:MM:dd") + "', samtals='" + Convert.ToDouble(tsamtals.Text) + "', afsl='" + Convert.ToDouble(textafsl.Text) + "', vsk1='" + Math.Round(vsk1) + "', vsk2='" + Math.Round(vsk2) + "',texti='" + rhaus1.Text + "' WHERE id = " + vnum + ""; command.ExecuteNonQuery(); } }