//public void OnEstimationSubmitted()
        //{
        //    var items = _db.EST_Item.Where(x => x.EstRevID == EstRevID &&
        //                                        (x.StatusID == (int)NEstItemStatus.New | x.StatusID == (int)NEstItemStatus.ContentsChanged) &&
        //                                        x.ItemPurposeID == (short)NEstItemPurpose.ForEstimation
        //                                        ).ToList();

        //    //Save Existing Item to backup
        //    foreach (var item in items)
        //    {
        //        item.StatusID = (short)NEstItemStatus.Submitted;
        //        item.ItemPurposeID = (short)NEstItemPurpose.ForBackup;
        //        item.Version += 1;
        //        _db.Entry(item).State = EntityState.Modified;
        //    }
        //    _db.SaveChanges();

        //    //Copy For Estimation
        //    foreach (var item in items)
        //    {
        //        MyEstItemCopy itemCopy = new MyEstItemCopyForEstimation(item.EstItemID);
        //        itemCopy.Copy();
        //    }

        //    //Version +=1
        //    var est = _db.Sales_JobMasterList_EstRev.Find(EstRevID);
        //    est.erRev += 1;
        //    _db.Entry(est).State = EntityState.Modified;
        //    _db.SaveChanges();

        //}


        public void OnEstimationSubmitted()
        {
            var items = _db.EST_Item.Where(x => x.EstRevID == EstRevID &&
                                           (x.StatusID == (int)NEstItemStatus.New | x.StatusID == (int)NEstItemStatus.ContentsChanged) &&
                                           x.ItemPurposeID == (short)NEstItemPurpose.ForEstimation
                                           ).ToList();

            //Save Existing Item to backup
            foreach (var item in items)
            {
                item.StatusID         = (short)NEstItemStatus.Submitted;
                item.Version         += 1;
                _db.Entry(item).State = EntityState.Modified;
            }
            _db.SaveChanges();

            //Version +=1
            var est = _db.Sales_JobMasterList_EstRev.Find(EstRevID);

            est.erRev           += 1;
            _db.Entry(est).State = EntityState.Modified;
            _db.SaveChanges();

            var task = _db.Sales_Dispatching.Find(TaskID);

            task.Importance       = est.erRev;
            _db.Entry(task).State = EntityState.Modified;
            _db.SaveChanges();
        }
        //private bool DeleteCategory()
        //{
        //    var isRefresh = false;
        //    var cat0s = _db.MaterialCategory0.Where(x => x.CategoryID > 0).OrderBy(x => x.CategoryID).ToList();
        //    foreach (var cat0 in cat0s)
        //    {
        //        var cat1s = cat0.MaterialCategory1.ToList();
        //        foreach (var cat1 in cat1s)
        //        {
        //            var cat2s = cat1.MaterialCategory2.ToList();
        //            foreach (var cat2 in cat2s)
        //            {
        //                var cat3s = cat2.MaterialCategory3.ToList();
        //                foreach (var cat3 in cat3s)
        //                {
        //                    var cat4s = cat3.MaterialCategory4.ToList();
        //                    foreach (var cat4 in cat4s)
        //                    {
        //                        if (cat4.Materials.Any()) continue;
        //                        _db.Entry(cat4).State = EntityState.Deleted;
        //                        _db.SaveChanges();
        //                        isRefresh = true;
        //                        break;
        //                    }
        //                    if (isRefresh) break;
        //                    if (cat3.Materials.Any()) continue;
        //                    _db.Entry(cat3).State = EntityState.Deleted;
        //                    _db.SaveChanges();
        //                    isRefresh = true;
        //                    break;
        //                }
        //                if (isRefresh) break;
        //                if (cat2.Materials.Any()) continue;
        //                _db.Entry(cat2).State = EntityState.Deleted;
        //                _db.SaveChanges();
        //                isRefresh = true;
        //                break;
        //            }
        //            if (isRefresh) break;
        //            if (cat1.Materials.Any()) continue;
        //            _db.Entry(cat1).State = EntityState.Deleted;
        //            _db.SaveChanges();
        //            isRefresh = true;
        //            break;
        //        }
        //        if (isRefresh) break;
        //        if (cat0.Materials.Any()) continue;
        //        _db.Entry(cat0).State = EntityState.Deleted;
        //        _db.SaveChanges();
        //        isRefresh = true;
        //        break;
        //    }
        //    return isRefresh;
        //}


        private void DeleteCategor4()
        {
            var cat0s = _db.MaterialCategory0.Where(x => x.CategoryID > 0).OrderBy(x => x.CategoryID).ToList();

            foreach (var cat0 in cat0s)
            {
                var cat1s = cat0.MaterialCategory1.ToList();
                foreach (var cat1 in cat1s)
                {
                    var cat2s = cat1.MaterialCategory2.ToList();
                    foreach (var cat2 in cat2s)
                    {
                        var cat3s = cat2.MaterialCategory3.ToList();
                        foreach (var cat3 in cat3s)
                        {
                            var cat4s = cat3.MaterialCategory4.ToList();
                            foreach (var cat4 in cat4s)
                            {
                                if (cat4.Materials.Any())
                                {
                                    continue;
                                }
                                _db.Entry(cat4).State = EntityState.Deleted;
                            }
                            _db.SaveChanges();
                        }
                    }
                }
            }
        }
