Пример #1
0
 private void Add_Click(object sender, EventArgs e)
 {
     if (userName.Text.Trim().Length != 0 && pwd.Text.Trim().Length != 0 && userType.Text.Length != 0)
     {
         try
         {
             using (var ctx = new ItemContext())
             {
                 User u = new User()
                 {
                     UserName = userName.Text.Trim(), UserPwd = pwd.Text.Trim(), UserType = userType.Text.Trim()
                 };
                 ctx.Users.Add(u);
                 ctx.SaveChanges();
                 MessageBox.Show("Successfully added new user!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             Clear_Click(this, e);
         }
     }
     else
     {
         MessageBox.Show("Please complete the information!");
     }
 }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string pwd = textBox2.Text.Trim().ToString();

            if (textBox2.Text.Trim().Length == 0 || textBox3.Text.Trim() != textBox2.Text.Trim())
            {
                MessageBox.Show("Failed, password and confirm password are not equal or empty!", "System", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                try
                {
                    using (var ctx = new ItemContext())
                    {
                        User user = new User()
                        {
                            UserName = uname, UserPwd = textBox2.Text.Trim().ToString()
                        };
                        ctx.Users.Attach(user);
                        ctx.Entry(user).State = System.Data.Entity.EntityState.Modified;
                        ctx.Entry(user).Property(x => x.UserType).IsModified = false;
                        ctx.SaveChanges();
                        MessageBox.Show("Password Successfully Changed!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #3
0
 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);
         }
     }
 }
Пример #4
0
 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);
 }
Пример #5
0
 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.");
     }
 }
Пример #6
0
        private void ReadyToOut_Click(object sender, EventArgs e)
        {
            int    position   = dataGridView1.Rows.GetFirstRow(DataGridViewElementStates.Selected);
            string currentRow = dataGridView1.Rows[position].Cells["SN"].Value.ToString();

            try
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (Convert.ToBoolean(row.Cells["Selected"].Value))
                    {
                        using (var ctx = new ItemContext())
                        {
                            string rdy       = row.Cells["SN"].Value.ToString();
                            var    pending   = ctx.Items.Where(sn => sn.SN == rdy).Select(x => x.Pending).First();
                            var    condition = ctx.Items.Where(sn => sn.SN == rdy).Select(x => x.Condition).First();
                            if (pending == null)
                            {
                                pending = false;
                            }
                            if (condition == null)
                            {
                                MessageBox.Show("The item without condition cannot set to rdy.");
                                return;
                            }
                            if (condition.Contains("unchecked") || condition.Contains("Unchecked") || condition.Contains("Defective"))
                            {
                                MessageBox.Show(condition.ToString() + " Item Cannot set to rdy to out");
                                return;
                            }
                            Item ite = new Item()
                            {
                                SN = row.Cells["SN"].Value.ToString(), Pending = !Convert.ToBoolean(pending.Value)
                            };
                            ctx.Entry <Item>(ite).State = EntityState.Unchanged;
                            ctx.Entry <Item>(ite).Property(p => p.Pending).IsModified = true;
                            ctx.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                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(currentRow, dataGridView1);
            }
        }
Пример #7
0
 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);
 }
Пример #8
0
 private void Modify_Click(object sender, EventArgs e)
 {
     if (userName.Text.Trim().Length != 0)
     {
         try
         {
             using (var ctx = new ItemContext())
             {
                 User u = new User()
                 {
                     UserName = userName.Text.Trim(), UserPwd = pwd.Text.Trim(), UserType = userType.Text
                 };
                 ctx.Users.Attach(u);
                 ctx.Entry(u).State = System.Data.Entity.EntityState.Modified;
                 ctx.SaveChanges();
                 MessageBox.Show("Successfully Updated!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             Clear_Click(this, e);
         }
     }
     else
     {
         MessageBox.Show("Please select one user!");
     }
 }
Пример #9
0
 private void Delete_Click(object sender, EventArgs e)
 {
     if (userName.Text.Trim().Length != 0)
     {
         try
         {
             using (var ctx = new ItemContext())
             {
                 User u = ctx.Users.Where(uname => uname.UserName == userName.Text.Trim()).First <User>();
                 ctx.Users.Remove(u);
                 ctx.SaveChanges();
                 MessageBox.Show(userName.Text.ToString() + " is deleted successfully!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             Clear_Click(this, e);
         }
     }
     else
     {
         MessageBox.Show("Pleas Select one user!");
     }
 }
Пример #10
0
        //private void setFridViewProperty()
        //{
        //    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        //    dataGridView1.ReadOnly = true;
        //    dataGridView1.ClearSelection();
        //    dataGridView1.RowHeadersVisible = false;
        //    dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        //    dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
        //    dataGridView1.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True;
        //    dataGridView1.AllowUserToResizeRows = false;
        //    dataGridView1.AllowUserToResizeColumns = true;
        //    dataGridView1.AllowUserToAddRows = false;
        //}

        private void Clear_Click(object sender, EventArgs e)
        {
            DateTime time1 = Convert.ToDateTime(dateTimePicker1.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.ItemBaks.Where(a => a.DateOfOut.CompareTo(time1) < 0);
                    foreach (var ite in list)
                    {
                        ctx.ItemBaks.Remove(ite);
                    }
                    ctx.SaveChanges();
                    MessageBox.Show("Clearance Successfully!");
                }
            }
            RecentDeletion_Load(this, e);
        }
Пример #11
0
 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.");
     }
 }
Пример #12
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);
        }
