Exemplo n.º 1
0
        private void ItemOut_Click(object sender, EventArgs e)
        {
            bool   select         = false;
            string outTrackingNum = "";
            bool   del            = false;
            int    indexDelete    = 0;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (Convert.ToBoolean(row.Cells["Selected"].Value))
                {
                    select = true;
                }
            }
            if (select)
            {
                ConfirmForm cf = new ConfirmForm(outTrackingNum);
                cf.ShowDialog();
                outTrackingNum = cf.getTracking();
                if (outTrackingNum.Length == 0)
                {
                    return;
                }
                else
                {
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells["Selected"].Value))
                        {
                            string itemOut         = row.Cells["SN"].Value.ToString();
                            string snDelete        = row.Cells["SN"].Value.ToString();
                            string inventoryDelete = InOrOut.Text.ToString();
                            indexDelete = indexDelete == 0 ? row.Index - 1 : indexDelete;

                            try
                            {
                                using (var ctx = new ItemContext())
                                {
                                    //var it = ctx.Items.Where(sn => sn.SN == itemOut);
                                    var          item    = ctx.Items.Where(sn => sn.SN == itemOut).First();
                                    ItemDisposed itemDis = new ItemDisposed();
                                    {
                                        itemDis.ItemTitle           = row.Cells["ItemTitle"].Value.ToString();
                                        itemDis.SN                  = row.Cells["SN"].Value.ToString();
                                        itemDis.UPC                 = row.Cells["UPC"].Value.ToString();
                                        itemDis.OrderId             = row.Cells["OrderId"].Value.ToString();
                                        itemDis.DateOfRcv           = Convert.ToDateTime(row.Cells["DateOfRcv"].Value);
                                        itemDis.DateOfOut           = DateTime.Now;
                                        itemDis.OriginalTrackingNum = row.Cells["OriginalTrackingNum"].Value.ToString();
                                        itemDis.OutTrackingNumber   = outTrackingNum;
                                        itemDis.Condition           = row.Cells["Condition"].Value.ToString();
                                        itemDis.Listed              = row.Cells["Listed"].Value.ToString();
                                        itemDis.ItemInOperator      = item.ItemInOperator;
                                        itemDis.ServiceMan          = item.ServiceMan;
                                        itemDis.ItemOutOperator     = uname;
                                        itemDis.Note                = row.Cells["Note"].Value.ToString();
                                        itemDis.ReturnCode          = item.ReturnCode;
                                        itemDis.Location            = row.Cells["Location"].Value.ToString();
                                    }
                                    ctx.ItemsDisposed.Add(itemDis);

                                    Item it = ctx.Items.Where(u => u.SN == snDelete).First <Item>();
                                    ctx.Items.Remove(it);
                                    ctx.SaveChanges();
                                    del = true;
                                }
                            }
                            catch (Exception ex)
                            {
                                del = false;
                                MessageBox.Show(ex.ToString());
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("No item selected.");
                return;
            }
            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)
                {
                    Search_Click(this, e);
                }
                else
                {
                    ReLoadData();
                }
                st.returnCurrentRow(indexDelete, dataGridView1);
            }
        }
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);
            }
        }