Example #3
0
        public MyCrEstimationRequisitionItem(int estRevID, long estItemID, int employeeID)
        {
            _printingEmployeeID = employeeID;
            Items = new List <CR_EstimationRequisitionItem>();

            if (estItemID > 0)
            {
                var estItem = _db.EST_Item.Find(estItemID);
                Items.AddRange(GetItems(estItem));
                estItem.Size = GetSize(estItem.EstItemID, estItem.Product.CategoryID);
                estItem.ReportDescription = GetReportDescription(estItem);
                _db.Entry(estItem).State  = EntityState.Modified;
            }
            else
            {
                var estItems = _db.EST_Item.Where(x => x.EstRevID == estRevID).ToList();
                foreach (var estItem in estItems)
                {
                    Items.AddRange(GetItems(estItem));
                    estItem.Size = GetSize(estItem.EstItemID, estItem.Product.CategoryID);
                    estItem.ReportDescription = GetReportDescription(estItem);
                    _db.Entry(estItem).State  = EntityState.Modified;
                }
            }

            _db.SaveChanges();
        }
        public void Delete()
        {
            if (!IsDeletable)
            {
                return;
            }

            var cat3s = _category2.MaterialCategory3.ToList();

            foreach (var cat3 in cat3s)
            {
                var cat4s = cat3.MaterialCategory4.ToList();
                foreach (var cat4 in cat4s)
                {
                    _db.Entry(cat4).State = EntityState.Deleted;
                }
                _db.SaveChanges();

                _db.Entry(cat3).State = EntityState.Deleted;
            }
            _db.SaveChanges();

            _db.Entry(_category2).State = EntityState.Deleted;
            _db.SaveChanges();
        }
Example #5
0
        public void UpdateBase()
        {
            try
            {
                //MyReflection.Copy(Value, newValue );
                var item = _db.EST_Item.Find(Value.EstItemID);
                item.EstItemID = Value.EstItemID;
                item.IsPreviousEstimationAvailable = Value.IsPreviousEstimationAvailable;

                item.EstItemNo       = Value.EstItemNo;
                item.EstPart         = Value.EstPart;
                item.ItemOption      = Value.ItemOption;
                item.IsFinalOption   = Value.IsFinalOption;
                item.PositionID      = Value.PositionID;
                item.RequirementID   = Value.RequirementID;
                item.BySubcontractor = Value.BySubcontractor;
                item.Qty             = Value.Qty;

                //              $(" #SpecialMaterialLeadTime, #SpecialMaterial, #IsThereSpecialMaterial").attr('disabled', true);
                if (MyAuthorization.IsResponseOwner)
                {
                    item.Description             = Value.Description;
                    item.Remark                  = Value.Remark;
                    item.IsThereSpecialMaterial  = Value.IsThereSpecialMaterial;
                    item.SpecialMaterial         = Value.SpecialMaterial;
                    item.SpecialMaterialLeadTime = Value.SpecialMaterialLeadTime;
                }

                if (MyAuthorization.IsRequestOwner)
                {
                    item.SalesDescription = Value.SalesDescription;
                }

                if (IsBiddingJob)
                {
                    item.BidSignIdCode       = Value.BidSignIdCode;
                    item.BidReferenceDrawing = Value.BidReferenceDrawing;
                    item.BidDescription      = Value.BidDescription;
                    item.BidRemark           = Value.BidRemark;
                }


                item.IsTemplateApplicable = Value.IsTemplateApplicable;
                item.StatusID             = Value.StatusID;

                _db.Entry(item).State = EntityState.Modified;
                _db.SaveChanges();
            }
            catch (Exception ex)
            {
                var s = ex.Message;
                throw;
            }
        }
