public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { DTO.ProductionTeamDto productionTeamDto = ((JObject)dtoItem).ToObject <DTO.ProductionTeamDto>(); notification = new Notification() { Type = NotificationType.Success }; try { using (var context = this.CreateContext()) { ProductionTeam productionTeam = new ProductionTeam(); if (id == 0) { context.ProductionTeam.Add(productionTeam); } if (id > 0) { productionTeam = context.ProductionTeam.FirstOrDefault(o => o.ProductionTeamID == id); if (productionTeam == null) { notification.Message = "Can not found data!"; return(false); } } this.converter.DTO2DB_ProductionTeam(productionTeamDto, ref productionTeam); productionTeam.UpdatedBy = userId; productionTeam.UpdatedDate = System.DateTime.Now; productionTeam.CompanyID = fwFactory.GetCompanyID(userId); context.SaveChanges(); dtoItem = this.GetData(productionTeam.ProductionTeamID, out notification); } return(true); } catch (System.Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; return(false); } }
public DTO.InitDTO GetInitDataReport(int userId, out Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; Support.DAL.DataFactory spF = new Support.DAL.DataFactory(); DTO.InitDTO data = new InitDTO(); int?companyID = fw_factory.GetCompanyID(userId); try { using (var context = CreateContext()) { data.productionTeams = AutoMapper.Mapper.Map <List <SupportMng_ProductionTeam_View>, List <Support.DTO.ProductionTeam> >(context.SupportMng_ProductionTeam_View.ToList()).ToList(); } data.clients = spF.GetClient().ToList(); return(data); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; return(data); } }
// // CUSTOM FUNCTION HERE // public override object GetInitData(int userID, out Notification notification) { notification = new Notification() { Type = NotificationType.Success }; Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); int?companyID = fwFactory.GetCompanyID(userID); SupportFormData data = new SupportFormData(); data.EmployeeDTOs = new List <EmployeeDTO>(); data.CompanyDTOs = new List <CompanyDTO>(); try { using (AnnualLeaveRptEntities context = CreateContext()) { data.EmployeeDTOs = converter.DB2DTO_EmployeeDTO(context.AnnualLeaveRpt_Employee_View.ToList()); data.CompanyDTOs = converter.DB2DTO_CompanyDTO(context.AnnualLeaveRpt_Company_View.Where(s => s.CompanyID == companyID).ToList()); } return(data); } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; return(data); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.ProductionPriceDTO dtoProductionPrice = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ProductionPriceDTO>(); try { int?companyID = fw_factory.GetCompanyID(userId); using (ProductionPriceMngEntities context = CreateContext()) { ProductionPrice dbItem = null; if (id == 0) { dbItem = new ProductionPrice(); context.ProductionPrice.Add(dbItem); } else { dbItem = context.ProductionPrice.Where(o => o.ProductionPriceID == id).FirstOrDefault(); } if (dbItem == null) { notification.Message = "data not found!"; return(false); } else { //convert dto to db converter.DTO2DB_ProductionPrice(dtoProductionPrice, ref dbItem, userId, companyID); //remove orphan context.ProductionPriceDetail.Local.Where(o => o.ProductionPrice == null).ToList().ForEach(o => context.ProductionPriceDetail.Remove(o)); //save data context.SaveChanges(); // Run automatic update unit price if (dtoProductionPrice.UpdateTypeID.HasValue && dtoProductionPrice.UpdateTypeID.Value == 2) { context.ProductionPriceMng_function_UpdatePriceReceivingNote(dbItem.ProductionPriceID); } //get return data dtoItem = GetData(dbItem.ProductionPriceID, out notification).Data; return(true); } } } catch (Exception ex) { Exception iEx = Library.Helper.GetInnerException(ex); notification.Type = NotificationType.Error; notification.Message = iEx.Message; return(false); } }
public DTO.SearchData Search(int userId, Hashtable filter, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Notification notification) { totalRows = 0; notification = new Notification() { Type = NotificationType.Success }; DTO.SearchData data = new SearchData() { Data = new List <OPSequenceSearchResultDto>() }; try { using (var context = this.CreateContext()) { string opSequenceNm = filter["OPSequenceNM"]?.ToString().Replace("'", "''"); string companyID = fwFactory.GetCompanyID(userId).HasValue ? fwFactory.GetCompanyID(userId).Value.ToString() : null; //var result = context.EmployeeMng_Employee_View.FirstOrDefault(o => o.UserID == userId); //if (result != null) // companyID = result.CompanyID.ToString(); totalRows = context.OPSequence_function_OPSequenceSearchResult(opSequenceNm, companyID, orderBy, orderDirection).Count(); data.Data = converter.DB2DTO_Search(context.OPSequence_function_OPSequenceSearchResult(opSequenceNm, companyID, orderBy, orderDirection).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList()); } } catch (Exception ex) { notification = new Notification() { Type = NotificationType.Error, Message = ex.Message }; return(data); } return(data); }
public override DTO.SearchFormData GetDataWithFilter(int userId, System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification) { DTO.SearchFormData searchFormData = new DTO.SearchFormData(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; totalRows = 0; try { int? workCenterID = null; string producedDate = null; int?companyID = fw_factory.GetCompanyID(userId); if (filters.ContainsKey("workCenterID") && filters["workCenterID"] != null) { workCenterID = Convert.ToInt32(filters["workCenterID"]); } if (filters.ContainsKey("producedDate") && !string.IsNullOrEmpty(filters["producedDate"].ToString())) { producedDate = filters["producedDate"].ToString().Replace("'", "''"); } using (ProductionStatisticsMngEntities context = CreateContext()) { totalRows = context.ProductionStatisticsMng_function_SearchProductionStatistics(orderBy, orderDirection, companyID, workCenterID, producedDate).Count(); var result = context.ProductionStatisticsMng_function_SearchProductionStatistics(orderBy, orderDirection, companyID, workCenterID, producedDate); searchFormData.Data = converter.DB2DTO_Search(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(searchFormData); }
public override DTO.SearchFormData GetDataWithFilter(int userId, System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification) { DTO.SearchFormData searchFormData = new DTO.SearchFormData(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; totalRows = 0; try { string productionItemUD = null; string productionItemNM = null; string productionItemNMEN = null; int? companyID = fw_factory.GetCompanyID(userId); if (filters.ContainsKey("productionItemUD") && !string.IsNullOrEmpty(filters["productionItemUD"].ToString())) { productionItemUD = filters["productionItemUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("productionItemNM") && !string.IsNullOrEmpty(filters["productionItemNM"].ToString())) { productionItemNM = filters["productionItemNM"].ToString().Replace("'", "''"); } if (filters.ContainsKey("productionItemNMEN") && !string.IsNullOrEmpty(filters["productionItemNMEN"].ToString())) { productionItemNMEN = filters["productionItemNMEN"].ToString().Replace("'", "''"); } using (BreakdownPriceListMngEntities context = CreateContext()) { totalRows = context.BreakdownPriceListMng_function_SearchBreakdownPriceList(orderBy, orderDirection, productionItemUD, productionItemNM, productionItemNMEN).Count(); var result = context.BreakdownPriceListMng_function_SearchBreakdownPriceList(orderBy, orderDirection, productionItemUD, productionItemNM, productionItemNMEN); searchFormData.Data = converter.DB2DTO_Search(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList()); searchFormData.CompanyID = companyID.Value; //get exchange rate of USD var dbExchangeRate = context.BreakdownPriceListMng_function_GetExchangeRate(DateTime.Now, "USD").FirstOrDefault(); if (dbExchangeRate != null) { searchFormData.ExchangeRate = dbExchangeRate.ExchangeRate; } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(searchFormData); }
// // CUSTOM FUNCTIONS // public DTO.ReportFormData GetReportData(int userId, int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.ReportFormData data = new DTO.ReportFormData(); data.Data = new DTO.WorkOrder(); data.OPSequenceDetails = new List <DTO.OPSequenceDetail>(); data.ProductionTeams = new List <DTO.ProductionTeam>(); data.FactoryWarehouses = new List <DTO.FactoryWarehouse>(); data.Details = new List <DTO.Detail>(); data.Receipts = new List <DTO.Receipt>(); data.ReceiptOverviews = new List <DTO.ReceiptOverview>(); data.ReceiptOverviewDetails = new List <DTO.ReceiptOverviewDetail>(); //try to get data try { using (WorkOrderRptEntities context = CreateContext()) { int companyId = fwFactory.GetCompanyID(userId).Value; data.Data = converter.DB2DTO_WorkOrder(context.WorkOrderRpt_WorkOrder_View.SingleOrDefault(o => o.WorkOrderID == id && o.CompanyID == companyId)); data.OPSequenceDetails = converter.DB2DTO_OPSequenceDetail(context.WorkOrderRpt_OPSequenceDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.ProductionTeams = converter.DB2DTO_ProductionTeam(context.WorkOrderRpt_ProductionTeamBySequenceDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.FactoryWarehouses = converter.DB2DTO_FactoryWarehouse(context.WorkOrderRpt_FactoryWarehouseBySequenceDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.Details = converter.DB2DTO_Detail(context.WorkOrderRpt_InOutDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.Receipts = converter.DB2DTO_Receipt(context.WorkOrderRpt_InOutReceipt_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.ReceiptOverviews = converter.DB2DTO_ReceiptOverview(context.WorkOrderRpt_ReceiptOverview_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).OrderBy(o => o.ReceiptDate).ToList()); data.ReceiptOverviewDetails = converter.DB2DTO_ReceiptOverviewDetail(context.WorkOrderRpt_ReceiptOverviewDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }
public override DTO.SaleDTO GetData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.SaleDTO dtoItem = new DTO.SaleDTO(); try { using (SaleEntities context = CreateContext()) { if (id > 0) { Sale dbItem; dbItem = context.Sale.FirstOrDefault(o => o.SaleID == id); dtoItem = converter.DB2DTO_Sale(dbItem); dtoItem.CompanyID = fwFactory.GetCompanyID(dbItem.UserID.Value); } else { dtoItem = new DTO.SaleDTO(); } return(dtoItem); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; notification.DetailMessage.Add(ex.Message); if (ex.GetBaseException() != null) { notification.DetailMessage.Add(ex.GetBaseException().Message); } return(null); } }
public override DTO.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification) { DTO.SearchFormData searchFormData = new DTO.SearchFormData(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; totalRows = 0; try { string workOrderUD = null; string productArticleCode = null; string productDescription = null; string clientUD = null; string proformaInvoiceNo = null; bool? hasBOM = null; int? workOrderStatusID = null; string startDate = null; string finishDate = null; int userId = Convert.ToInt32(filters["userId"]); int?companyID = fw_factory.GetCompanyID(userId); if (filters.ContainsKey("workOrderUD") && !string.IsNullOrEmpty(filters["workOrderUD"].ToString())) { workOrderUD = filters["workOrderUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("productArticleCode") && !string.IsNullOrEmpty(filters["productArticleCode"].ToString())) { productArticleCode = filters["productArticleCode"].ToString().Replace("'", "''"); } if (filters.ContainsKey("productDescription") && !string.IsNullOrEmpty(filters["productDescription"].ToString())) { productDescription = filters["productDescription"].ToString().Replace("'", "''"); } if (filters.ContainsKey("clientUD") && !string.IsNullOrEmpty(filters["clientUD"].ToString())) { clientUD = filters["clientUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("proformaInvoiceNo") && !string.IsNullOrEmpty(filters["proformaInvoiceNo"].ToString())) { proformaInvoiceNo = filters["proformaInvoiceNo"].ToString().Replace("'", "''"); } if (filters.ContainsKey("hasBOM") && filters["hasBOM"] != null && !string.IsNullOrEmpty(filters["hasBOM"].ToString())) { switch (filters["hasBOM"].ToString().ToLower()) { case "true": hasBOM = true; break; case "false": hasBOM = false; break; default: hasBOM = null; break; } } if (filters.ContainsKey("workOrderStatusID") && filters["workOrderStatusID"] != null) { workOrderStatusID = Convert.ToInt32(filters["workOrderStatusID"]); } if (filters.ContainsKey("startDate") && !string.IsNullOrEmpty(filters["startDate"].ToString())) { startDate = filters["startDate"].ToString().Replace("'", "''"); } if (filters.ContainsKey("finishDate") && !string.IsNullOrEmpty(filters["finishDate"].ToString())) { finishDate = filters["finishDate"].ToString().Replace("'", "''"); } using (PlanningProductionEntities context = CreateContext()) { totalRows = context.PlanningProductionMng_function_SearchPlanningProduction(orderBy, orderDirection, companyID, workOrderUD, productArticleCode, productDescription, clientUD, proformaInvoiceNo, hasBOM, workOrderStatusID, startDate, finishDate).Count(); var result = context.PlanningProductionMng_function_SearchPlanningProduction(orderBy, orderDirection, companyID, workOrderUD, productArticleCode, productDescription, clientUD, proformaInvoiceNo, hasBOM, workOrderStatusID, startDate, finishDate); searchFormData.Data = converter.DB2DTO_Search(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(searchFormData); }
public override DTO.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.SearchFormData data = new DTO.SearchFormData(); data.Data = new List <DTO.WorkOrderDTO>(); data.WeekInfoDTOs = new List <DTO.WeekInfoDTO>(); totalRows = 0; DateTime?StartDateFrom = null; DateTime?StartDateTo = null; DateTime?FinishedDateFrom = null; DateTime?FinishedDateTo = null; string WorkOrderUD = null; string ClientUD = null; string ProformaInvoiceNo = null; string WorkOrderStatus = null; int? WorkCenterID = null; int? UserID = null; int CompanyID = 0; if (filters.ContainsKey("StartDateFrom") && filters["StartDateFrom"] != null && !string.IsNullOrEmpty(filters["StartDateFrom"].ToString())) { StartDateFrom = filters["StartDateFrom"].ToString().Replace("'", "''").ConvertStringToDateTime(); } if (filters.ContainsKey("StartDateTo") && filters["StartDateTo"] != null && !string.IsNullOrEmpty(filters["StartDateTo"].ToString())) { StartDateTo = filters["StartDateTo"].ToString().Replace("'", "''").ConvertStringToDateTime(); } if (filters.ContainsKey("FinishedDateFrom") && filters["FinishedDateFrom"] != null && !string.IsNullOrEmpty(filters["FinishedDateFrom"].ToString())) { FinishedDateFrom = filters["FinishedDateFrom"].ToString().Replace("'", "''").ConvertStringToDateTime(); } if (filters.ContainsKey("FinishedDateTo") && filters["FinishedDateTo"] != null && !string.IsNullOrEmpty(filters["FinishedDateTo"].ToString())) { FinishedDateTo = filters["FinishedDateTo"].ToString().Replace("'", "''").ConvertStringToDateTime(); } if (filters.ContainsKey("WorkOrderUD") && filters["WorkOrderUD"] != null && !string.IsNullOrEmpty(filters["WorkOrderUD"].ToString())) { WorkOrderUD = filters["WorkOrderUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("ClientUD") && filters["ClientUD"] != null && !string.IsNullOrEmpty(filters["ClientUD"].ToString())) { ClientUD = filters["ClientUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("ProformaInvoiceNo") && filters["ProformaInvoiceNo"] != null && !string.IsNullOrEmpty(filters["ProformaInvoiceNo"].ToString())) { ProformaInvoiceNo = filters["ProformaInvoiceNo"].ToString().Replace("'", "''"); } if (filters.ContainsKey("WorkOrderStatus") && filters["WorkOrderStatus"] != null && !string.IsNullOrEmpty(filters["WorkOrderStatus"].ToString())) { WorkOrderStatus = filters["WorkOrderStatus"].ToString().Replace("'", "''"); } if (filters.ContainsKey("WorkCenterID") && filters["WorkCenterID"] != null && !string.IsNullOrEmpty(filters["WorkCenterID"].ToString())) { WorkCenterID = Convert.ToInt32(filters["WorkCenterID"]); } if (filters.ContainsKey("UserID") && filters["UserID"] != null && !string.IsNullOrEmpty(filters["UserID"].ToString())) { UserID = Convert.ToInt32(filters["UserID"]); } //try to get data try { try { CompanyID = fwFactory.GetCompanyID(UserID.Value).Value; } catch { CompanyID = 0; } using (MasterGrantChartRptEntities context = CreateContext()) { var dbWorkOrders = context.MasterGrantChartRpt_function_SearchWorkOrder(StartDateFrom, StartDateTo, FinishedDateFrom, FinishedDateTo, WorkOrderUD, ClientUD, ProformaInvoiceNo, WorkOrderStatus, WorkCenterID, CompanyID).OrderBy(o => o.StartDate).ToList(); DateTime?FromDate = dbWorkOrders.Min(o => o.WeekStart); DateTime?ToDate = dbWorkOrders.Max(o => o.WeekEnd); data.Data = converter.DB2DTO_WorkOrderList(dbWorkOrders); data.WeekInfoDTOs = converter.DB2DTO_WeekInfoList(context.WeekInfo.Where(o => o.WeekEnd >= FromDate && o.WeekEnd <= ToDate).OrderBy(o => o.WeekStart).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }
public string GetPrintDataOffer5(int OfferID, bool IsSendEmail, bool IsGetFullSizeImage, int imageOption, int userID, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; PrintDataObject ds = new PrintDataObject(); try { SqlDataAdapter adap = new SqlDataAdapter(); adap.SelectCommand = new SqlCommand("OfferMng_function_GetPrintData", new SqlConnection(DALBase.Helper.GetSQLConnectionString())); adap.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure; adap.SelectCommand.Parameters.AddWithValue("@OfferID", OfferID); adap.SelectCommand.Parameters.AddWithValue("@IsSendEmail", IsSendEmail); adap.SelectCommand.Parameters.AddWithValue("@ImageOption", imageOption); adap.TableMappings.Add("Table", "ParamTable"); adap.TableMappings.Add("Table1", "PrintHeader"); adap.TableMappings.Add("Table2", "PrintDetail"); adap.TableMappings.Add("Table3", "ModelPieceReport"); adap.Fill(ds); //logo image ds.PrintHeader.FirstOrDefault().LogoImage = FrameworkSetting.Setting.MediaThumbnailUrl + ds.PrintHeader.FirstOrDefault().LogoImage; //set image url foreach (var item in ds.PrintDetail) { if (IsGetFullSizeImage) { item.FileLocation = FrameworkSetting.Setting.MediaFullSizeUrl + item.FileLocation_FullSize; item.FileGardenLocation = FrameworkSetting.Setting.MediaFullSizeUrl + item.FileGardenLocation_FullSize; } else { item.FileLocation = FrameworkSetting.Setting.MediaThumbnailUrl + item.FileLocation; item.FileGardenLocation = FrameworkSetting.Setting.MediaThumbnailUrl + item.FileGardenLocation; } } //DALBase.Helper.DevCreateReportXMLSource(ds, "Offer5"); // generate xml file string reportFile = ""; Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); int?companyID = fwFactory.GetCompanyID(userID); switch (companyID) { case 13: reportFile = "Offer5_OrangePine"; break; default: reportFile = "Offer5"; break; } // remove table from dataset ds.Tables.Remove("OfferMng_OfferPrintoutPP_View"); ds.Tables.Remove("OfferMng_OfferPrintoutPP_Detail_View"); ds.Tables.Remove("OfferMng_OfferPrintoutPP_PieceDetail_View"); ds.AcceptChanges(); return(Library.Helper.CreateReportFileWithEPPlus2(ds, reportFile)); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; Exception iEx = Library.Helper.GetInnerException(ex); notification.Message = iEx.Message; return(string.Empty); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { notification = new Notification { Type = NotificationType.Success }; DTO.PurchaseQuotationDTO dtoPurchaseQuotation = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.PurchaseQuotationDTO>(); try { // 1. Check validation validFrom and validTo var validFrom = dtoPurchaseQuotation.ValidFrom.ConvertStringToDateTime(); var validTo = dtoPurchaseQuotation.ValidTo.ConvertStringToDateTime(); // 1.1. Case validFrom not value if (!validFrom.HasValue) { notification.Type = NotificationType.Error; notification.Message = "Valid From is invalid!"; return(false); } // 1.2. Compare if (validTo.HasValue) { if (validTo.Value.CompareTo(validFrom.Value) < 0) { notification.Type = NotificationType.Error; notification.Message = "Valid From is less than Valid To!"; return(false); } } using (var context = CreatContext()) { PurchaseQuotation dbItem; if (id == 0) { dbItem = new PurchaseQuotation(); context.PurchaseQuotation.Add(dbItem); } else { dbItem = context.PurchaseQuotation.Where(o => o.PurchaseQuotationID == id).FirstOrDefault(); } if (dbItem == null) { notification.Type = NotificationType.Error; notification.Message = "Data Not Found !"; return(false); } else { //converter converter.DTO2DB_PurchaseQuatation(dtoPurchaseQuotation, ref dbItem); //upload file Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoPurchaseQuotation.File_HasChange.HasValue && dtoPurchaseQuotation.File_HasChange.Value) { dbItem.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoPurchaseQuotation.File_NewFile, dtoPurchaseQuotation.AttachedFile, dtoPurchaseQuotation.FriendlyName); } //Remove context.PurchaseQuotationDetail.Local.Where(o => o.PurchaseQuotation == null).ToList().ForEach(o => context.PurchaseQuotationDetail.Remove(o)); int?companyID = fwFactory.GetCompanyID(userId); dbItem.CompanyID = companyID; dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; if (id == 0) { dbItem.PurchaseQuotationUD = context.PurchaseQuotationMng_function_GeneratePurchaseQuotationUD().FirstOrDefault(); dbItem.CreatedBy = userId; dbItem.CreatedDate = DateTime.Now; } /// cuong.tran: ProductionFrameWeight - start foreach (var item in dtoPurchaseQuotation.PurchaseQuotationDetailDTOs) { /// Only material is component if (item.ProductionItemTypeID == 1 && item.FrameWeight.HasValue) { var dtoFrameWeight = context.ProductionFrameWeight.FirstOrDefault(o => o.ProductionItemID == item.ProductionItemID); if (dtoFrameWeight == null) { // Insert table ProductionFrameWeight ProductionFrameWeight dbFrameWeight = new ProductionFrameWeight(); context.ProductionFrameWeight.Add(dbFrameWeight); dbFrameWeight.ProductionItemID = item.ProductionItemID; dbFrameWeight.FrameWeight = item.FrameWeight; dbFrameWeight.UpdatedBy = userId; dbFrameWeight.UpdatedDate = DateTime.Now; context.SaveChanges(); // Insert table ProductionFrameWeightHistory ProductionFrameWeightHistory dbFrameWeightHistory = new ProductionFrameWeightHistory(); context.ProductionFrameWeightHistory.Add(dbFrameWeightHistory); dbFrameWeightHistory.ProductionFrameWeightID = dbFrameWeight.ProductionFrameWeightID; dbFrameWeightHistory.FrameWeight = item.FrameWeight; dbFrameWeightHistory.UpdatedBy = userId; dbFrameWeightHistory.UpdatedDate = DateTime.Now; context.SaveChanges(); } } } /// cuong.tran: ProductionFrameWeight - e n d //Save context.SaveChanges(); dtoItem = GetData(dbItem.PurchaseQuotationID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; return(false); } }
public void DTO2DB_PurchasingInvoice(int iRequesterID, PurchasingInvoiceMng_Booking_View dbBooking, DTO.PurchasingInvoiceMng.PurchasingInvoice dtoItem, ref PurchasingInvoice dbItem) { Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); //int userOfficeID = fwFactory.GetUserOffice(iRequesterID); int[] internalCompanyID = new int[] { 1, 2, 3 }; int userOfficeID = 1; if (!internalCompanyID.ToList().Contains(fwFactory.GetCompanyID(iRequesterID).Value)) // 1, 2, 3 = AVF, AVS, AVT { userOfficeID = 4; // fake the office id equal to 4, backward compatible } //Purchasing Invoice Detail if (dtoItem.PurchasingInvoiceDetails != null) { //CHECK foreach (var item in dbItem.PurchasingInvoiceDetail.ToArray()) { if (!dtoItem.PurchasingInvoiceDetails.Select(s => s.PurchasingInvoiceDetailID).Contains(item.PurchasingInvoiceDetailID)) { dbItem.PurchasingInvoiceDetail.Remove(item); } } //MAP foreach (var dtoDetail in dtoItem.PurchasingInvoiceDetails) { PurchasingInvoiceDetail dbDetail; if (dtoDetail.PurchasingInvoiceDetailID < 0) { dbDetail = new PurchasingInvoiceDetail(); dbDetail.UnitPrice = dbBooking.PurchasingInvoiceMng_LoadingPlanDetail_View.Where(o => o.LoadingPlanDetailID == dtoDetail.LoadingPlanDetailID).FirstOrDefault().UnitPrice; dbItem.PurchasingInvoiceDetail.Add(dbDetail); } else { dbDetail = dbItem.PurchasingInvoiceDetail.FirstOrDefault(o => o.PurchasingInvoiceDetailID == dtoDetail.PurchasingInvoiceDetailID); if (userOfficeID != 4) { dbDetail.UnitPrice = dtoDetail.UnitPrice; } } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.PurchasingInvoiceMng.PurchasingInvoiceDetail, PurchasingInvoiceDetail>(dtoDetail, dbDetail); } } } //Purchasing Invoice Sparepart Detail if (dtoItem.PurchasingInvoiceSparepartDetails != null) { //CHECK foreach (var item in dbItem.PurchasingInvoiceSparepartDetail.ToArray()) { if (!dtoItem.PurchasingInvoiceSparepartDetails.Select(s => s.PurchasingInvoiceSparepartDetailID).Contains(item.PurchasingInvoiceSparepartDetailID)) { dbItem.PurchasingInvoiceSparepartDetail.Remove(item); } } //MAP foreach (var dtoDetail in dtoItem.PurchasingInvoiceSparepartDetails) { PurchasingInvoiceSparepartDetail dbDetail; if (dtoDetail.PurchasingInvoiceSparepartDetailID < 0) { dbDetail = new PurchasingInvoiceSparepartDetail(); dbDetail.UnitPrice = dbBooking.PurchasingInvoiceMng_LoadingPlanSparepartDetail_View.Where(o => o.LoadingPlanSparepartDetailID == dtoDetail.LoadingPlanSparepartDetailID).FirstOrDefault().UnitPrice; dbItem.PurchasingInvoiceSparepartDetail.Add(dbDetail); } else { dbDetail = dbItem.PurchasingInvoiceSparepartDetail.FirstOrDefault(o => o.PurchasingInvoiceSparepartDetailID == dtoDetail.PurchasingInvoiceSparepartDetailID); if (userOfficeID != 4) { dbDetail.UnitPrice = dtoDetail.UnitPrice; } } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.PurchasingInvoiceMng.PurchasingInvoiceSparepartDetail, PurchasingInvoiceSparepartDetail>(dtoDetail, dbDetail); } } } //Purchasing Invoice Sparepart Detail if (dtoItem.PurchasingInvoiceExtraDetails != null) { //CHECK foreach (var item in dbItem.PurchasingInvoiceExtraDetail.ToArray()) { if (!dtoItem.PurchasingInvoiceExtraDetails.Select(s => s.PurchasingInvoiceExtraDetailID).Contains(item.PurchasingInvoiceExtraDetailID)) { dbItem.PurchasingInvoiceExtraDetail.Remove(item); } } //MAP foreach (var dtoDetail in dtoItem.PurchasingInvoiceExtraDetails) { PurchasingInvoiceExtraDetail dbDetail; if (dtoDetail.PurchasingInvoiceExtraDetailID < 0) { dbDetail = new PurchasingInvoiceExtraDetail(); dbItem.PurchasingInvoiceExtraDetail.Add(dbDetail); } else { dbDetail = dbItem.PurchasingInvoiceExtraDetail.FirstOrDefault(o => o.PurchasingInvoiceExtraDetailID == dtoDetail.PurchasingInvoiceExtraDetailID); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.PurchasingInvoiceMng.PurchasingInvoiceExtraDetail, PurchasingInvoiceExtraDetail>(dtoDetail, dbDetail); } } } //Purchasing Invoice Sample Detail if (dtoItem.PurchasingInvoiceSampleDetails != null) { //CHECK foreach (var item in dbItem.PurchasingInvoiceSampleDetail.ToArray()) { if (!dtoItem.PurchasingInvoiceSampleDetails.Select(s => s.PurchasingInvoiceSampleDetailID).Contains(item.PurchasingInvoiceSampleDetailID)) { dbItem.PurchasingInvoiceSampleDetail.Remove(item); } } //MAP foreach (var dtoDetail in dtoItem.PurchasingInvoiceSampleDetails) { PurchasingInvoiceSampleDetail dbDetail; if (dtoDetail.PurchasingInvoiceSampleDetailID < 0) { dbDetail = new PurchasingInvoiceSampleDetail(); dbDetail.UnitPrice = dbBooking.PurchasingInvoiceMng_LoadingPlanSampleDetail_View.Where(o => o.LoadingPlanSampleDetailID == dtoDetail.LoadingPlanSampleDetailID).FirstOrDefault().UnitPrice; dbItem.PurchasingInvoiceSampleDetail.Add(dbDetail); } else { dbDetail = dbItem.PurchasingInvoiceSampleDetail.FirstOrDefault(o => o.PurchasingInvoiceSampleDetailID == dtoDetail.PurchasingInvoiceSampleDetailID); if (userOfficeID != 4) { dbDetail.UnitPrice = dtoDetail.UnitPrice; } } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.PurchasingInvoiceMng.PurchasingInvoiceSampleDetail, PurchasingInvoiceSampleDetail>(dtoDetail, dbDetail); } } } //Purchasing Invoice AutoMapper.Mapper.Map <DTO.PurchasingInvoiceMng.PurchasingInvoice, PurchasingInvoice>(dtoItem, dbItem); if (dtoItem.PurchasingInvoiceID > 0) { dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = dtoItem.UpdatedBy; } else { dbItem.CreatedDate = DateTime.Now; dbItem.CreatedBy = dtoItem.UpdatedBy; } dbItem.InvoiceDate = dtoItem.InvoiceDate.ConvertStringToDateTime(); if (dbItem.SupplierID == 336037) { dbItem.FactoryRawMaterialID = 250; } }
public override DTO.SearchFormData GetDataWithFilter(Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.SearchFormData data = new DTO.SearchFormData(); data.Data = new List <DTO.WorkOrderDTO>(); data.WeekInfoDTOs = new List <DTO.WeekInfoDTO>(); data.ReceivingDetailDTOs = new List <DTO.ReceivingDetailDTO>(); data.ReceivingSetDetailDTOs = new List <DTO.ReceivingSetDetailDTO>(); data.WorkcenterStatus = new List <DTO.WorkcenterStatus>(); data.MaterialStatus = new List <DTO.MaterialStatus>(); totalRows = 0; string StartDateFrom = null; string StartDateTo = null; string FinishedDateFrom = null; string FinishedDateTo = null; string WorkOrderUD = null; string ClientUD = null; string ProformaInvoiceNo = null; string WorkOrderStatus = null; int? WorkCenterID = null; int? UserID = null; int CompanyID = 0; if (filters.ContainsKey("StartDateFrom") && filters["StartDateFrom"] != null && !string.IsNullOrEmpty(filters["StartDateFrom"].ToString())) { StartDateFrom = filters["StartDateFrom"].ToString().Replace("'", "''"); } if (filters.ContainsKey("StartDateTo") && filters["StartDateTo"] != null && !string.IsNullOrEmpty(filters["StartDateTo"].ToString())) { StartDateTo = filters["StartDateTo"].ToString().Replace("'", "''"); } if (filters.ContainsKey("FinishedDateFrom") && filters["FinishedDateFrom"] != null && !string.IsNullOrEmpty(filters["FinishedDateFrom"].ToString())) { FinishedDateFrom = filters["FinishedDateFrom"].ToString().Replace("'", "''"); } if (filters.ContainsKey("FinishedDateTo") && filters["FinishedDateTo"] != null && !string.IsNullOrEmpty(filters["FinishedDateTo"].ToString())) { FinishedDateTo = filters["FinishedDateTo"].ToString().Replace("'", "''"); } if (filters.ContainsKey("WorkOrderUD") && filters["WorkOrderUD"] != null && !string.IsNullOrEmpty(filters["WorkOrderUD"].ToString())) { WorkOrderUD = filters["WorkOrderUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("ClientUD") && filters["ClientUD"] != null && !string.IsNullOrEmpty(filters["ClientUD"].ToString())) { ClientUD = filters["ClientUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("ProformaInvoiceNo") && filters["ProformaInvoiceNo"] != null && !string.IsNullOrEmpty(filters["ProformaInvoiceNo"].ToString())) { ProformaInvoiceNo = filters["ProformaInvoiceNo"].ToString().Replace("'", "''"); } if (filters.ContainsKey("WorkOrderStatus") && filters["WorkOrderStatus"] != null && !string.IsNullOrEmpty(filters["WorkOrderStatus"].ToString())) { WorkOrderStatus = filters["WorkOrderStatus"].ToString().Replace("'", "''"); } if (filters.ContainsKey("WorkCenterID") && filters["WorkCenterID"] != null && !string.IsNullOrEmpty(filters["WorkCenterID"].ToString())) { WorkCenterID = Convert.ToInt32(filters["WorkCenterID"]); } else { notification.Type = Library.DTO.NotificationType.Error; notification.Message = "Work Center invalid"; return(data); } if (filters.ContainsKey("UserID") && filters["UserID"] != null && !string.IsNullOrEmpty(filters["UserID"].ToString())) { UserID = Convert.ToInt32(filters["UserID"]); } //try to get data try { try { CompanyID = fwFactory.GetCompanyID(UserID.Value).Value; } catch { CompanyID = 0; } using (PlanningReportWorkCenterEntities context = CreateContext()) { var dbWorkOrders = context.PlanningReportWorkCenter_function_SearchWorkOrder(StartDateFrom, StartDateTo, FinishedDateFrom, FinishedDateTo, WorkOrderUD, ClientUD, ProformaInvoiceNo, WorkOrderStatus, WorkCenterID, CompanyID).OrderBy(o => o.StartDate).ToList(); data.Data = converter.DB2DTO_WorkOrderList(dbWorkOrders); //get real List <int?> workOrderIDs = data.Data.Select(s => s.WorkOrderID).ToList(); List <int?> workCenterIDs = data.Data.Select(s => s.WorkCenterID).ToList(); var realData = context.PlanningReportWorkCenter_ReceivingDetail_View.Where(o => workOrderIDs.Contains(o.WorkOrderID.Value) && workCenterIDs.Contains(o.WorkCenterID.Value)).ToList(); var detailData = context.PlanningReportWorkCenter_SetDetail_View.Where(o => workOrderIDs.Contains(o.WorkOrderID.Value) && workCenterIDs.Contains(o.WorkCenterID.Value)).ToList(); data.ReceivingDetailDTOs = converter.DB2DTO_ReceivingDetail(realData); //data.ReceivingSetDetailDTOs = converter.DB2DTO_ReceivingSetDetail(context.PlanningReportWorkCenter_SetDetail_View.Where(o => workOrderIDs.Contains(o.WorkOrderID.Value) && workCenterIDs.Contains(o.WorkCenterID.Value)).ToList()); data.ReceivingSetDetailDTOs = converter.DB2DTO_ReceivingSetDetail(detailData); data.WorkcenterStatus = converter.DB2DTO_GetWorkCenterStatus(context.PlanningReportWorkCenter_GetWorkCenterStatus_View.Where(o => o.WorkCenterID != null && o.WorkCenterID == WorkCenterID).ToList()); data.MaterialStatus = converter.DB2DTO_GetMaterialStatus(context.PlanningReportWorkCenter_GetMaterialStatus_View.ToList()); int?FromDate = dbWorkOrders.Min(o => o.WeekInfoID); //int? ToDate = dbWorkOrders.Max(o => o.WeekInfoID); int?ToDate; if (realData.Max(o => o.WeekInfoID) > dbWorkOrders.Max(o => o.WeekInfoID)) { ToDate = realData.Max(o => o.WeekInfoID); } else { ToDate = dbWorkOrders.Max(o => o.WeekInfoID); } data.WeekInfoDTOs = converter.DB2DTO_WeekInfoList(context.WeekInfo.Where(o => o.WeekInfoID >= FromDate && o.WeekInfoID <= ToDate).OrderBy(o => o.WeekStart).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }