// Where the magic happens private void updateStuff() { string userId = textBox1.Text.ToUpper(); lastId = userId; if (userId.Equals("")) { return; } //find Airman SqlCommand command = new SqlCommand("SELECT * FROM [dbo].[Airmen] WHERE [barcode] = '" + userId + "'", con); con.Open(); SqlDataReader reader = command.ExecuteReader(); try { string name = null; string room = null; string mtl = null; string barcode = null; string shift = null; bool boolIn = false; while (reader.Read()) { name = reader["name"].ToString(); room = reader["room"].ToString(); mtl = reader["mtl"].ToString(); barcode = reader["barcode"].ToString(); shift = reader["shift"].ToString(); boolIn = bool.Parse(reader["inHouse"].ToString()); } con.Close(); if (name == null) { //No airman found return; } lastAirman = new Airman(name, room, mtl, barcode, shift, boolIn); //Airman was in state boolIn, now flip it in scans table bool currIn = !boolIn; // Update labels labelName.Text = name; labelRoom.Text = lastAirman.Room; labelShift.Text = lastAirman.Shift; string dateString = String.Format("{0:MM/dd/yy HH:mm}", DateTime.Now); // 08/21/17 16:40 int irow = -1; if (dataGridView1.Rows.Count > 0) { DataGridViewCell bc = null; for (int i = 0; i < dataGridView1.Rows.Count; i++) { bc = dataGridView1.Rows[i].Cells[0]; if (bc.Value.ToString().ToUpper().Equals(barcode.ToUpper())) { irow = i; break; } } } if (irow < 0) { //No row in the db, add it // Add info to data grid view DataGridViewRow row = new DataGridViewRow(); string inOut = (currIn ? "In" : "Out"); row.CreateCells(dataGridView1); row.Cells[0].Value = barcode; row.Cells[1].Value = name; //Name row.Cells[2].Value = lastAirman.Room; //Room row.Cells[3].Value = lastAirman.Shift; //Transition row.Cells[4].Value = inOut; //Status row.Cells[5].Value = dateString; //Time dataGridView1.Rows.Insert(0, row); } else { // Remove row from table, change values, and add it to the top DataGridViewRow dgRow = dataGridView1.Rows[irow]; string inOut = (currIn ? "In" : "Out"); dgRow.Cells[4].Value = inOut; dgRow.Cells[5].Value = dateString; dataGridView1.Rows.RemoveAt(irow); dataGridView1.Rows.Insert(0, dgRow); } // Now save info to database in scans table int saveIn = 0; if (currIn) { saveIn = 1; } string statement = "INSERT INTO [dbo].[Scans] (barcode, inHouse, time) VALUES("; statement += "'" + userId + "', "; statement += saveIn + ", "; statement += "'" + dateString + "');"; executeSQLCommand(statement); //Update in/out status in airmen table statement = "UPDATE [dbo].[Airmen] SET inHouse = " + saveIn + " WHERE barcode = '" + userId + "'; "; executeSQLCommand(statement); } finally { // Always call Close when done reading. reader.Close(); } // Clear textbox textBox1.Text = ""; }
private void UpdateStepList() { if (MainForm.Instance.ProjectObj != null) { KeTiList = ConnectionManager.Context.table("Project").where ("Type='" + "课题" + "' and ParentID='" + MainForm.Instance.ProjectObj.ID + "'").select("*").getList <Project>(new Project()); StepList = ConnectionManager.Context.table("Step").where ("ProjectID in (select ID from Project where Type='" + "课题" + "' and ParentID='" + MainForm.Instance.ProjectObj.ID + "')").select("*").getList <Step>(new Step()); if (StepList != null && KeTiList != null && StepList.Count >= 1 && KeTiList.Count >= 1) { //数据行列表,先生成然后等待排序 List <DataGridViewRow> rowList = new List <DataGridViewRow>(); int indexx = 0; foreach (Step step in StepList) { ProjectAndStep projectAndStep = ConnectionManager.Context.table("ProjectAndStep").where ("StepID='" + step.ID + "'").select("*").getItem <ProjectAndStep>(new ProjectAndStep()); Project ketiProject = null; foreach (Project pp in KeTiList) { if (pp.ID != null && pp.ID.Equals(step.ProjectID)) { ketiProject = pp; break; } } if (ketiProject == null || projectAndStep == null) { continue; } indexx++; List <object> cells = new List <object>(); cells.Add(indexx + ""); cells.Add(ketiProject.Name); cells.Add(step.StepIndex); cells.Add(projectAndStep.StepDest); cells.Add(projectAndStep.StepContent); cells.Add(projectAndStep.StepResult); cells.Add(projectAndStep.StepTarget); cells.Add(projectAndStep.Money); DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow.CreateCells(dgvDetail, cells.ToArray()); dgvRow.Tag = step; rowList.Add(dgvRow); } foreach (DataGridViewColumn col in dgvDetail.Columns) { col.SortMode = DataGridViewColumnSortMode.NotSortable; } dgvDetail.Rows.Clear(); foreach (IGrouping <object, DataGridViewRow> group in rowList.GroupBy(x => x.Cells[1].Value)) { foreach (DataGridViewRow student in group.OrderBy(a => (int)a.Cells[2].Value))//不排序直接输出的话:Student student in group { dgvDetail.Rows.Add(student); } } } } }
private void btnPesquisa_Click(object sender, EventArgs e) { if (Validacoes()) { CreaterCursor Cr = new CreaterCursor(); this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0); try { RowRelatorio.Clear(); string DataInicial = Util.ConverStringDateSearch(msktDataInicial.Text); string DataFinal = Util.ConverStringDateSearch(msktDataFinal.Text); RowRelatorio.Add(new RowsFiltro("DATAEMISSAO", "System.DateTime", ">=", DataInicial, "and")); RowRelatorio.Add(new RowsFiltro("DATAEMISSAO", "System.DateTime", "<=", DataFinal, "and")); if (rbOrcamentoPesquisa.Checked) { RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "S", "and")); } if (rbVendasPesquisa.Checked) { RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "N", "and")); } RowRelatorio.Add(new RowsFiltro("IDFUNCIONARIO", "System.Int32", "=", Convert.ToInt32(cbFuncionario.SelectedValue).ToString(), "and")); DataGriewDados.Rows.Clear(); TotalGeral = 0; TotalGeralComissao = 0; LIS_PRODUTOOSFECHColl.Clear(); LIS_SERVICOOSFECHColl.Clear(); if (chkProduto.Checked) { LIS_PRODUTOOSFECHColl = LIS_PRODUTOOSFECHP.ReadCollectionByParameter(RowRelatorio, "IDORDEMSERVICO DESC"); lblTotalRegistros.Text = "Total de Registros: " + LIS_PRODUTOOSFECHColl.Count.ToString(); PreencheGridProduto(); } if (ChkServiço.Checked) { LIS_SERVICOOSFECHColl = LIS_SERVICOOSFECHP.ReadCollectionByParameter(RowRelatorio, "IDORDEMSERVICO DESC"); lblTotalRegistros.Text = "Total de Registros: " + (LIS_SERVICOOSFECHColl.Count + LIS_PRODUTOOSFECHColl.Count).ToString(); PreencheGridServico(); } DataGriewDados.Sort(DataGriewDados.Columns["ordemservico"], ListSortDirection.Descending); DataGridViewRow row3 = new DataGridViewRow(); row3.CreateCells(DataGriewDados, "", "", "Total Geral:", TotalGeral.ToString("n2"), TotalGeralComissao.ToString("n2")); row3.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row3); this.Cursor = Cursors.Default; } catch (Exception EX) { this.Cursor = Cursors.Default; MessageBox.Show("Erro na pesquisa!"); MessageBox.Show("Erro técnico: " + EX.Message); } } }
private void ShowMessages(List <ViewerHelper.Data.MailAPI.Message> messages) { // Show all messages in List. try { foreach (var item in messages) { // Add new row. string rowReceivedDateTime = item.ReceivedDateTime ?? ""; string rowCreatedDateTime = item.CreatedDateTime ?? ""; string rowSentDateTime = item.SentDateTime ?? ""; string subject = item.Subject ?? ""; string sender = (item.Sender != null && item.Sender.EmailAddress != null && item.Sender.EmailAddress.Address != null) ? item.Sender.EmailAddress.Address : ""; string recipients = (item.ToRecipients != null) ? ConvertRecipientsListToString(item.ToRecipients) : ""; string isDraft = (item.IsDraft != null && item.IsDraft.HasValue) ? item.IsDraft.Value.ToString() : ""; if (DateTime.TryParse(rowReceivedDateTime, out DateTime receivedDateTime) == false) { receivedDateTime = DateTime.MinValue; } if (DateTime.TryParse(rowCreatedDateTime, out DateTime createdDateTime) == false) { createdDateTime = DateTime.MinValue; } if (DateTime.TryParse(rowSentDateTime, out DateTime sentDateTime) == false) { sentDateTime = DateTime.MinValue; } DataGridViewRow itemRow = new DataGridViewRow { Tag = item.Id }; itemRow.CreateCells(dataGridView_ItemList, new object[] { subject, sender, recipients, receivedDateTime, createdDateTime, sentDateTime }); if (item.IsDraft != null && item.IsDraft.HasValue && item.IsDraft.Value == true) { // This item is draft. itemRow.ContextMenuStrip = contextMenuStrip_ItemList_DraftItem; } else { // This item is not draft. itemRow.ContextMenuStrip = contextMenuStrip_ItemList; } if (dataGridView_ItemList.InvokeRequired) { dataGridView_ItemList.Invoke(new MethodInvoker(delegate { dataGridView_ItemList.Rows.Add(itemRow); })); } else { dataGridView_ItemList.Rows.Add(itemRow); } } } catch (InvalidOperationException ex) { if (isFormClosing) { // It seems that this window was closed. // Do nothing. } else { MessageBox.Show(ex.Message, "Office365APIEditor"); } } catch (Exception ex) { MessageBox.Show(ex.GetType().FullName + "\r\n" + ex.Message, "Office365APIEditor"); } }
private void UpdateTable() { orgContData.Rows.Clear(); var sql = new Model(); var allContainers = sql.FindinTable <OrganizationContainer>("Organization", Org.Id.ToString()); var allPlatforms = new List <Platform>(); var allConTypes = sql.FindinTable <ContainerType>(); foreach (var value in allContainers) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(orgContData); if (allPlatforms.All(pt => pt.Id != value.Platform)) { allPlatforms.Add(sql.FindinTable <Platform>((int)value.Platform).FirstOrDefault()); } row.Cells[0].Value = value.Id; row.Cells[1].Value = allConTypes.Find(ac => ac.Id == value.Container).Name; row.Cells[2].Value = allPlatforms.Find(ap => ap.Id == value.Platform).Address; var schedulValue = String.Empty; if (!String.IsNullOrEmpty(value.Schedule)) { var scheduleValues = value.Schedule.Split(';'); foreach (var tempValue in scheduleValues) { switch (tempValue) { case "1": schedulValue = schedulValue + "ПН, "; break; case "2": schedulValue = schedulValue + "ВТ, "; break; case "3": schedulValue = schedulValue + "СР, "; break; case "4": schedulValue = schedulValue + "ЧТ, "; break; case "5": schedulValue = schedulValue + "ПТ, "; break; case "6": schedulValue = schedulValue + "СБ, "; break; case "7": schedulValue = schedulValue + "ВС, "; break; } } } if (!String.IsNullOrEmpty(schedulValue)) { schedulValue = schedulValue.Substring(0, schedulValue.Length - 2); } row.Cells[3].Value = schedulValue; orgContData.Rows.Add(row); } }