Example #6
0
        public void Insert()
        {
            //Insert Categories if not exist
            var mc0 = new MyMaterialCategory0();

            CategoryID0 = mc0.CreateCategoryID(CategoryID0, 0, CategoryName0);

            var mc1 = new MyMaterialCategory1();

            CategoryID1 = mc1.CreateCategoryID(CategoryID1, CategoryID0, CategoryName1);

            var mc2 = new MyMaterialCategory2();

            CategoryID2 = mc2.CreateCategoryID(CategoryID2, CategoryID1, CategoryName2);

            var mc3 = new MyMaterialCategory3();

            CategoryID3 = mc3.CreateCategoryID(CategoryID3, CategoryID2, CategoryName3);

            var mc4 = new MyMaterialCategory4();

            CategoryID4 = mc4.CreateCategoryID(CategoryID4, CategoryID3, CategoryName4);


            //1. Insert material
            var material = new SpecDomain.Model.Material();

            MyReflection.Copy(this, material);
            _db.Materials.Add(material);
            _db.SaveChanges();


            //2. Insert Price
            var price = new MaterialPrice
            {
                MaterialID         = material.MaterialID,
                UnitID             = UnitID,
                Price              = Price,
                InvoicePriceUnitID = UnitID,
                VenderID           = 0,
                Active             = true
            };

            _db.MaterialPrices.Add(price);
            _db.SaveChanges();

            //3. Update Price
            material.PriceID          = price.PriceID;
            material.UnitID           = price.UnitID;
            material.Price            = Price;
            _db.Entry(material).State = EntityState.Modified;
            _db.SaveChanges();
        }
Example #7
0
 public void Delete()
 {
     try
     {
         _db.Entry(Value).State = EntityState.Deleted;
         _db.SaveChanges();
     }
     catch (DbEntityValidationException dbEx)
     {
         DeleteResult = dbEx.Message;
         throw;
     }
 }
        public void OnSalesDispatchingTaskDeleted(long salesDispatchingTaskID)
        {
            var db       = new SpecificationDbEntities();
            var reqTitle = db.Sales_Dispatching_DrawingRequisition_Estimation.FirstOrDefault(x => x.SubmitID == salesDispatchingTaskID);

            if (reqTitle == null)
            {
                return;
            }

            reqTitle.SubmitID = 0;
            var ver = reqTitle.Version;

            if (ver > 1)
            {
                ver = ver - 1;
                reqTitle.Version = ver;
            }
            else
            {
                reqTitle.Version = 0;
            }
            db.Entry(reqTitle).State = EntityState.Modified;
            db.SaveChanges();

            if (reqTitle.Version > 0)
            {
                return;
            }

            //Reset Item Status to Original
            var items = db.EST_Item.Where(x => x.EstRevID == reqTitle.EstRevID).ToList();

            foreach (var item in items)
            {
                if (item.Sales_Dispatching_DrawingRequisition_EstimationItem == null)
                {
                    continue;
                }
                if (!item.Sales_Dispatching_DrawingRequisition_EstimationItem.Any( ))
                {
                    continue;
                }
                foreach (var req in item.Sales_Dispatching_DrawingRequisition_EstimationItem)
                {
                    req.Status          = 0;
                    db.Entry(req).State = EntityState.Modified;
                }
            }
            db.SaveChanges();
        }
Example #9
0
        public void DeActiveExistingPrices()
        {
            var mps = _db.MaterialPrices.Where(x => x.MaterialID == Value.MaterialID).ToList();

            if (mps.Count <= 0)
            {
                return;
            }
            foreach (var mp in mps)
            {
                mp.Active           = false;
                _db.Entry(mp).State = EntityState.Modified;
                _db.SaveChanges();
            }
        }
