Ejemplo n.º 1
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>
        /// 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);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update2 - ProjectNumber and ProjectHistory
        /// </summary>
        public void Update2()
        {
            ProjectNumberGateway projectNumberGateway = new ProjectNumberGateway(Data);
            ProjectHistoryGateway projectHistoryGateway = new ProjectHistoryGateway(Data);

            DataTable projectChanges = Table.GetChanges();
            DataTable projectNumberChanges = projectNumberGateway.Table.GetChanges();
            DataTable projectHistoryChanges = projectHistoryGateway.Table.GetChanges();

            if ((projectChanges == null) && (projectNumberChanges == null) && (projectHistoryChanges == null)) return;

            try
            {
                DB.Open();
                DB.BeginTransaction();

                Adapter.InsertCommand.Transaction = DB.Transaction;
                Adapter.UpdateCommand.Transaction = DB.Transaction;
                Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectNumberGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectNumberGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectNumberGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectHistoryGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectHistoryGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectHistoryGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                if ((projectChanges != null) && (projectChanges.Rows.Count > 0))
                {
                    Adapter.Update(projectChanges);
                    int newProjectId = DB.GetIdentCurrent("LFS_PROJECT", DB.Transaction);

                    //Getting projectId for History table
                    ProjectTDS.LFS_PROJECT_HISTORYRow row = ((ProjectTDS.LFS_PROJECT_HISTORYDataTable)projectHistoryGateway.Table).FindByProjectIDRefID(0, 1);
                    row.ProjectID = newProjectId;
                    projectHistoryChanges = projectHistoryGateway.Table.GetChanges();
                }

                if ((projectNumberChanges != null) && (projectNumberChanges.Rows.Count > 0))
                {
                    projectNumberGateway.Adapter.Update(projectNumberChanges);
                }

                if ((projectHistoryChanges != null) && (projectHistoryChanges.Rows.Count > 0))
                {
                    projectHistoryGateway.Adapter.Update(projectHistoryChanges);
                }

                DB.CommitTransaction();
            }

            catch (DBConcurrencyException dBConcurrencyException)
            {
                DB.RollbackTransaction();
                throw new Exception("Concurrency error: Another user already updated the data you are working on.  Your operation has been cancelled.", dBConcurrencyException);
            }

            catch (SqlException sqlException)
            {
                DB.RollbackTransaction();
                byte severityLevel = sqlException.Class;
                if (severityLevel <= 16)
                {
                    throw new Exception("Low severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if ((severityLevel >= 17) && (severityLevel <= 19))
                {
                    throw new Exception("Mid severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if (severityLevel >= 20)
                {
                    throw new Exception("High severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
            }

            catch (Exception e)
            {
                DB.RollbackTransaction();
                throw new Exception("Unknow error. Your operation has been cancelled.", e);
            }

            finally
            {
                DB.Close();
            }
        }
        /// <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;
        }