Example #1
0
        public string UpdateRegionFullIndex()
        {
            string result = "";
            string guid   = Guid.NewGuid().ToString();

            try
            {
                DataSet ds = new DataSet();
                DataControl.BLRegion    _objBlRegion = new DataControl.BLRegion();
                DataControl.CurrentInfo _objCurInfo  = new DataControl.CurrentInfo();
                ds = _objBlRegion.GetAllRegionsForMigration(_objCurInfo.GetCompanyCode());
                DataSet   dsAllRegions = new DataSet();
                DataRow[] dr;
                DataRow[] drChild;
                dr = ds.Tables[0].AsEnumerable().Where(c => c["Under_Region_Id"].ToString() == "0").ToArray();
                if (dr.Length > 0)
                {
                    string regionCode = dr[0]["Region_Code"].ToString();
                    string regionId   = dr[0]["Region_Id"].ToString();
                    dsAllRegions = _objBlRegion.GetRegionHierarchyDataset(_objCurInfo.GetCompanyCode(), regionCode, _objCurInfo.GetUserCode(), guid);
                    if (dsAllRegions.Tables[0].Rows.Count > 0)
                    {
                        DataRow[] drRoot;
                        drRoot = dsAllRegions.Tables[0].AsEnumerable().Where(c => c["Under_Region_Id"].ToString() == "0").ToArray();
                        drRoot[0]["Full_index"]   = regionId + ".";
                        drRoot[0]["Company_Code"] = _objCurInfo.GetCompanyCode();
                        dsAllRegions.AcceptChanges();

                        for (int i = 0; i < dsAllRegions.Tables[0].Rows.Count; i++)
                        {
                            string curRegionCode    = dsAllRegions.Tables[0].Rows[i]["Region_Code"].ToString();
                            string curParRegionCode = dsAllRegions.Tables[0].Rows[i]["Under_Region_Code"].ToString();
                            if (curRegionCode != curParRegionCode)
                            {
                                string    curRegionId = dsAllRegions.Tables[0].Rows[i]["Region_Id"].ToString();
                                string    parIndex    = "";
                                DataRow[] drTemp;
                                drTemp = dsAllRegions.Tables[0].AsEnumerable().Where(c => c["Region_Code"].ToString() == curParRegionCode).ToArray();
                                if (drTemp.Length > 0)
                                {
                                    parIndex = drTemp[0]["Full_index"].ToString();
                                    dsAllRegions.Tables[0].Rows[i]["Full_index"]   = parIndex + curRegionId + ".";
                                    dsAllRegions.Tables[0].Rows[i]["Company_Code"] = _objCurInfo.GetCompanyCode();
                                }
                            }
                        }
                        //Update Qry
                        int rowsAffected = 0;
                        result = _objBlRegion.BulkRegionTempInsert(_objCurInfo.GetCompanyCode(), dsAllRegions.Tables[0], "REFRESH");
                        if (result.Split(':')[0].ToUpper() == "SUCCESS")
                        {
                            rowsAffected = _objBlRegion.UpdateRegionIndexFromTemptoRegionMaster(_objCurInfo.GetCompanyCode(), "REFRESH",
                                                                                                guid, _objCurInfo.GetUserCode());
                            if (rowsAffected > 0)
                            {
                                result = "SUCCESS:Region tree refreshed successfully";
                            }
                            else
                            {
                                result = "ERROR:Error occurred while refresh the region";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result = "FAILURE:" + ex.Message;
            }
            return(result);
        }
Example #2
0
        public string UpdateRegionNewIndex()
        {
            string result = "";
            string guid   = Guid.NewGuid().ToString();

            try
            {
                DataSet ds = new DataSet();
                DataControl.BLRegion    _objBlRegion = new DataControl.BLRegion();
                DataControl.CurrentInfo _objCurInfo  = new DataControl.CurrentInfo();
                ds = _objBlRegion.GetAllRegionsForMigration(_objCurInfo.GetCompanyCode());
                DataSet   dsAllRegions = new DataSet();
                DataRow[] dr;
                dr = ds.Tables[0].AsEnumerable().Where(c => c["Under_Region_Id"].ToString() == "0").ToArray();
                if (dr.Length > 0)
                {
                    string userCode = dr[0]["Region_Code"].ToString();
                    string userId   = dr[0]["Region_Id"].ToString();
                    dsAllRegions = _objBlRegion.GetRegionHierarchyDataset(_objCurInfo.GetCompanyCode(), userCode, _objCurInfo.GetUserCode(), guid);
                    if (dsAllRegions.Tables[0].Rows.Count > 0)
                    {
                        //Display Order Update
                        for (int d = 0; d < dsAllRegions.Tables[0].Rows.Count; d++)
                        {
                            dsAllRegions.Tables[0].Rows[d]["Display_Order"] = d + 1;
                            dsAllRegions.AcceptChanges();
                        }
                        //Root user seq and full index update
                        DataRow[] drRoot;
                        drRoot = dsAllRegions.Tables[0].AsEnumerable().Where(c => c["Under_Region_Id"].ToString() == "0").ToArray();
                        drRoot[0]["Full_index"]   = userId + ".";
                        drRoot[0]["Seq_index"]    = "1";
                        drRoot[0]["Company_Code"] = _objCurInfo.GetCompanyCode();
                        // Root child nodes seq and full index updation
                        DataRow[] drChild;
                        drChild = dsAllRegions.Tables[0].AsEnumerable().Where(d => d["Under_Region_Code"].ToString() == userCode).ToArray();
                        if (drChild.Length > 0)
                        {
                            int c = 0;
                            foreach (DataRow drr in drChild)
                            {
                                c++;
                                drr["Seq_index"]    = c.ToString();
                                drr["Company_Code"] = _objCurInfo.GetCompanyCode();
                                dsAllRegions.AcceptChanges();
                            }
                        }
                        dsAllRegions.AcceptChanges();
                        int displayOrder = 0;
                        for (int i = 0; i < dsAllRegions.Tables[0].Rows.Count; i++)
                        {
                            displayOrder++;
                            string curRegionCode    = dsAllRegions.Tables[0].Rows[i]["Region_Code"].ToString();
                            string curParRegionCode = dsAllRegions.Tables[0].Rows[i]["Under_Region_Code"].ToString();
                            if (curRegionCode != curParRegionCode)
                            {
                                string    curRegionId = dsAllRegions.Tables[0].Rows[i]["Region_Id"].ToString();
                                string    parIndex    = "";
                                DataRow[] drTemp;
                                drTemp = dsAllRegions.Tables[0].AsEnumerable().Where(c => c["Region_Code"].ToString() == curParRegionCode).ToArray();
                                if (drTemp.Length > 0)
                                {
                                    parIndex = drTemp[0]["Full_index"].ToString();
                                    dsAllRegions.Tables[0].Rows[i]["Full_index"]      = parIndex + curRegionId + ".";
                                    dsAllRegions.Tables[0].Rows[i]["Company_Code"]    = _objCurInfo.GetCompanyCode();
                                    dsAllRegions.Tables[0].Rows[i]["Under_Region_Id"] = drTemp[0]["Region_Id"].ToString();
                                }

                                drChild = dsAllRegions.Tables[0].AsEnumerable().Where(d => d["Under_Region_Code"].ToString() == curRegionCode).ToArray();
                                if (drChild.Length > 0)
                                {
                                    int c = 0;
                                    foreach (DataRow drr in drChild)
                                    {
                                        c++;
                                        drr["Seq_index"]    = c.ToString();
                                        drr["Company_Code"] = _objCurInfo.GetCompanyCode();
                                        dsAllRegions.AcceptChanges();
                                    }
                                }
                            }
                        }
                        //Update Qry
                        int rowsAffected = 0;
                        result = _objBlRegion.BulkRegionTempInsert(_objCurInfo.GetCompanyCode(), dsAllRegions.Tables[0], "MIGRATION");
                        if (result.Split(':')[0].ToUpper() == "SUCCESS")
                        {
                            rowsAffected = _objBlRegion.UpdateRegionIndexFromTemptoRegionMaster(_objCurInfo.GetCompanyCode(), "MIGRATION",
                                                                                                guid, _objCurInfo.GetUserCode());
                            if (rowsAffected > 0)
                            {
                                result = "SUCCESS:Region Migration Done";
                            }
                            else
                            {
                                result = "ERROR:Error occurred while migration";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result = "FAILURE:" + ex.Message;
            }
            return(result);
        }