Example #10
0
        public void EstimatorFinished()
        {
            Value.erLocked = false;
            //ItemStauts=Estimated if purpose=estimation
            var existingItems = _db.EST_Item.Where(x => x.EstRevID == _estRevID &
                                                   x.ItemPurposeID == (int)NEstItemPurpose.ForEstimation &
                                                   x.StatusID != (int)NEstItemStatus.Estimated &
                                                   x.StatusID != (int)NEstItemStatus.New
                                                   ).ToList();

            // Update Status to Estimated
            foreach (var item in existingItems)
            {
                item.StatusID = (int)NEstItemStatus.Estimated;
            }
            _db.Entry(Value).State = EntityState.Modified;
            _db.SaveChanges();

            //Copy to Backup
            foreach (var item in existingItems)
            {
                var estItemCopy = new MyEstItemCopyToBackup(item.EstItemID);
                estItemCopy.Copy();
            }
        }
Example #11
0
        private void UpdateEstService(long estServiceID, double?cost, string detail, string name, short qsServiceID, string note)
        {
            try
            {
                var service = _db.EST_Service.Find(estServiceID);
                if (service != null)
                {
                    if (cost != null && cost > 0)
                    {
                        service.qsAmount     = "$" + cost.ToString();
                        service.qsAmountText = "$" + cost.ToString();
                    }
                    else
                    {
                        service.qsAmount     = note;
                        service.qsAmountText = note;
                    }

                    service.qsTitle       = name;
                    service.qsDescription = (detail == null ? "" : detail);
                    service.qsServiceID   = qsServiceID;

                    _db.Entry(service).State = EntityState.Modified;
                    _db.SaveChanges();

                    LogMethods.Log.Debug("UpdateEstService:Debug:" + "Done");
                }
            }
            catch (Exception e)
            {
                LogMethods.Log.Error("UpdateEstService:Error:" + e.Message);
            }
        }
Example #12
0
        public void UpdateDefaultValue(int optionID)
        {
            if (Value == null)
            {
                return;
            }

            var option = _db.EST_Item_Specification_Template_Option.Find(optionID);

            OptionName = option.OptionName;

            Value.DefaultValue       = optionID;
            Value.DefaultValueString = OptionName;
            _db.Entry(Value).State   = EntityState.Modified;
            _db.SaveChanges();
        }
Example #13
0
        public void Delete(long drawingID)
        {
            var db  = new SpecificationDbEntities();
            var drw = db.EST_Drawing.Find(drawingID);

            db.Entry(drw).State = EntityState.Deleted;
            db.SaveChanges();
        }
Example #14
0
        public void Update()
        {
            //Price Table It's self
            var mp = _db.MaterialPrices.Find(PriceID);

            MyReflection.Copy(this, mp);
            _db.Entry(mp).State = EntityState.Modified;

            //Sync copy of the contens in Table.Material
            var material = _db.Materials.Find(MaterialID);

            material.PriceID          = PriceID;
            material.UnitID           = UnitID;
            material.Price            = MyCommon.MyConvert.ConvertToDouble(Price);
            _db.Entry(material).State = EntityState.Modified;
            _db.SaveChanges();
        }
 //3. Update Price
 private void UpdateMaterialPrice()
 {
     _myMaterial.PriceID          = _myPrice.PriceID;
     _myMaterial.UnitID           = _myPrice.UnitID;
     _myMaterial.Price            = Convert.ToDouble(_myPrice.Price);
     _db.Entry(_myMaterial).State = EntityState.Modified;
     _db.SaveChanges();
 }
        public void Delete()
        {
            if (!DeleteValidation.IsValid)
            {
                return;
            }

            var prices = _material.MaterialPrices.ToList();

            foreach (var price in prices)
            {
                _db.Entry(price).State = EntityState.Deleted;
            }
            _db.SaveChanges();

            _db.Entry(_material).State = EntityState.Deleted;
            _db.SaveChanges();
        }
 public void Delete()
 {
     if (!IsDeletable)
     {
         return;
     }
     _db.Entry(_category4).State = EntityState.Deleted;
     _db.SaveChanges();
 }
        //ID did not change
        public void Update(int categoryID, int parentID, string categoryName, Int16 statusID)
        {
            var cat = _db.MaterialCategory0.Find(categoryID);

            cat.ParentID         = parentID;
            cat.CategoryName     = categoryName;
            cat.Status           = statusID;
            _db.Entry(cat).State = EntityState.Modified;
            _db.SaveChanges();
        }
