/// <summary>
        /// Save
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="loginId">loginId</param>
        public void Save(int companyId, int loginId)
        {
            foreach (DataMigrationTDS.DataMigrationProjectRow row in (DataMigrationTDS.DataMigrationProjectDataTable)Table)
            {
                // get parameters
                DateTime date = DateTime.Now;
                Int64 countryId = row.CountryID;
                Int64? provinceId = null; if (!row.IsProvinceIDNull()) provinceId = row.ProvinceID;
                Int64? countyId = null; if (!row.IsCountyIDNull()) countyId = row.CountyID;
                Int64? cityId = null; if (!row.IsCityIDNull()) cityId = row.CityID;
                int officeId = row.OfficeID;
                int? projectLeadId = null; if (!row.IsProjectLeadIDNull()) projectLeadId = row.ProjectLeadID;
                int salesmanId = row.SalesmanID;
                string projectState = "Active";
                string projectType = "Project";
                string name = row.Name;
                int clientId = row.COMPANIES_ID;

                string projectNumber = GetProjectNumber(row, companyId);

                DataMigrationProjectGateway dataMigrationProjectGateway = new DataMigrationProjectGateway(null);
                if (dataMigrationProjectGateway.GetProjectIdByName(row.Name) == 0)
                {
                    int projectId = dataMigrationProjectGateway.InsertProject(countryId, officeId, projectLeadId, salesmanId, projectNumber, projectType, projectState, name, "", null, null, null, clientId, null, null, "", false, null, null, null, provinceId, cityId, companyId, countyId);

                    dataMigrationProjectGateway.InsertHistory(projectId, 1, projectState, DateTime.Now, loginId, companyId);

                    ProjectNumberGateway projectNumberGateway = new ProjectNumberGateway();
                    projectNumberGateway.Load();
                    ProjectNumber projectNumberForLoad = new ProjectNumber(projectNumberGateway.Data);
                    string pnProjectIncrement = projectNumberForLoad.GetProjectIncrement(date.Year, companyId);
                    int projectIncrement = int.Parse(pnProjectIncrement);
                    dataMigrationProjectGateway.UpdateProjectNumber(date.Year, projectIncrement, companyId);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Generate Project Number for new Project
        /// </summary>
        /// <param name="countryId">CountryId</param>
        /// <param name="officeId">OfficeId</param>
        /// <param name="salesmanId">SalesmanId - EmployeeId</param>
        /// <param name="date">Date to generate</param>
        /// <param name="companyId">companyId</param>
        /// <returns>Project Number generated</returns>
        public string GenerateProjectNumber(Int64 countryId, int officeId, int salesmanId, DateTime date, int companyId)
        {
            CountryGateway countryGateway = new CountryGateway(new DataSet());
            countryGateway.LoadByCountryId(countryId);
            string pnCountryId = countryGateway.GetIdForProjects(countryId);

            OfficeGateway officeGateway = new OfficeGateway(new DataSet());
            officeGateway.LoadByOfficeId(officeId);
            string pnOfficeId = officeGateway.GetIdForProjects(officeId);

            SalesmanGateway salesmanGateway = new SalesmanGateway(new DataSet());
            salesmanGateway.LoadBySalesmanId(salesmanId);
            string pnSalesmanId = salesmanGateway.GetIdForProjects(salesmanId);

            ProjectNumberGateway projectNumberGateway = new ProjectNumberGateway(Data);
            projectNumberGateway.Load();
            ProjectNumber projectNumber = new ProjectNumber(Data);
            string pnYearCode = projectNumber.GetYearCode(date.Year);
            string pnProjectIncrement = projectNumber.GetProjectIncrement(date.Year, companyId);

            string newProjectNumber = pnCountryId + pnOfficeId + pnSalesmanId + pnYearCode + pnProjectIncrement;

            return newProjectNumber;
        }
        /// <summary>
        /// GetProjectNumber
        /// </summary>
        /// <param name="row">row</param>
        /// <param name="companyId">companyId</param>
        /// <returns></returns>
        private string GetProjectNumber(DataMigrationTDS.DataMigrationProjectRow row, int companyId)
        {
            DateTime date = DateTime.Now;

            CountryGateway countryGateway = new CountryGateway(new DataSet());
            countryGateway.LoadByCountryId(row.CountryID);
            string pnCountryId = countryGateway.GetIdForProjects(row.CountryID);

            OfficeGateway officeGateway = new OfficeGateway(new DataSet());
            officeGateway.LoadByOfficeId(row.OfficeID);
            string pnOfficeId = officeGateway.GetIdForProjects(row.OfficeID);

            SalesmanGateway salesmanGateway = new SalesmanGateway(new DataSet());
            salesmanGateway.LoadBySalesmanId(row.SalesmanID);
            string pnSalesmanId = salesmanGateway.GetIdForProjects(row.SalesmanID);

            ProjectNumberGateway projectNumberGateway = new ProjectNumberGateway();
            projectNumberGateway.Load();
            ProjectNumber projectNumber = new ProjectNumber(projectNumberGateway.Data);
            string pnYearCode = projectNumber.GetYearCode(date.Year);
            string pnProjectIncrement = projectNumber.GetProjectIncrement(date.Year, companyId);

            string newProjectNumber = pnCountryId + pnOfficeId + pnSalesmanId + pnYearCode + pnProjectIncrement;

            return newProjectNumber;
        }