Exemplo n.º 1
0
        private void multipleDeleteButton_Click(object sender, EventArgs e)
        {
            DateTime time1 = Convert.ToDateTime(clearDatePicker.Text);

            if (MessageBox.Show("The Log before " + time1.Date + " will be deleted", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                using (ItemContext ctx = new ItemContext())
                {
                    var list = ctx.ItemsDisposed.Where(a => a.DateOfOut.CompareTo(time1) < 0);
                    foreach (var it in list)
                    {
                        ItemBak bak = new ItemBak()
                        {
                            ItemTitle           = it.ItemTitle,
                            SN                  = it.SN,
                            UPC                 = it.UPC,
                            Condition           = it.Condition,
                            DateOfOut           = it.DateOfOut,
                            DateOfRcv           = it.DateOfRcv,
                            ItemInOperator      = it.ItemInOperator,
                            ItemOutOperator     = it.ItemOutOperator,
                            Listed              = it.Listed,
                            Location            = it.Location,
                            Note                = it.Note,
                            OrderId             = it.OrderId,
                            OriginalTrackingNum = it.OriginalTrackingNum,
                            OutTrackingNumber   = it.OutTrackingNumber,
                            ReturnCode          = it.ReturnCode,
                            ServiceMan          = it.ServiceMan
                        };
                        ctx.ItemBaks.Add(bak);
                        ctx.ItemsDisposed.Remove(it);
                    }
                    ctx.SaveChanges();
                    MessageBox.Show("Clearance Successfully!");
                }
            }
            Management_Load(this, e);
        }
Exemplo n.º 2
0
        private void Delete_Click(object sender, EventArgs e)
        {
            //var first = dataGridView1.Rows.GetFirstRow(DataGridViewElementStates.Selected);
            //string snDelete = this.dataGridView1.Rows[first].Cells["SN"].Value.ToString();
            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 item will be permanently deleted!", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells["Selected"].Value))
                        {
                            string snDelete        = row.Cells["SN"].Value.ToString();
                            string oIdDelete       = row.Cells["OrderId"].Value.ToString();
                            string inventoryDelete = InOrOut.Text.ToString();
                            indexDelete = indexDelete == 0 ? row.Index - 1 : indexDelete;

                            try
                            {
                                using (var ctx = new ItemContext())
                                {
                                    //int id = ctx.ItemBaks.Count() + 1;
                                    if (inventoryDelete == "In Inventory")
                                    {
                                        Item it = ctx.Items.Where(u => u.SN == snDelete).First <Item>();
                                        ctx.Items.Remove(it);
                                        ctx.SaveChanges();
                                        del = true;
                                    }
                                    else
                                    {
                                        //MessageBox.Show(id.ToString());
                                        ItemDisposed it  = ctx.ItemsDisposed.Where(o => o.OrderId == oIdDelete).Where(u => u.SN == snDelete).First <ItemDisposed>();
                                        ItemBak      bak = new ItemBak()
                                        {
                                            ItemTitle           = it.ItemTitle, SN = it.SN, UPC = it.UPC, Condition = it.Condition, DateOfOut = it.DateOfOut, DateOfRcv = it.DateOfRcv, ItemInOperator = it.ItemInOperator,
                                            ItemOutOperator     = it.ItemOutOperator, Listed = it.Listed, Location = it.Location, Note = it.Note, OrderId = it.OrderId,
                                            OriginalTrackingNum = it.OriginalTrackingNum, OutTrackingNumber = it.OutTrackingNumber, ReturnCode = it.ReturnCode, ServiceMan = it.ServiceMan
                                        };
                                        ctx.ItemBaks.Add(bak);
                                        ctx.ItemsDisposed.Remove(it);
                                        ctx.SaveChanges();
                                        del = true;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                del = false;
                                MessageBox.Show(ex.Message);
                            }
                            finally
                            {
                            }
                        }
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                MessageBox.Show("No item selected!");
            }
            if (del)
            {
                //MessageBox.Show("Delete Successfully!");
                del = false;
                if (ItemTitle.Text.Length != 0 || OrderId.Text.Length != 0 || UPC.Text.Length != 0 || SN.Text.Length != 0 ||
                    RcvTime.Checked || Condition.Text.Length != 0 || pendingBox.Checked ||
                    location.Text.Trim().Length != 0 || LPN.Text.Trim().Length != 0 || TrackingNum.Text.Trim().Length != 0)
                {
                    Search_Click(this, e);
                }
                else
                {
                    ReLoadData();
                }
                st.returnCurrentRow(indexDelete, dataGridView1);
            }
        }