Example #19
0
        public void Authorization(int estRevID)
        {
            var employeesEnabledSpecificationTemplateEdit = new int[] { 12, 28, 8, 93 };
            var employeesEnabledCostTemplateEdit          = new int[] { 12, 28, 8, 93 };

            Value.IsAuthorized    = false;
            Value.IsResponseOwner = false;
            Value.IsRequestOwner  = false;
            Value.IsLocked        = false;
            Value.IsSpecificationTemplateEditEnabled = false;
            Value.IsCostTemplateEditEnabled          = false;

            var role = new EmployeeRole(Value.EmployeeID);

            if (role.IsInRoles(FsMembershipAuthorizationArray.PageEstimationEstimatorOnlyControlsEnabled))
            {
                Value.IsAuthorized    = true;
                Value.IsResponseOwner = true;
            }

            if (role.IsInRoles(FsMembershipAuthorizationArray.PageEstimationModifyContentsEnabled))
            {
                Value.IsAuthorized   = true;
                Value.IsRequestOwner = true;
            }

            //  if (!Value.IsRequestOwner) return;

            Value.EstRevID = estRevID;
            var est = _db.Sales_JobMasterList_EstRev.Find(estRevID);

            Value.ProjectID = est.JobID;
            var job = new SpecProjectDetail(est.JobID);

            if (Value.EmployeeID != job.Sales && Value.EmployeeID != job.Sa1ID)
            {
                Value.IsRequestOwner = false;
            }

            if (Value.EmployeeID == 12 || Value.EmployeeID == 28)
            {
                Value.IsRequestOwner  = true;
                Value.IsResponseOwner = true;
            }

            //
            Value.IsSpecificationTemplateEditEnabled = employeesEnabledSpecificationTemplateEdit.Contains(Value.EmployeeID);
            Value.IsCostTemplateEditEnabled          = employeesEnabledCostTemplateEdit.Contains(Value.EmployeeID);

            _db.Entry(Value).State = EntityState.Modified;
            _db.SaveChanges();
        }
Example #20
0
        public void Initialization()
        {
            DrawingRequisitionTitle = _db.Sales_Dispatching_DrawingRequisition_Estimation.FirstOrDefault(x => x.EstRevID == _estRevID);
            _validation             = new DrawingRequisitionFormPreValidation(_projectID, _estRevID);

            if (DrawingRequisitionTitle == null)
            {
                DrawingRequisitionTitle = CreateNewTitle();
            }
            else
            {
                if (DrawingRequisitionTitle.InstalltoCustomerID != _validation.InstallToCustomerID |
                    DrawingRequisitionTitle.MallID != _validation.MallID)
                {
                    DrawingRequisitionTitle.InstalltoCustomerID = _validation.InstallToCustomerID;
                    DrawingRequisitionTitle.MallID = _validation.MallID;

                    _db.Entry(DrawingRequisitionTitle).State = EntityState.Modified;
                    _db.SaveChanges();
                }
            }
        }
        private void OnSubmitted(long taskID)
        {
            //Item
            var items = _db.EST_Item.Where(x => x.EstRevID == EstRevID).ToList();

            foreach (var item in items)
            {
                if (item.Sales_Dispatching_DrawingRequisition_EstimationItem == null)
                {
                    continue;
                }
                if (!item.Sales_Dispatching_DrawingRequisition_EstimationItem.Any( ))
                {
                    continue;
                }
                foreach (var req in item.Sales_Dispatching_DrawingRequisition_EstimationItem)
                {
                    if (!req.IsIncludedWhenPrint)
                    {
                        continue;
                    }
                    if (req.Status == 0)
                    {
                        req.Status           = 1;
                        _db.Entry(req).State = EntityState.Modified;
                    }
                }
            }
            _db.SaveChanges();

            //Update TaskID
            var title = _db.Sales_Dispatching_DrawingRequisition_Estimation.Find(RequisitionID);

            title.Version          = title.Version + 1;
            title.SubmitID         = taskID;
            _db.Entry(title).State = EntityState.Modified;
            _db.SaveChanges();
        }
