Ejemplo n.º 1
0
 public static ObservableCollection <Source.Data.Entities.Stocks> ItemsSource()
 {
     try
     {
         var dbcontext = new Source.Data.SourceContext();
         var list      = new ObservableCollection <Source.Data.Entities.Stocks>(dbcontext.Stocks);
         var Items     = (from a in list
                          select new Source.Data.Entities.Stocks
         {
             Yy = a.Yy,
             Mm = a.Mm,
             ColorCode = a.ColorCode,
             MaterialCo = a.MaterialCo,
             MaterialType = a.MaterialType,
             StockName = a.StockName,
             QtyOpen = a.QtyOpen,
             QtyIn = a.QtyIn,
             QtyOut = a.QtyOut,
             QtyEnd = a.QtyEnd,
             IsChecked = false,
             AutoId = Source.Data.SourceContext.Action.CreateAutoID(),
             UpdateStatus = "Unchanged"
         }
                          );
         return(new ObservableCollection <Source.Data.Entities.Stocks>(Items));
     }
     catch (Exception err)
     {
         return(new ObservableCollection <Source.Data.Entities.Stocks>());
     }
 }
Ejemplo n.º 2
0
        //=============
        #region  Delete
        public static Source.Data.SourceContext.MSG Delete(IEnumerable <Source.Data.Entities.StockCloseEnds> items)
        {
            var _return = new Source.Data.SourceContext.MSG();

            try
            {
                var dbContext = new  Source.Data.SourceContext();
                foreach (var item in items)
                {
                    var itemDel = dbContext.StockCloseEnds.Where(s => s.Yy == item.Yy &&
                                                                 s.Mm == item.Mm &&
                                                                 s.StockName == item.StockName).FirstOrDefault();
                    dbContext.Entry(itemDel).State = System.Data.Entity.EntityState.Deleted;
                }
                ;
                dbContext.SaveChanges();
                _return = new Source.Data.SourceContext.MSG("Deleted", false);
            }
            catch (Exception err)
            {
                _return = new Source.Data.SourceContext.MSG("Deleted", true);
                _return.MsgInformation += "\n " + err.ToString();
            }



            return(_return);
        }
Ejemplo n.º 3
0
 public static Source.Data.Entities.StationTracking GetBySessionID(string _SesstionID)
 {
     try
     {
         var dbcontext = new Source.Data.SourceContext();
         return(dbcontext.StationTrackings.Where(x => x.SessionID == _SesstionID).First());
     }
     catch (Exception err)
     {
         return(new Source.Data.Entities.StationTracking());
     }
 }
Ejemplo n.º 4
0
 public static ObservableCollection <Source.Data.Entities.StationTracking> ItemsSource(string _Station, String SessionSymbol)
 {
     try
     {
         var dbcontext = new Source.Data.SourceContext();
         var list      = new ObservableCollection <Source.Data.Entities.StationTracking>(dbcontext.StationTrackings.Where(x => x.Station == _Station && x.SessionID.Substring(0, 2) == SessionSymbol && x.IsReturn != true));
         var Items     = (from a in list
                          select new Source.Data.Entities.StationTracking
         {
             SessionID = a.SessionID,
             Station = a.Station,
             Year = a.Year,
             Seq = a.Seq,
             ColorCode = a.ColorCode,
             ColorName = a.ColorName,
             MaterialCo = a.MaterialCo,
             MaterialName = a.MaterialName,
             MaterialType = a.MaterialType,
             ScaleWeight = a.ScaleWeight,
             ScaleDate = a.ScaleDate,
             WinlineCode = a.WinlineCode,
             ItemName = a.ItemName,
             SessionParent = a.SessionParent,
             UserUpdate = a.UserUpdate,
             UserUpdateTime = a.UserUpdateTime,
             UserAdded = a.UserAdded,
             UserAddedTime = a.UserAddedTime,
             IsChecked = false,
             AutoId = Source.Data.SourceContext.Action.CreateAutoID(),
             UpdateStatus = "Unchanged"
         }
                          );
         return(new ObservableCollection <Source.Data.Entities.StationTracking>(Items.OrderByDescending(x => x.ScaleDate)));
     }
     catch (Exception err)
     {
         return(new ObservableCollection <Source.Data.Entities.StationTracking>());
     }
 }
Ejemplo n.º 5
0
        public static ObservableCollection <Source.Data.Entities.StockCloseEnds> ItemsSource()
        {
            try
            {
                var dbcontext = new Source.Data.SourceContext();

                var listStock = dbcontext.Stocks.ToList().GroupBy(x => new { x.Yy, x.Mm }).Select(x1 => new Source.Data.Entities.StockCloseEnds {
                    Yy           = x1.Key.Yy,
                    Mm           = x1.Key.Mm,
                    IsLock       = false,
                    IsDefault    = false,
                    IsChecked    = false,
                    AutoId       = Source.Data.SourceContext.Action.CreateAutoID(),
                    UpdateStatus = "Added"
                }).ToList();

                var list = dbcontext.StockCloseEnds.ToList();

                foreach (var item in listStock)
                {
                    var itemCheck = list.Where(x => x.Mm == item.Mm && x.Yy == item.Yy);

                    if (itemCheck.Count() > 0)
                    {
                        item.IsLock       = itemCheck.First().IsLock == null?false:itemCheck.First().IsLock;
                        item.IsDefault    = itemCheck.First().IsDefault == null?false: itemCheck.First().IsDefault;
                        item.UpdateStatus = "Modified";
                    }
                }



                return(new ObservableCollection <Source.Data.Entities.StockCloseEnds>(listStock));
            }
            catch (Exception err)
            {
                return(new ObservableCollection <Source.Data.Entities.StockCloseEnds>());
            }
        }
