private void button3_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Selected) { try { int selectedId = Convert.ToInt32(row.Cells[0].Value.ToString()); using (var ctx = new ItemContext()) { ItemOutbound it = ctx.ItemOutbounds.Where(id => id.ItemOutboundId == selectedId).First <ItemOutbound>(); ctx.ItemOutbounds.Remove(it); ctx.SaveChanges(); MessageBox.Show("Delete successfully."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } fillBy1ToolStripButton_Click(this, e); }
private void button1_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Selected) { try { using (var ctx = new ItemContext()) { ItemOutbound it = new ItemOutbound(); it.ItemOutboundId = Convert.ToInt32(row.Cells[0].Value.ToString()); it.isDelete = false; ctx.ItemOutbounds.Attach(it); ctx.Entry(it).State = System.Data.Entity.EntityState.Unchanged; ctx.Entry(it).Property(p => p.isDelete).IsModified = true; ctx.SaveChanges(); MessageBox.Show("Restore successfully."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } fillBy1ToolStripButton_Click(this, e); }
private void button1_Click(object sender, EventArgs e) { if (itemTitile.Text.Length != 0 && SN.Text.Length != 0 && date.Text.Length != 0 && TrackingNumLabel.Text.Length != 0) { try { //determine editors using (var ctx = new ItemContext()) { ItemOutbound itemOutbound = ctx.ItemOutbounds.Where(u => u.ItemOutboundId == itemOutboundId).FirstOrDefault(); itemOutbound.ItemTitle = itemTitile.Text; itemOutbound.Date = Convert.ToDateTime(date.Text); itemOutbound.Qty = Convert.ToInt32(Qty.Text); itemOutbound.SN = SN.Text; itemOutbound.TrackingNum = TrackingNum.Text; ctx.Entry(itemOutbound).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); MessageBox.Show("Successfully updated!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void OutboundModify_Load(object sender, EventArgs e) { try { using (var ctx = new ItemContext()) { ItemOutbound itemOutbound = ctx.ItemOutbounds.Find(itemOutboundId); TrackingNum.Text = itemOutbound.TrackingNum; itemTitile.Text = itemOutbound.ItemTitle; date.Text = itemOutbound.Date.ToString(); Qty.Text = itemOutbound.Qty.ToString(); SN.Text = itemOutbound.SN; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { if (itemTitile.Text.Trim().Length != 0 && TrackingNum.Text.Trim().Length != 0 && SN.Text.Trim().Length != 0) { try { using (var ctx = new ItemContext()) { DateTime timeLimit = DateTime.Now.AddDays(-3); var itemExist = ctx.ItemOutbounds.Where(x => x.TrackingNum == TrackingNum.Text.Trim()).Where(time => DateTime.Compare(time.Date, timeLimit) > 0).ToList(); if (itemExist.Count > 0) { if (MessageBox.Show("The tracking number has been used in recent 3 days.", "Do you want to continue?", MessageBoxButtons.YesNo) == DialogResult.Yes) { } else { return; } } ItemOutbound IO = new ItemOutbound() { ItemTitle = itemTitile.Text.Trim(), TrackingNum = TrackingNum.Text.Trim(), Date = Convert.ToDateTime(date.Text.ToString()), Qty = Convert.ToInt32(Qty.Text), Manipulator = manipulator, SN = SN.Text.Trim(), isDelete = false }; ctx.ItemOutbounds.Add(IO); ctx.SaveChanges(); } MessageBox.Show("Record successfully added!"); SN.Text = ""; TrackingNum.Text = ""; date.Value = DateTime.Now; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("itemTitile, TrackingNum, SN cannot be null."); } }
private void Delete_Click(object sender, EventArgs e) { bool del = false; bool select = false; int indexDelete = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { if (Convert.ToBoolean(row.Cells["Selected"].Value)) { select = true; } } if (select) { if (MessageBox.Show("This record will be deleted!", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (Convert.ToBoolean(row.Cells["Selected"].Value)) { int idDelete = Convert.ToInt32(row.Cells["ItemOutboundId"].Value.ToString()); indexDelete = indexDelete == 0 ? row.Index - 1 : indexDelete; //string trackingDelete = row.Cells["TrackingNum"].Value.ToString(); try { using (var ctx = new ItemContext()) { ItemOutbound itemOutboundDel = new ItemOutbound(); itemOutboundDel.ItemOutboundId = idDelete; itemOutboundDel.isDelete = true; ctx.ItemOutbounds.Attach(itemOutboundDel); ctx.Entry(itemOutboundDel).Property(x => x.isDelete).IsModified = true; ctx.SaveChanges(); del = true; } } catch (Exception ex) { del = false; MessageBox.Show(ex.Message); } } } } } else { MessageBox.Show("No item selected!"); } if (del) // deleted { del = false; if (ItemTitle.Text.Length != 0 || SN.Text.Length != 0 || OutBoundDate.Checked || Manipulator.Text.Length != 0 || TrackingNum.Text.Trim().Length != 0) { Search_Click(this, e); } else { ReLoadData(); } st.returnCurrentRow(indexDelete, dataGridView1); } }