Example #22
0
 private void DeleteDrawingRequisitionItem()
 {
     try
     {
         var objDeletes =
             _db.Sales_Dispatching_DrawingRequisition_EstimationItem.Where(x => x.EstItemID == _estItemID)
             .ToList();
         foreach (var obj in objDeletes)
         {
             _db.Entry(obj).State = EntityState.Deleted;
         }
         _db.SaveChanges();
     }
     catch (DbEntityValidationException dbEx)
     {
         throw;
     }
 }
Example #23
0
        public void Refresh()
        {
            var existingItems = _db.CR_CostItem.Where(x => x.PrintingEmployeeID == _printingEmployeeID).ToList();

            if (existingItems.Any())
            {
                foreach (var ei in existingItems)
                {
                    _db.Entry(ei).State = EntityState.Deleted;
                }
                _db.SaveChanges();
            }

            foreach (var item in _items)
            {
                _db.CR_CostItem.Add(item);
            }
            _db.SaveChanges();
        }
Example #24
0
        private void CreateNewSpecialFields()
        {
            //Supposed to Have Fields
            var configuedFields = _db.EST_Item_Specification_Template.Where(x => x.ProductID == _product.ProductID)
                                  .OrderBy(x => x.OrderNumber)
                                  .ToList();

            if (!configuedFields.Any())
            {
                //Disble Template
                var newValue = _db.EST_Item.Find(_estItemID);
                newValue.IsTemplateApplicable = false;
                _db.Entry(newValue).State     = EntityState.Modified;
                _db.SaveChanges();
                return;
            }
            try
            {
                foreach (var field in configuedFields)
                {
                    var item = new EST_Item_Specification()
                    {
                        EstItemID     = _estItemID,
                        OrderNumber   = field.OrderNumber,
                        Title         = field.Title,
                        OptionGroupID = field.OptionGroupID,
                        Contents      = GetDefaultSpecialContents(field.DefaultValue),
                        IsMandatory   = field.IsMandatory,
                    };
                    _db.EST_Item_Specification.Add(item);
                }
                _db.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                var s = dbEx.Message;
                throw;
            }
        }
        public MaterialCategoryDelete()
        {
            var cat0s = _db.MaterialCategory0.Where(x => x.CategoryID > 0).ToList();

            foreach (var cat0 in cat0s)
            {
                var cat1s = cat0.MaterialCategory1.ToList();
                foreach (var cat1 in cat1s)
                {
                    var cat2s = cat1.MaterialCategory2.ToList();
                    foreach (var cat2 in cat2s)
                    {
                        var cat3s = cat2.MaterialCategory3.ToList();
                        foreach (var cat3 in cat3s)
                        {
                            var b     = false;
                            var cat4s = cat3.MaterialCategory4.ToList();
                            foreach (var cat4 in cat4s)
                            {
                                if (cat4.Materials.Any())
                                {
                                    continue;
                                }
                                //cat4.MaterialCategory3.MaterialCategory2.MaterialCategory1.MaterialCategory0.

                                _db.Entry(cat4).State = EntityState.Deleted;
                                b = true;
                            }
                            if (b)
                            {
                                _db.SaveChanges();
                            }
                        }
                    }
                }
            }
        }
Example #26
0
 public void Update()
 {
     _db.Entry(Value).State = EntityState.Modified;
     _db.SaveChanges();
     var hello = "World";
 }
Example #27
0
 public void UpdateDescription(string textValue)
 {
     _estItem.Description      = textValue;
     _db.Entry(_estItem).State = EntityState.Modified;
     _db.SaveChanges();
 }
Example #28
0
 public void Update()
 {
     _db.Entry(Value).State = EntityState.Modified;
     _db.SaveChanges();
 }
