Exemplo n.º 1
0
 public static void AddDataBaseSOH(DataBaseSOH entrySOH, DataBaseTranHistory newTrans)
 {
     using (WMS_Project_DB db = new WMS_Project_DB(CONNECTION.conn))
     {
         db.DataBaseSOHs.InsertOnSubmit(entrySOH);
         DataBaseTranHistory.addNewTransHistoryEntry(newTrans, db);
     }
 }
Exemplo n.º 2
0
        public static void UpdateDataBaseSOH(DataBaseSOH entrySOH, DataBaseTranHistory newTrans)
        {
            //DataContext db = new DataContext(connection);

            //Table<DataBaseSOH> DataBaseSOHs = db.GetTable<DataBaseSOH>();

            entrySOH.Location = entrySOH.Location.ToUpper();
            newTrans.Location = newTrans.Location.ToUpper();

            using (WMS_Project_DB db = new WMS_Project_DB(CONNECTION.conn))
            {
                try
                {

                    DataBaseSOH dbSOH = db.DataBaseSOHs.Single(o =>
                                 o.Branch.Equals(entrySOH.Branch)
                                 && o.Owner.Equals(entrySOH.Owner)
                                 && o.Location.Equals(entrySOH.Location)
                                 && o.ProductCode.Equals(entrySOH.ProductCode)
                                 && o.Colour.Equals(entrySOH.Colour)
                                 && o.Size.Equals(entrySOH.Size)
                                 && o.ArrivalDate.Equals(entrySOH.ArrivalDate));

                    if (entrySOH.Location != newTrans.Location) //location changed
                    {
                        DataBaseSOH toLoc = db.DataBaseSOHs.SingleOrDefault(o =>
                                 o.Branch.Equals(entrySOH.Branch)
                                 && o.Owner.Equals(entrySOH.Owner)
                                 && o.Location.Equals(newTrans.Location)
                                 && o.ProductCode.Equals(entrySOH.ProductCode)
                                 && o.Colour.Equals(entrySOH.Colour)
                                 && o.Size.Equals(entrySOH.Size)
                                 && o.ArrivalDate.Equals(entrySOH.ArrivalDate));

                        if (toLoc == null)
                        {
                            //dbSOH.Location = newTrans.Location;             //newTrans stores updated location
                            DataBaseSOH newSOH = new DataBaseSOH()         //entrySOH stores the previous
                            {
                                ArrivalDate = dbSOH.ArrivalDate,
                                Attribute1 = dbSOH.Attribute1,
                                Attribute2 = dbSOH.Attribute2,
                                Attribute3 = dbSOH.Attribute3,
                                Attribute4 = dbSOH.Attribute4,
                                Attribute5 = dbSOH.Attribute5,
                                BatchNumber = dbSOH.BatchNumber,
                                Branch = dbSOH.Branch,
                                Colour = dbSOH.Colour,
                                ExpiryDate = dbSOH.ExpiryDate,
                                Location = newTrans.Location,   //location changed
                                Owner = dbSOH.Owner,
                                ProductCode = dbSOH.ProductCode,
                                QTY = dbSOH.QTY,
                                RecordIdentifier = dbSOH.RecordIdentifier,
                                SerialNumber = dbSOH.SerialNumber,
                                Size = dbSOH.Size,
                                StockStatus = dbSOH.StockStatus,
                                UOM = dbSOH.UOM
                            };
                            db.DataBaseSOHs.InsertOnSubmit(newSOH);
                        }
                        else
                        {
                            toLoc.QTY += dbSOH.QTY;
                        }
                        db.DataBaseSOHs.DeleteOnSubmit(dbSOH);
                    }
                    else
                    {
                        if (dbSOH.QTY != entrySOH.QTY)  //QTY adjust
                        {
                            dbSOH.QTY = entrySOH.QTY;
                        }
                        else if (dbSOH.StockStatus != entrySOH.StockStatus) //stock adjust
                            dbSOH.StockStatus = entrySOH.StockStatus;
                        else
                        {
                            dbSOH.Attribute1 = entrySOH.Attribute1;
                            dbSOH.Attribute2 = entrySOH.Attribute2;
                            dbSOH.Attribute3 = entrySOH.Attribute3;
                            dbSOH.Attribute4 = entrySOH.Attribute4;
                            dbSOH.Attribute5 = entrySOH.Attribute5;
                        }
                    }
                    //db.SubmitChanges();
                    DataBaseTranHistory.addNewTransHistoryEntry(newTrans, db);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            }
        }
Exemplo n.º 3
0
 public static void AddDataBaseSOH(DataBaseSOH entrySOH, DataBaseTranHistory newTrans)
 {
     using (WMS_Project_DB db = new WMS_Project_DB(CONNECTION.conn))
     {
         db.DataBaseSOHs.InsertOnSubmit(entrySOH);
         DataBaseTranHistory.addNewTransHistoryEntry(newTrans, db);
     }
 }
Exemplo n.º 4
0
        private void SaveEdit_Click(object sender, RoutedEventArgs e)
        {
            if (curOption != AttributesEditOption.CreateNew)
            {
                float curQTY = 0, prevQTY = 0;
                string JobNum = string.Empty;
                string JobType = string.Empty;

                if (curOption == AttributesEditOption.AdjQTY)
                {
                    curQTY = float.Parse(QTYField.Text);
                    if (curQTY < 0)
                    {
                        MessageBox.Show("Item quantity should not be negative!");
                        return;
                    }//QTY must be positive
                }

                //get current row
                DataGridRow curRow = GetListViewItem(dataGrid.SelectedIndex, dataGrid);
                DataBaseSOH selectedSOH = curRow.Item as DataBaseSOH;

                // check if any difference had been made
                if (curOption == AttributesEditOption.AdjQTY)
                {
                    prevQTY = selectedSOH.QTY;
                    if (curQTY == prevQTY)
                    {
                        MessageBox.Show("No change discovered!");
                        return;
                    }
                    //selectedSOH.Branch = BranchField.Text;
                    selectedSOH.QTY = curQTY;
                    JobNum = "ADJ";
                    JobType = "ADJ";
                }
                else if (curOption == AttributesEditOption.AdjAttr)
                {
                    if (Attr1Field.Text.Equals(selectedSOH.Attribute1)
                        && Attr2Field.Text.Equals(selectedSOH.Attribute2)
                        && Attr3Field.Text.Equals(selectedSOH.Attribute3)
                        && Attr4Field.Text.Equals(selectedSOH.Attribute4)
                        && Attr5Field.Text.Equals(selectedSOH.Attribute5))
                    {
                        MessageBox.Show("No change discovered!");
                        return;
                    }
                    selectedSOH.Attribute1 = Attr1Field.Text;
                    selectedSOH.Attribute2 = Attr2Field.Text;
                    selectedSOH.Attribute3 = Attr3Field.Text;
                    selectedSOH.Attribute4 = Attr4Field.Text;
                    selectedSOH.Attribute5 = Attr5Field.Text;
                    JobNum = "ATTR";
                    JobType = "ADJ";
                }
                else if (curOption == AttributesEditOption.AdjStkStats)
                {
                    if (StockField.Text.Equals(selectedSOH.StockStatus))
                    {
                        MessageBox.Show("No change discovered!");
                        return;
                    }
                    selectedSOH.StockStatus = StockField.Text;
                    JobType = "STA";
                    JobNum = "STATUS";
                }

                if (!(Reason1.IsChecked == true) && !(Reason2.IsChecked == true) && !(Reason3.IsChecked == true)
                    && !(Reason4.IsChecked == true) && !(Reason5.IsChecked == true) && !(Reason6.IsChecked == true)
                    && !(Reason7.IsChecked == true))
                {
                    MessageBox.Show("You need to choose or write a specific reason!");
                    return;
                }
                else if ((Reason7.IsChecked == true) && (ReasonField.Text == string.Empty))
                {
                    MessageBox.Show("You need to choose or write a specific reason!");
                    return;
                }

                DataBaseTranHistory newTrans = new DataBaseTranHistory();
                {
                    newTrans.RecordIdentifier = "TRN";
                    newTrans.Type = JobType;
                    newTrans.Date = DateTime.Today;
                    newTrans.Time = DateTime.Now.TimeOfDay;
                    newTrans.User = CONNECTION.DbHandle.Username;
                    newTrans.Owner = selectedSOH.Owner;
                    newTrans.ProductCode = selectedSOH.ProductCode;
                    newTrans.Colour = selectedSOH.Colour;
                    newTrans.Size = selectedSOH.Size;
                    newTrans.Location = selectedSOH.Location;
                    newTrans.UOM = selectedSOH.UOM;
                    newTrans.QTY = selectedSOH.QTY - prevQTY;
                    newTrans.JobNumber = JobNum;
                    newTrans.ArrivalDate = selectedSOH.ArrivalDate;
                    newTrans.BatchNumber = selectedSOH.BatchNumber;
                    newTrans.ExpiryDate = (selectedSOH.ExpiryDate == null) ? DateTime.MaxValue : Convert.ToDateTime(selectedSOH.ExpiryDate);
                    newTrans.SerialNumber = selectedSOH.SerialNumber;
                    newTrans.Attribute1 = selectedSOH.Attribute1;
                    newTrans.Attribute2 = selectedSOH.Attribute2;
                    newTrans.Attribute3 = selectedSOH.Attribute3;
                    newTrans.Attribute4 = selectedSOH.Attribute4;
                    newTrans.Attribute5 = selectedSOH.Attribute5;
                    newTrans.StockStatus = selectedSOH.StockStatus;
                    newTrans.ReasonCode = UserFrame.ReasonCode;
                    newTrans.Notes = ReasonField.Text;
                }
                try
                {
                    DataBaseSOH.UpdateDataBaseSOH(selectedSOH, newTrans);    //can be made easier if only QTY is allowed to change
                    InvEditFrame.Visibility = Visibility.Collapsed;
                    ShowInvTable(branchFilter.Text, ownerFilter.Text, ProFilter.Text, LocFilter.Text, InvQuery.ShowZero);
                    chart.Visibility = Visibility.Visible;
                    resetSelection();
                }
                catch
                {
                    MessageBox.Show("Update Data Error!");
                }
            }
            else
            {
                if (BranchField.Text.Equals(string.Empty)
                    || OwnerField.Text.Equals(string.Empty)
                    || PcodeField.Text.Equals(string.Empty)
                    || LocationField.Text.Equals(string.Empty)
                    || UOMField.Text.Equals(string.Empty)
                    || QTYField.Text.Equals(string.Empty)
                    || ArrivalField.Text.Equals(string.Empty)
                    || ColourField.Text.Equals(string.Empty)
                    || SizeField.Text.Equals(string.Empty)
                    || StockField.Text.Equals(string.Empty))
                {
                    MessageBox.Show("You should complete all red compulsory field!");
                    return;
                }
                if (!(Reason1.IsChecked == true) && !(Reason2.IsChecked == true) && !(Reason3.IsChecked == true)
                    && !(Reason4.IsChecked == true) && !(Reason5.IsChecked == true) && !(Reason6.IsChecked == true)
                    && !(Reason7.IsChecked == true))
                {
                    MessageBox.Show("You need to choose or write a specific reason!");
                    return;
                }
                else if ((Reason7.IsChecked == true) && (ReasonField.Text == string.Empty))
                {
                    MessageBox.Show("You need to choose or write a specific reason!");
                    return;
                }
                if (0 > float.Parse(QTYField.Text))
                {
                    MessageBox.Show("Item quantity should not be negative!");
                    return;
                }
                DataBaseSOH newSOH = new DataBaseSOH()
                {
                    RecordIdentifier = "SOH",
                    Branch = BranchField.Text,
                    Owner = OwnerField.Text,
                    ProductCode = PcodeField.Text,
                    Colour = ColourField.Text,
                    Size = SizeField.Text,
                    Location = LocationField.Text,
                    UOM = UOMField.Text,
                    QTY = float.Parse(QTYField.Text),
                    ArrivalDate = Convert.ToDateTime(ArrivalField.Text),
                    BatchNumber = BatchField.Text.Trim() == string.Empty ? null : BatchField.Text.Trim(),
                    ExpiryDate = ExpiryField.Text.Trim() == string.Empty ? null : ExpiryField.Text.Trim(),
                    SerialNumber = SNField.Text.Trim() == string.Empty ? null : SNField.Text.Trim(),
                    Attribute1 = Attr1Field.Text.Trim() == string.Empty ? null : Attr1Field.Text.Trim(),
                    Attribute2 = Attr2Field.Text.Trim() == string.Empty ? null : Attr2Field.Text.Trim(),
                    Attribute3 = Attr3Field.Text.Trim() == string.Empty ? null : Attr3Field.Text.Trim(),
                    Attribute4 = Attr4Field.Text.Trim() == string.Empty ? null : Attr4Field.Text.Trim(),
                    Attribute5 = Attr5Field.Text.Trim() == string.Empty ? null : Attr5Field.Text.Trim(),
                    StockStatus = StockField.Text
                };

                DataBaseTranHistory newTrans = new DataBaseTranHistory();
                {
                    newTrans.RecordIdentifier = "TRN";
                    newTrans.Type = "CRT";
                    newTrans.Date = DateTime.Today;
                    newTrans.Time = DateTime.Now.TimeOfDay;
                    newTrans.User = CONNECTION.DbHandle.Username;
                    newTrans.Owner = newSOH.Owner;
                    newTrans.ProductCode = newSOH.ProductCode;
                    newTrans.Colour = newSOH.Colour;
                    newTrans.Size = newSOH.Size;
                    newTrans.Location = newSOH.Location;
                    newTrans.UOM = newSOH.UOM;
                    newTrans.QTY = newSOH.QTY;
                    newTrans.JobNumber = "CREATE";
                    newTrans.ArrivalDate = newSOH.ArrivalDate;
                    newTrans.BatchNumber = newSOH.BatchNumber;
                    newTrans.ExpiryDate = (newSOH.ExpiryDate == null) ? DateTime.MaxValue : Convert.ToDateTime(newSOH.ExpiryDate);
                    newTrans.SerialNumber = newSOH.SerialNumber;
                    newTrans.Attribute1 = newSOH.Attribute1;
                    newTrans.Attribute2 = newSOH.Attribute2;
                    newTrans.Attribute3 = newSOH.Attribute3;
                    newTrans.Attribute4 = newSOH.Attribute4;
                    newTrans.Attribute5 = newSOH.Attribute5;
                    newTrans.StockStatus = newSOH.StockStatus;
                    newTrans.ReasonCode = UserFrame.ReasonCode;
                    newTrans.Notes = ReasonField.Text;
                }
                try
                {
                    DataBaseSOH.AddDataBaseSOH(newSOH, newTrans);    //can be made easier if only QTY is allowed to change
                    InvEditFrame.Visibility = Visibility.Collapsed;
                    ShowInvTable(branchFilter.Text, ownerFilter.Text, ProFilter.Text, LocFilter.Text, InvQuery.ShowZero);
                    chart.Visibility = Visibility.Visible;
                    resetSelection();
                }
                catch
                {
                    MessageBox.Show("Add Data Error!");
                }
            }
        }
Exemplo n.º 5
0
        public static void UpdateDataBaseSOH(DataBaseSOH entrySOH, DataBaseTranHistory newTrans)
        {
            //DataContext db = new DataContext(connection);

            //Table<DataBaseSOH> DataBaseSOHs = db.GetTable<DataBaseSOH>();

            entrySOH.Location = entrySOH.Location.ToUpper();
            newTrans.Location = newTrans.Location.ToUpper();

            using (WMS_Project_DB db = new WMS_Project_DB(CONNECTION.conn))
            {
                try
                {
                    DataBaseSOH dbSOH = db.DataBaseSOHs.Single(o =>
                                                               o.Branch.Equals(entrySOH.Branch) &&
                                                               o.Owner.Equals(entrySOH.Owner) &&
                                                               o.Location.Equals(entrySOH.Location) &&
                                                               o.ProductCode.Equals(entrySOH.ProductCode) &&
                                                               o.Colour.Equals(entrySOH.Colour) &&
                                                               o.Size.Equals(entrySOH.Size) &&
                                                               o.ArrivalDate.Equals(entrySOH.ArrivalDate));


                    if (entrySOH.Location != newTrans.Location) //location changed
                    {
                        DataBaseSOH toLoc = db.DataBaseSOHs.SingleOrDefault(o =>
                                                                            o.Branch.Equals(entrySOH.Branch) &&
                                                                            o.Owner.Equals(entrySOH.Owner) &&
                                                                            o.Location.Equals(newTrans.Location) &&
                                                                            o.ProductCode.Equals(entrySOH.ProductCode) &&
                                                                            o.Colour.Equals(entrySOH.Colour) &&
                                                                            o.Size.Equals(entrySOH.Size) &&
                                                                            o.ArrivalDate.Equals(entrySOH.ArrivalDate));

                        if (toLoc == null)
                        {
                            //dbSOH.Location = newTrans.Location;             //newTrans stores updated location
                            DataBaseSOH newSOH = new DataBaseSOH()         //entrySOH stores the previous
                            {
                                ArrivalDate      = dbSOH.ArrivalDate,
                                Attribute1       = dbSOH.Attribute1,
                                Attribute2       = dbSOH.Attribute2,
                                Attribute3       = dbSOH.Attribute3,
                                Attribute4       = dbSOH.Attribute4,
                                Attribute5       = dbSOH.Attribute5,
                                BatchNumber      = dbSOH.BatchNumber,
                                Branch           = dbSOH.Branch,
                                Colour           = dbSOH.Colour,
                                ExpiryDate       = dbSOH.ExpiryDate,
                                Location         = newTrans.Location, //location changed
                                Owner            = dbSOH.Owner,
                                ProductCode      = dbSOH.ProductCode,
                                QTY              = dbSOH.QTY,
                                RecordIdentifier = dbSOH.RecordIdentifier,
                                SerialNumber     = dbSOH.SerialNumber,
                                Size             = dbSOH.Size,
                                StockStatus      = dbSOH.StockStatus,
                                UOM              = dbSOH.UOM
                            };
                            db.DataBaseSOHs.InsertOnSubmit(newSOH);
                        }
                        else
                        {
                            toLoc.QTY += dbSOH.QTY;
                        }
                        db.DataBaseSOHs.DeleteOnSubmit(dbSOH);
                    }
                    else
                    {
                        if (dbSOH.QTY != entrySOH.QTY)  //QTY adjust
                        {
                            dbSOH.QTY = entrySOH.QTY;
                        }
                        else if (dbSOH.StockStatus != entrySOH.StockStatus) //stock adjust
                        {
                            dbSOH.StockStatus = entrySOH.StockStatus;
                        }
                        else
                        {
                            dbSOH.Attribute1 = entrySOH.Attribute1;
                            dbSOH.Attribute2 = entrySOH.Attribute2;
                            dbSOH.Attribute3 = entrySOH.Attribute3;
                            dbSOH.Attribute4 = entrySOH.Attribute4;
                            dbSOH.Attribute5 = entrySOH.Attribute5;
                        }
                    }
                    //db.SubmitChanges();
                    DataBaseTranHistory.addNewTransHistoryEntry(newTrans, db);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            }
        }