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()) { ItemInbound it = ctx.ItemInbounds.Where(id => id.ItemInboundId == selectedId).First <ItemInbound>(); ctx.ItemInbounds.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()) { ItemInbound it = new ItemInbound(); it.ItemInboundId = Convert.ToInt32(row.Cells[0].Value.ToString()); it.isDelete = false; ctx.ItemInbounds.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 && UPC.Text.Length != 0 && date.Text.Length != 0 && TrackingNumLabel.Text.Length != 0) { try { using (var ctx = new ItemContext()) { ItemInbound itemInbound = ctx.ItemInbounds.Where(u => u.ItemInboundId == itemInboundId).FirstOrDefault(); itemInbound.ItemTitle = itemTitile.Text; itemInbound.Date = Convert.ToDateTime(date.Text); itemInbound.Qty = Convert.ToInt32(Qty.Text); itemInbound.UPC = UPC.Text; itemInbound.TrackingNum = TrackingNum.Text; itemInbound.ShipperId = tbShipperID.Text; ctx.Entry(itemInbound).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); MessageBox.Show("Successfully updated!"); } } 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 && UPC.Text.Trim().Length != 0) { try { using (var ctx = new ItemContext()) { ItemInbound II = new ItemInbound() { ItemTitle = itemTitile.Text.Trim(), TrackingNum = TrackingNum.Text.Trim(), Date = Convert.ToDateTime(date.Text.ToString()), Qty = Convert.ToInt32(Qty.Text), Manipulator = manipulator, UPC = UPC.Text.Trim(), ShipperId = tbShipperID.Text.Trim(), isDelete = false }; ctx.ItemInbounds.Add(II); ctx.SaveChanges(); } MessageBox.Show("Record successfully added!"); UPC.Text = ""; TrackingNum.Text = ""; date.Value = DateTime.Now; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("itemTitile, TrackingNum, UPC cannot be null."); } }
private void InboundModify_Load(object sender, EventArgs e) { try { using (var ctx = new ItemContext()) { ItemInbound itemInbound = ctx.ItemInbounds.Find(itemInboundId); TrackingNum.Text = itemInbound.TrackingNum; itemTitile.Text = itemInbound.ItemTitle; date.Text = itemInbound.Date.ToString(); Qty.Text = itemInbound.Qty.ToString(); UPC.Text = itemInbound.UPC;; tbShipperID.Text = itemInbound.ShipperId; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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["ItemInboundId"].Value.ToString()); indexDelete = indexDelete == 0 ? row.Index - 1 : indexDelete; //string trackingDelete = row.Cells["TrackingNum"].Value.ToString(); try { using (var ctx = new ItemContext()) { ItemInbound itemInboundDel = new ItemInbound(); itemInboundDel.ItemInboundId = idDelete; itemInboundDel.isDelete = true; ctx.ItemInbounds.Attach(itemInboundDel); ctx.Entry(itemInboundDel).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 || UPC.Text.Length != 0 || InBoundDate.Checked || ShipperID.Text.Length != 0 || TrackingNum.Text.Trim().Length != 0) { Search_Click(this, e); } else { ReLoadData(); } st.returnCurrentRow(indexDelete, dataGridView1); } }