Example #29
0
        private void GetEstimationApprovalData(string sfEstimaitonID, int jobId, int estRevID, enterprise.QueryResult result, double?version, int employeeNumber, double?estHour, DateTime?dueDate, DateTime?dueTime, DateTime?issueDateTime)
        {
            try
            {
                if (version == null || result == null || (result != null && result.size == 0))
                {
                    return;
                }

                //cast query results
                IEnumerable <enterprise.ProcessInstance> processInstanceList = result.records.Cast <enterprise.ProcessInstance>();

                foreach (var el in processInstanceList)
                {
                    if (el.Status == "Pending")
                    {
                        var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.JobID == jobId && x.TaskType == 201 && x.Importance == version).FirstOrDefault();
                        if (sales_Dispatching == null)
                        {
                            SubmitEstimationRequestVm vm = new SubmitEstimationRequestVm();
                            vm.JobID       = jobId;
                            vm.EstRevID    = estRevID;
                            vm.SubmitBy    = employeeNumber;
                            vm.EstimatorID = 8; //mr Fan

                            if (dueDate != null)
                            {
                                if (dueTime != null)
                                {
                                    TimeZone localZone  = TimeZone.CurrentTimeZone;
                                    DateTime currentUTC = localZone.ToUniversalTime(dueTime.Value);
                                    DateTime localTime  = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, currentUTC.Hour, currentUTC.Minute, 00);
                                    if (localZone.IsDaylightSavingTime(localTime))
                                    {
                                        localTime = localTime.AddHours(-1);
                                    }
                                    vm.FormatedRequiredTime = localTime.ToString("MMM dd, yyyy  hh:mm tt");
                                }
                                else
                                {
                                    vm.FormatedRequiredTime = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, dueDate.Value.Hour, dueDate.Value.Minute, 00).ToString("MMM dd, yyyy  hh:mm tt");
                                }
                            }
                            else
                            {
                                DateTime dt1 = MyDateTime.GetDateOfAddedBusinessDays(DateTime.Today, 2);
                                DateTime dt2 = DateTime.Now.AddMinutes(2);
                                vm.FormatedRequiredTime =
                                    new DateTime(dt1.Year, dt1.Month, dt1.Day, dt2.Hour, dt2.Minute, 00).ToString("MMM dd, yyyy  hh:mm tt");
                            }

                            if (issueDateTime != null)
                            {
                                vm.Create(issueDateTime.Value.ToLocalTime());
                            }
                            else
                            {
                                vm.Create();
                            }
                            vm.OnEstimationSubmittedWithoutChangingEstVer();
                        }
                    }
                    else if (el.Status == "Approved")
                    {
                        var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.JobID == jobId && x.TaskType == 201 && x.Importance == version).FirstOrDefault();
                        if (sales_Dispatching != null)
                        {
                            if (estHour != null)
                            {
                                sales_Dispatching.WorkedHour = estHour;
                            }
                            sales_Dispatching.Status = 249;
                            if (el.CompletedDate != null)
                            {
                                sales_Dispatching.FinishedDate = el.CompletedDate.Value.ToLocalTime();
                            }

                            _db.Entry(sales_Dispatching).State = EntityState.Modified;
                            _db.SaveChanges();
                        }
                    }
                    else if (el.Status == "Removed")
                    {
                        var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.JobID == jobId && x.TaskType == 201 && x.Importance == version + 1).FirstOrDefault();
                        if (sales_Dispatching != null)
                        {
                            /* delete a row in Sales_Dispatching */
                            _db.Sales_Dispatching.Remove(sales_Dispatching);
                            _db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogMethods.Log.Error("GetEstimationApprovalData:Error:" + e.Message);
            }
        }