Пример #13
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. ");
            }
        }
Пример #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (itemTitile.Text.Length != 0 && dateOfRcv.Text.Length != 0 && orderId.Text.Length != 0 && SN.Text.Length != 0)
            {
                //if (!(Regex.IsMatch(Regex.Replace(orderId.Text.Trim().ToString(), "-",""), StrRegex(1))))
                //{
                //    //MessageBox.Show(orderId.Text.Trim().ToString().Split('-')[0].ToString());
                //    MessageBox.Show("Order Number has to be number, alphabet and '-'!", "System", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    return;
                //}
                //if (UPC.Text.Trim().Length != 0 && !(Regex.IsMatch(UPC.Text.Trim().ToString(), StrRegex(3))))
                //{
                //    MessageBox.Show("UPC has to be number!", "System", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    return;
                //}
                //if (!Regex.IsMatch(SN.Text.Trim().ToString(), StrRegex(1)))
                //{
                //    MessageBox.Show("SN has to be number or alphabet!", "System", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    return;
                //}

                try
                {
                    using (var ctx = new ItemContext())
                    {
                        //MessageBox.Show(dateOfRcv.Text.ToString());
                        Item Ite = 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 = uname, Condition = condition.Text, Note = Note.Text.Trim(), Pending = false
                        };
                        //var WholeRecord = ctx.Items.Select(a => a.SN).Union(ctx.ItemsDisposed.Select(b => b.SN));
                        var WholeRecord = ctx.Items.Select(a => a.SN);
                        //MessageBox.Show(WholeRecord.Where(x => x.Equals(SN.Text.Trim())).ToList().ToString());
                        if (WholeRecord.Where(x => x.Equals(SN.Text.Trim())).ToList().Count == 0)
                        {
                            ctx.Items.Add(Ite);
                            ctx.SaveChanges();
                            MessageBox.Show("Successfully added!");
                            //MessageBox.Show(WholeRecord.Where(x => x.Equals(SN.Text.Trim())).ToList().ToString());
                            foreach (Control ctr in this.Controls)
                            {
                                if (ctr is TextBox)
                                {
                                    if (ctr.Name == itemTitile.Name || ctr.Name == originalTrackingNum.Name || ctr.Name == orderId.Name || ctr.Name == location.Name)
                                    {
                                        continue;
                                    }
                                    ctr.Text = "";
                                }
                            }

                            noSNCheckBox.Checked = false;
                            dateOfRcv.Value      = DateTime.Now;
                            listed.SelectedIndex = 0;
                            //condition.SelectedIndex = 0;
                        }
                        else
                        {
                            MessageBox.Show("Item already exists in inventory!");
                            //MessageBox.Show(WholeRecord.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                }
            }
            else
            {
                MessageBox.Show("Item title, orderID, and SN are required.");
            }
        }
Пример #15
0
        private void SaveAll_Click(object sender, EventArgs e)
        {
            if (itemTitile.Text.Trim().Length > 0 || location.Text.Trim().Length > 0 ||
                listed.Text.Trim().Length > 0 || condition.Text.Trim().Length > 0 ||
                note.Text.Trim().Length > 0 || upc.Text.Trim().Length > 0)
            {
                foreach (string sn in SN)
                {
                    try
                    {
                        using (ItemContext ctx = new ItemContext())
                        {
                            Item it = ctx.Items.Find(sn);
                            it.ServiceMan = uname;
                            foreach (Control ctr in this.Controls)
                            {
                                if (ctr.Text.Trim().Length != 0)
                                {
                                    switch (ctr.Name)
                                    {
                                    case "itemTitile":
                                        it.ItemTitle = ctr.Text.Trim();
                                        break;

                                    case "location":
                                        it.Location = ctr.Text.Trim();
                                        break;

                                    case "listed":
                                        it.Listed = ctr.Text.Trim();
                                        break;

                                    case "condition":
                                        it.Condition = ctr.Text.Trim();
                                        break;

                                    case "upc":
                                        it.UPC = ctr.Text.Trim();
                                        break;

                                    case "note":
                                        it.Note = ctr.Text.Trim();
                                        break;
                                    }
                                }
                            }
                            ctx.Items.Attach(it);
                            ctx.Entry(it).State = System.Data.Entity.EntityState.Modified;
                            ctx.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        return;
                    }
                }
                MessageBox.Show("Successfull updated multiple items!");
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Nothing can be updated!");
            }
        }
Пример #16
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);
            }
        }
Пример #17
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);
            }
        }
Пример #18
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["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);
            }
        }