Example #1
0
        public void CreateRequisitionItems()
        {
            foreach (var lkv in AvailableEstItems)
            {
                var estItem = _db.EST_Item.Find(lkv.Key);
                var reqItem = GetNewSalesDispatchingDrawingRequisitionEstimationItem(estItem, RequisitionID, lkv.IsChecked);
                _db.Sales_Dispatching_DrawingRequisition_EstimationItem.Add(reqItem);
                _db.SaveChanges();
                lkv.Value2 = reqItem.RequisitionItemID.ToString();
            }

            //_db.SaveChanges();
        }
Example #2
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();
                }
            }
        }
        public void Create()
        {
            InitializeCreateData();
            var task = new Sales_Dispatching();

            MyReflection.Copy(this, task);
            task.Responsible = (short)EstimatorID;
            _db.Sales_Dispatching.Add(task);
            _db.SaveChanges();

            TaskID = task.TaskID;
        }
Example #4
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 #5
0
        private void CreateSalesJobMasterListEstRev(int jobID)
        {
            var job   = new SpecProjectDetail(jobID);
            var sa1ID = job.Sa1ID;

            //public int EstRevID { get; set; }
            var est = new Sales_JobMasterList_EstRev
            {
                JobID    = jobID,
                erRev    = 0,
                erLocked = false,
                erAmount = 0,
                sa1ID    = sa1ID,
                TaskID   = 0
            };

            //Save to DB
            _db.Sales_JobMasterList_EstRev.Add(est);
            _db.SaveChanges();

            //Output
            NewEstRevID = est.EstRevID;
        }
Example #6
0
        private int  CreateNewEstimation(int projectID)
        {
            var dbSpec = new SpecificationDbEntities();
            var est    = new Sales_JobMasterList_EstRev()
            {
                JobID = projectID,
                erRev = 1,
                sa1ID = 0
            };

            dbSpec.Sales_JobMasterList_EstRev.Add(est);
            dbSpec.SaveChanges();

            return(est.EstRevID);
        }
Example #7
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 #8
0
 public MyEstRevCreateConfiguration(int estRevID)
 {
     try
     {
         var config    = _db.EST_Cost_Configuration.Find(0);
         var newConfig = new EST_Cost_Configuration();
         MyCommon.MyReflection.Copy(config, newConfig);
         newConfig.EstRevID = estRevID;
         _db.EST_Cost_Configuration.Add(newConfig);
         _db.SaveChanges();
     }
     catch (DbEntityValidationException dbEx)
     {
         var s = dbEx.Message;
         throw;
     }
 }
Example #9
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();
        }
Example #10
0
        public DbMaterialCreateNewVm()
        {
            var vm = new FanMaterialCostBases();

            foreach (var fan in vm.Values)
            {
                var material = new SpecDomain.Model.Material()
                {
                    //public int DbItemID { get; set; }
                    //TypeID = 120,
                    //Name = fan.CostItemName,
                    //Unit = fan.Unit,
                    //UnitPrice = fan.UnitPrice,
                };
                _db.Materials.Add(material);
            }

            _db.SaveChanges();
        }
Example #11
0
        private long CreateNewEstItem(string productName)
        {
            try
            {
                var item = new EST_Item()
                {
                    EstRevID             = _estRevID,
                    SerialID             = EstItemCommon.GetNewSerialID(_estRevID),
                    EstItemNo            = (short)EstItemCommon.GetNewNumber(_estRevID),
                    ProductID            = _product.ProductID,
                    ProductName          = productName,
                    StatusID             = (int)NEstItemStatus.New,
                    EstPart              = 1,
                    ItemOption           = 1,
                    IsFinalOption        = true,
                    Qty                  = 1,
                    RequirementID        = (int)NWorkorderRequirement.Installation,
                    PositionID           = 10,
                    IsTemplateApplicable = true,
                    SizeRows             = _template.SizeTotalRows,
                    EstimatorPrice       = 0,
                    PriceA               = 0,
                    PriceB               = 0,
                    PriceExtra           = 0,
                };

                //Create New EstItem
                _db.EST_Item.Add(item);
                _db.SaveChanges();

                return(item.EstItemID);
            }
            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 #13
0
 public void Update()
 {
     _db.Entry(Value).State = EntityState.Modified;
     _db.SaveChanges();
     var hello = "World";
 }
Example #14
0
 public void UpdateDescription(string textValue)
 {
     _estItem.Description      = textValue;
     _db.Entry(_estItem).State = EntityState.Modified;
     _db.SaveChanges();
 }
Example #15
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 #16
0
 public void Update()
 {
     _db.Entry(Value).State = EntityState.Modified;
     _db.SaveChanges();
 }
Example #17
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);
            }
        }
Example #18
0
 public void Create()
 {
     _db.MaterialPrices.Add(Value);
     _db.SaveChanges();
 }