Ejemplo n.º 6
0
        public static Source.Data.SourceContext.MSG Save(Source.Data.Entities.StationTracking item, string Symbol)
        {
            var _return = new Source.Data.SourceContext.MSG();

            try
            {
                using (var dbContext = new Source.Data.SourceContext())
                {
                    //check the ObjectState property and mark appropriate EntityState
                    if (item.UpdateStatus == "Added")
                    {
                        var items     = dbContext.StationTrackings.Where(x => x.Station == item.Station && x.Year == item.Year);
                        var itemCheck = items.Where(s => s.SessionID == item.SessionID).ToList();
                        if (itemCheck.Count > 0)
                        {
                            _return.IsError        = true;
                            _return.MsgInformation = "Can not save data <<Duplication>>!";
                        }
                        else
                        {
                            item.UserAdded      = tmpLogin.Id;
                            item.UserAddedTime  = DateTime.Now;
                            item.UserUpdate     = tmpLogin.Id;
                            item.UserUpdateTime = DateTime.Now;

                            int MaxID = items.Count() == 0 ? 0 : items.Max(x => x == null ? 0 :(int)x.Seq);
                            item.Seq = MaxID + 1;


                            item.SessionID = Symbol + item.Year.Substring(2, 2) + item.Seq.ToString("00000#");



                            dbContext.Entry(item).State = System.Data.Entity.EntityState.Added;
                        }
                    }
                    else if (item.UpdateStatus == "Modified")
                    {
                        item.UserUpdate     = tmpLogin.Id;
                        item.UserUpdateTime = DateTime.Now;

                        dbContext.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        dbContext.Entry(item).Property(x => x.Seq).IsModified           = false;
                        dbContext.Entry(item).Property(x => x.UserAdded).IsModified     = false;
                        dbContext.Entry(item).Property(x => x.UserAddedTime).IsModified = false;
                        //dbContext.Entry(item).Property(x => x.Isdel).IsModified = false;
                    }
                    else if (item.UpdateStatus == "Deleted")
                    {
                        dbContext.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                    }
                    else
                    {
                        dbContext.Entry(item).State = System.Data.Entity.EntityState.Unchanged;
                    }
                    //=========================
                    if (_return.IsError != true)
                    {
                        dbContext.SaveChanges();
                        _return = new Source.Data.SourceContext.MSG(item.UpdateStatus, false);
                    }
                }
            }
            catch (Exception err)
            {
                _return = new Source.Data.SourceContext.MSG(item.UpdateStatus, true);
                _return.MsgInformation += "\n " + err.ToString();
            }
            return(_return);
        }
Ejemplo n.º 7
0
        public static Source.Data.SourceContext.MSG Save(Source.Data.Entities.Stocks item)
        {
            var _return = new Source.Data.SourceContext.MSG();

            try
            {
                using (var dbContext = new Source.Data.SourceContext())
                {
                    //check the ObjectState property and mark appropriate EntityState
                    if (item.UpdateStatus == "Added")
                    {
                        var items     = dbContext.Stocks;
                        var itemCheck = items.Where(s => s.Yy == item.Yy &&
                                                    s.Mm == item.Mm &&
                                                    s.ColorCode == item.ColorCode &&
                                                    s.MaterialCo == item.MaterialCo &&
                                                    s.MaterialType == item.MaterialType &&
                                                    s.StockName == item.StockName).ToList();
                        if (itemCheck.Count > 0)
                        {
                            _return.IsError        = true;
                            _return.MsgInformation = "Can not save data <<Duplication>>!";
                        }
                        else
                        {
                            //item.UserAdded = tmpLogin.Id;
                            //item.UserAddedTime = DateTime.Now;
                            //item.UserUpdate = tmpLogin.Id;
                            //item.UserUpdateTime = DateTime.Now;

                            //int MaxID = items.Count() == 0 ? 0 : items.Max(x => x == null ? 0 :(int)x.Seq);
                            //item.Seq = MaxID + 1;


                            //item.Yy = "I" +item.Seq.ToString();
                            //item.Mm = "I" +item.Seq.ToString();
                            //item.ColorCode = "I" +item.Seq.ToString();
                            //item.MaterialCo = "I" +item.Seq.ToString();
                            //item.MaterialType = "I" +item.Seq.ToString();
                            //item.StockName = "I" +item.Seq.ToString();


                            dbContext.Entry(item).State = System.Data.Entity.EntityState.Added;
                        }
                    }
                    else if (item.UpdateStatus == "Modified")
                    {
                        //item.UserUpdate = tmpLogin.Id;
                        //item.UserUpdateTime = DateTime.Now;

                        //dbContext.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        //dbContext.Entry(item).Property(x => x.Seq).IsModified = false;
                        //dbContext.Entry(item).Property(x => x.UserAdded).IsModified = false;
                        //dbContext.Entry(item).Property(x => x.UserAddedTime).IsModified = false;
                        //dbContext.Entry(item).Property(x => x.Isdel).IsModified = false;
                    }
                    else if (item.UpdateStatus == "Deleted")
                    {
                        dbContext.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                    }
                    else
                    {
                        dbContext.Entry(item).State = System.Data.Entity.EntityState.Unchanged;
                    }
                    //=========================
                    if (_return.IsError != true)
                    {
                        dbContext.SaveChanges();
                        _return = new Source.Data.SourceContext.MSG(item.UpdateStatus, false);
                    }
                }
            }
            catch (Exception err)
            {
                _return = new Source.Data.SourceContext.MSG(item.UpdateStatus, true);
                _return.MsgInformation += "\n " + err.ToString();
            }
            return(_return);
        }