Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (itemTitile.Text.Length != 0 && orderId.Text.Length != 0 && SN.Text.Length != 0 && condition.Text.Length != 0)
            {
                try
                {
                    //determine editors
                    editor = editorMaker(editor);
                    if (SN.ReadOnly)
                    {
                        using (var ctx = new ItemContext())
                        {
                            Item ite;
                            if (utype == "serviceMan")
                            {
                                //Item it = ctx.Items.SingleOrDefault(a => a.SN == snCode);
                                //it.ItemTitle = itemTitile.Text.Trim();
                                //it.DateOfRcv = Convert.ToDateTime(dateOfRcv.Text);
                                //it.OrderId = orderId.Text.Trim();
                                //it.UPC = UPC.Text.Trim();
                                //it.SN = SN.Text.Trim();
                                //it.ReturnCode = returnCode.Text.Trim();
                                //it.Location = location.Text.Trim();
                                //it.Listed = listed.Text;
                                //it.ServiceMan = uname;
                                //it.Condition = condition.Text;
                                //it.OriginalTrackingNum = originalTrackingNum.Text.Trim();
                                //it.Note = Note.Text.Trim();

                                //ctx.Items.Attach(it);
                                //ctx.Entry(it).State = System.Data.Entity.EntityState.Modified;

                                ite = new Item()
                                {
                                    ItemTitle           = itemTitile.Text.Trim(),
                                    DateOfRcv           = Convert.ToDateTime(dateOfRcv.Text),
                                    OrderId             = orderId.Text.Trim(),
                                    UPC                 = UPC.Text.Trim(),
                                    SN                  = SN.Text.Trim(),
                                    OriginalTrackingNum = originalTrackingNum.Text.Trim(),
                                    ReturnCode          = returnCode.Text.Trim(),
                                    Location            = location.Text.Trim(),
                                    Listed              = listed.Text,
                                    ServiceMan          = editor,
                                    Condition           = condition.Text,
                                    Note                = Note.Text.Trim()
                                };
                                ctx.Items.Attach(ite);
                                ctx.Entry(ite).State = System.Data.Entity.EntityState.Modified;
                                ctx.Entry(ite).Property(x => x.ItemInOperator).IsModified = false;
                                ctx.Entry(ite).Property(y => y.Pending).IsModified        = false;
                            }
                            else
                            {
                                ite = new Item()
                                {
                                    ItemTitle           = itemTitile.Text.Trim(),
                                    DateOfRcv           = Convert.ToDateTime(dateOfRcv.Text),
                                    OrderId             = orderId.Text.Trim(),
                                    UPC                 = UPC.Text.Trim(),
                                    SN                  = SN.Text.Trim(),
                                    OriginalTrackingNum = originalTrackingNum.Text.Trim(),
                                    ReturnCode          = returnCode.Text.Trim(),
                                    Location            = location.Text.Trim(),
                                    Listed              = listed.Text,
                                    Condition           = condition.Text,
                                    Note                = Note.Text.Trim()
                                };
                                ctx.Items.Attach(ite);
                                ctx.Entry(ite).State = System.Data.Entity.EntityState.Modified;
                                ctx.Entry(ite).Property(x => x.ItemInOperator).IsModified = false;
                                ctx.Entry(ite).Property(x => x.ServiceMan).IsModified     = false;
                                ctx.Entry(ite).Property(y => y.Pending).IsModified        = false;
                            }
                            ctx.SaveChanges();
                            MessageBox.Show("Successfully updated!");
                            this.Dispose(true);
                        }
                    }
                    else
                    {
                        try
                        {
                            using (ItemContext ctx = new ItemContext())
                            {
                                Item it    = ctx.Items.SingleOrDefault(a => a.SN == snCode);
                                Item itNew = new Item()
                                {
                                    ItemTitle           = itemTitile.Text.Trim(),
                                    OrderId             = orderId.Text.Trim(),
                                    UPC                 = UPC.Text.Trim(),
                                    SN                  = SN.Text.Trim(),
                                    OriginalTrackingNum = originalTrackingNum.Text.Trim(),
                                    ReturnCode          = returnCode.Text.Trim(),
                                    Location            = location.Text.Trim(),
                                    DateOfRcv           = Convert.ToDateTime(dateOfRcv.Text.ToString()),
                                    Listed              = listed.Text,
                                    ItemInOperator      = it.ItemInOperator,
                                    Condition           = condition.Text,
                                    Note                = Note.Text.Trim(),
                                    Pending             = it.Pending,
                                    ServiceMan          = editorMaker(editor)
                                };
                                ctx.Items.Remove(it);
                                ctx.Items.Add(itNew);
                                ctx.SaveChanges();
                                MessageBox.Show("Successfully updated!");
                                snCode = SN.Text;
                                this.Dispose(true);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                }
            }
            else
            {
                MessageBox.Show("Item title, order ID, and Condition are required. ");
            }
        }
Esempio n. 2
0
        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);
            }
        }