Example #30
0
        private void GetDrawingApprovalData(int jobId, enterprise.QueryResult result, double?version, int employeeNumber, double?drawHour, DateTime?dueDate, int requisitionId, string drawingType, string sfDrawingID, double?NumofDrawings, DateTime?dueTime, DateTime?issueDateTime)
        {
            try
            {
                if (version == null || result == null || (result != null && result.size == 0))
                {
                    return;
                }

                //cast query results
                IEnumerable <enterprise.ProcessInstance> processInstanceList = result.records.Cast <enterprise.ProcessInstance>();

                foreach (var el in processInstanceList)
                {
                    int   taskType   = 501;
                    short taskStatus = 549;
                    if (drawingType.Trim() == "Structure")
                    {
                        taskType   = 551;
                        taskStatus = 599;
                    }

                    if (el.Status == "Pending")
                    {
                        int drawingID = CommonMethods.GetMISID(TableName.Sales_Dispatching, sfDrawingID, salesForceProjectID);
                        if (drawingID == 0)
                        {
                            //not exist
                            var vm = new SubmitDrawingRequestVm(requisitionId, employeeNumber);
                            if (dueDate != null)
                            {
                                if (dueTime != null)
                                {
                                    TimeZone localZone  = TimeZone.CurrentTimeZone;
                                    DateTime currentUTC = localZone.ToUniversalTime(dueTime.Value);
                                    DateTime localTime  = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, currentUTC.Hour, currentUTC.Minute, 00);
                                    if (localZone.IsDaylightSavingTime(localTime))
                                    {
                                        localTime = localTime.AddHours(-1);
                                    }
                                    vm.FormatedRequiredTime = localTime.ToString("MMM dd, yyyy  hh:mm tt");
                                }
                                else
                                {
                                    vm.FormatedRequiredTime = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, dueDate.Value.Hour, dueDate.Value.Minute, 00).ToString("MMM dd, yyyy  hh:mm tt");
                                }
                            }
                            else
                            {
                                DateTime dt1 = MyDateTime.GetDateOfAddedBusinessDays(DateTime.Today, 2);
                                DateTime dt2 = DateTime.Now.AddMinutes(2);
                                vm.FormatedRequiredTime =
                                    new DateTime(dt1.Year, dt1.Month, dt1.Day, dt2.Hour, dt2.Minute, 00).ToString("MMM dd, yyyy  hh:mm tt");
                            }
                            long taskID;
                            if (issueDateTime == null)
                            {
                                taskID = vm.Create();
                            }
                            else
                            {
                                taskID = vm.Create(issueDateTime.Value.ToLocalTime());
                            }
                            if (taskID > 0)
                            {
                                CommonMethods.InsertToMISSalesForceMapping(TableName.Sales_Dispatching, sfDrawingID, taskID.ToString(), salesForceProjectID);
                            }
                        }

                        /*
                         * var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.JobID == jobId && x.TaskType == taskType && x.Importance == version).FirstOrDefault();
                         * if (sales_Dispatching == null)
                         * {
                         *  var vm = new SubmitDrawingRequestVm(requisitionId, employeeNumber);
                         *  if (dueDate != null)
                         *  {
                         *      vm.FormatedRequiredTime = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, dueDate.Value.Hour, dueDate.Value.Minute, 00).ToString("MMM dd, yyyy  hh:mm tt");
                         *  }
                         *  else
                         *  {
                         *      DateTime dt1 = MyDateTime.GetDateOfAddedBusinessDays(DateTime.Today, 2);
                         *      DateTime dt2 = DateTime.Now.AddMinutes(2);
                         *      vm.FormatedRequiredTime =
                         *          new DateTime(dt1.Year, dt1.Month, dt1.Day, dt2.Hour, dt2.Minute, 00).ToString("MMM dd, yyyy  hh:mm tt");
                         *  }
                         *  vm.Create();
                         * }
                         * */
                    }
                    else if (el.Status == "Approved")
                    {
                        int drawingID = CommonMethods.GetMISID(TableName.Sales_Dispatching, sfDrawingID, salesForceProjectID);
                        if (drawingID > 0)
                        {
                            var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.TaskID == drawingID).FirstOrDefault();
                            if (sales_Dispatching != null)
                            {
                                if (drawHour != null)
                                {
                                    sales_Dispatching.WorkedHour = drawHour;
                                }

                                if (NumofDrawings != null)
                                {
                                    sales_Dispatching.NumberOfDrawing = Convert.ToInt32(NumofDrawings);
                                }

                                sales_Dispatching.Status = taskStatus;
                                if (el.CompletedDate != null)
                                {
                                    sales_Dispatching.FinishedDate = el.CompletedDate.Value.ToLocalTime();
                                }

                                _db.Entry(sales_Dispatching).State = EntityState.Modified;
                                _db.SaveChanges();
                            }
                        }
                    }
                    else if (el.Status == "Removed")
                    {
                        int drawingID = CommonMethods.GetMISID(TableName.Sales_Dispatching, sfDrawingID, salesForceProjectID);
                        if (drawingID > 0)
                        {
                            var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.TaskID == drawingID).FirstOrDefault();
                            if (sales_Dispatching != null)
                            {
                                /* delete a row in Sales_Dispatching */
                                _db.Sales_Dispatching.Remove(sales_Dispatching);
                                _db.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogMethods.Log.Error("GetDrawingApprovalData:Error:" + e.Message);
            }
        }