public string GetCustomerData1(List <MVCModels.StockiestHeaderDetails> stock, List <MVCModels.StockiestHeaderDetails> stock1, string[] targetRegionCodes, string customerCode) { List <MVCModels.StockiestHeaderDetails> lstStok = new List <StockiestHeaderDetails>(); SPData objData = new SPData(); DataControl.CurrentInfo objCurInfo = new CurrentInfo(); string strReturn = "aa"; try { using (IDbConnection connection = IDbOpenConnection()) { List <MVCModels.StockiestHeaderDetails> lstStock1 = new List <StockiestHeaderDetails>(); List <MVCModels.StockiestHeaderDetails> lstStock = new List <StockiestHeaderDetails>(); int a = 1; for (int r = 0; r < targetRegionCodes.Count() - 1; r++) { for (int j = 0; j < stock.Count; j++) { StockiestHeaderDetails _objstock = new StockiestHeaderDetails(); long SeqNum = objData.GetSeqNumber("SEQ_tbl_SFA_Customer_Master"); _objstock.ID = a; _objstock.Old_Customer_Code = stock[j].Customer_Code; _objstock.Customer_Code = SeqNum.ToString(); _objstock.Company_Code = _objCurInfo.GetCompanyCode(); _objstock.Region_Code = targetRegionCodes[r]; _objstock.Created_By = objCurInfo.GetUserCode(); _objstock.Move_Type = "SHIFT"; _objstock.Customer_Name = stock[j].Customer_Name; _objstock.Primary_Email = stock[j].Primary_Email; _objstock.Region_Type_Code = stock[j].Region_Type_Code; _objstock.Customer_Status = "1"; _objstock.Customer_Entity_Type = "STOCKIEST"; _objstock.Row_Status = stock[j].Row_Status; _objstock.Row_Version_No = stock[j].Row_Version_No; _objstock.CCM_Customer_ID = stock[j].CCM_Customer_ID; _objstock.Contact_Relation = stock[j].Contact_Relation; _objstock.Is_Billable = stock[j].Is_Billable; _objstock.Source_Region_Code = stock[j].Source_Region_Code; _objstock.Effective_From = stock[j].Effective_From; _objstock.Special_Discount_Rate = stock[j].Special_Discount_Rate; _objstock.Octroi_Rate = stock[j].Octroi_Rate; _objstock.Address1 = stock[j].Address1; _objstock.Address2 = stock[j].Address2; _objstock.Additional_Surcharge_Status = stock[j].Additional_Surcharge_Status; _objstock.Category = stock[j].Category; _objstock.CForm_Availability = stock[j].CForm_Availability; _objstock.City = stock[j].City; _objstock.CST_Applicable = stock[j].CST_Applicable; _objstock.CST_Number = stock[j].CST_Number; _objstock.Customer_Group = stock[j].Customer_Group; _objstock.Depot_Code = stock[j].Depot_Code; _objstock.Destination_Place = stock[j].Destination_Place; _objstock.Registered_Delear_Status = stock[j].Registered_Delear_Status; _objstock.Tax_Exempted_Status = stock[j].Tax_Exempted_Status; _objstock.Tin_Number = stock[j].Tin_Number; _objstock.Product_Discount_Applicable_Status = stock[j].Product_Discount_Applicable_Status; _objstock.Primary_Contact = stock[j].Primary_Contact; _objstock.Is_Inherited = stock[j].Is_Inherited; _objstock.Local_Area = stock[j].Local_Area; _objstock.Mobile = stock[j].Mobile; _objstock.Octroi_Reimbursment_Status = stock[j].Octroi_Reimbursment_Status; _objstock.Party_Location = stock[j].Party_Location; _objstock.Place_Type = stock[j].Place_Type; _objstock.Remarks = stock[j].Remarks; _objstock.DOB = stock[j].DOB; _objstock.Email = stock[j].Email; _objstock.Fax = stock[j].Fax; _objstock.Drug_License_Number1 = stock[j].Drug_License_Number1; _objstock.Drug_License_Number2 = stock[j].Drug_License_Number2; _objstock.Locked = stock[j].Locked; _objstock.Speciality_Code = stock[j].Speciality_Code; _objstock.SubRegion_Code = stock[j].SubRegion_Code; _objstock.Phone = stock[j].Phone; _objstock.Pin_Code = stock[j].Pin_Code; _objstock.Changed_Column_Name = "Customer_Status"; _objstock.Old_Value = "1"; _objstock.New_Value = "0"; _objstock.Ref_Key1 = stock[j].Ref_Key1; _objstock.Ref_Key2 = stock[j].Ref_Key2; _objstock.Registration_Number = stock[j].Registration_Number; _objstock.SubRegion_Code = stock[j].SubRegion_Code; lstStock.Add(_objstock); a++; } } Data _objData = new Data(); try { SPData _objSPData = new SPData(); string cmdText = "SP_HDInsertShiftStockist"; SqlCommand command = new SqlCommand(cmdText); command.CommandType = CommandType.StoredProcedure; if (lstStock.Count == 0) { _objSPData.AddParamToSqlCommandWithTypeName(command, "@TVP_InheritStock", ParameterDirection.Input, SqlDbType.Structured, null, "TVP_InheritStock"); } else { _objSPData.AddParamToSqlCommandWithTypeName(command, "@TVP_InheritStock", ParameterDirection.Input, SqlDbType.Structured, new StockiestDetailsEnumurator(lstStock), "TVP_InheritStock"); } _objSPData.AddParamToSqlCommand(command, "@Result", ParameterDirection.Output, SqlDbType.VarChar, 500, strReturn); _objData.OpenConnection(lstStock[0].Company_Code); _objData.ExecuteNonQuery(command); return(command.Parameters["@Result"].Value.ToString()); } catch (Exception ex) { return(ex.Message + "^" + ex.StackTrace); } finally { _objData.CloseConnection(); } } return(strReturn); } catch (Exception ex) { return(ex.Message + "^" + ex.StackTrace); } }
public string InheritStockiest(List <MVCModels.StockiestHeaderDetails> stock, string[] targetRegionCodes, out string matchingResult) { List <MVCModels.StockiestHeaderDetails> lstRegionStock = new List <StockiestHeaderDetails>(); DataControl.CurrentInfo objCurInfo = new CurrentInfo(); Data _objData = new Data(); matchingResult = ""; int r = 0; string region = string.Join("^", targetRegionCodes); List <StockiestDetails> stockdetails = new List <StockiestDetails>(); try { using (IDbConnection connection = IDbOpenConnection()) { var parameter = new DynamicParameters(); parameter.Add("@RegionCodes", region); stockdetails = connection.Query <MVCModels.StockiestDetails>(SP_HDGETSTOCKIESTDETAILS, parameter, commandType: CommandType.StoredProcedure).ToList(); } foreach (var st in stock) { List <MVCModels.StockiestDetails> lstStock = stockdetails.Where(x => x.Customer_Code == st.Customer_Code).ToList(); if (lstStock.Count > 0) { matchingResult = "Selected Stockiest " + lstStock[0].Customer_Name + " is already in inherited status for the selected target region"; break; } } } catch { throw; } if (matchingResult != "") { return("-2"); } else { try { using (IDbConnection connection = IDbOpenConnection()) { r = 0; List <MVCModels.StockiestHeaderDetails> lstStock1 = new List <StockiestHeaderDetails>(); List <MVCModels.StockiestHeaderDetails> lstStock = new List <StockiestHeaderDetails>(); int a = 0; for (r = 0; r < targetRegionCodes.Count() - 1; r++) { for (int j = 0; j < stock.Count; j++) { StockiestHeaderDetails _objstock = new StockiestHeaderDetails(); _objstock.ID = a; _objstock.Company_Code = _objCurInfo.GetCompanyCode(); _objstock.Region_Code = targetRegionCodes[r]; _objstock.Created_By = objCurInfo.GetUserCode(); _objstock.Move_Type = "INHERIT"; _objstock.Customer_Code = stock[j].Customer_Code; _objstock.Customer_Name = stock[j].Customer_Name; _objstock.Primary_Email = stock[j].Primary_Email; _objstock.Region_Type_Code = stock[j].Region_Type_Code; _objstock.Customer_Status = "1"; _objstock.Customer_Entity_Type = "STOCKIEST"; _objstock.Row_Status = stock[j].Row_Status; _objstock.Row_Version_No = stock[j].Row_Version_No; _objstock.CCM_Customer_ID = stock[j].CCM_Customer_ID; _objstock.Contact_Relation = stock[j].Contact_Relation; _objstock.Is_Billable = stock[j].Is_Billable; _objstock.Source_Region_Code = stock[j].Source_Region_Code; _objstock.Effective_From = stock[j].Effective_From; _objstock.Special_Discount_Rate = stock[j].Special_Discount_Rate; _objstock.Octroi_Rate = stock[j].Octroi_Rate; _objstock.Address1 = stock[j].Address1; _objstock.Address2 = stock[j].Address2; _objstock.Additional_Surcharge_Status = stock[j].Additional_Surcharge_Status; _objstock.Category = stock[j].Category; _objstock.CForm_Availability = stock[j].CForm_Availability; _objstock.City = stock[j].City; _objstock.CST_Applicable = stock[j].CST_Applicable; _objstock.CST_Number = stock[j].CST_Number; _objstock.Customer_Group = stock[j].Customer_Group; _objstock.Depot_Code = stock[j].Depot_Code; _objstock.Destination_Place = stock[j].Destination_Place; _objstock.Registered_Delear_Status = stock[j].Registered_Delear_Status; _objstock.Tax_Exempted_Status = stock[j].Tax_Exempted_Status; _objstock.Tin_Number = stock[j].Tin_Number; _objstock.Product_Discount_Applicable_Status = stock[j].Product_Discount_Applicable_Status; _objstock.Primary_Contact = stock[j].Primary_Contact; _objstock.Is_Inherited = stock[j].Is_Inherited; _objstock.Local_Area = stock[j].Local_Area; _objstock.Mobile = stock[j].Mobile; _objstock.Octroi_Reimbursment_Status = stock[j].Octroi_Reimbursment_Status; _objstock.Party_Location = stock[j].Party_Location; _objstock.Place_Type = stock[j].Place_Type; _objstock.Remarks = stock[j].Remarks; _objstock.DOB = stock[j].DOB; _objstock.Email = stock[j].Email; _objstock.Fax = stock[j].Fax; _objstock.Drug_License_Number1 = stock[j].Drug_License_Number1; _objstock.Drug_License_Number2 = stock[j].Drug_License_Number2; _objstock.Locked = stock[j].Locked; _objstock.Speciality_Code = stock[j].Speciality_Code; _objstock.SubRegion_Code = stock[j].SubRegion_Code; _objstock.Phone = stock[j].Phone; _objstock.Pin_Code = stock[j].Pin_Code; _objstock.Ref_Key1 = stock[j].Ref_Key1; _objstock.Ref_Key2 = stock[j].Ref_Key2; _objstock.Registration_Number = stock[j].Registration_Number; _objstock.SubRegion_Code = stock[j].SubRegion_Code; lstStock.Add(_objstock); a++; } } string strReturn = ""; try { SPData _objSPData = new SPData(); string cmdText = "SP_Hd_InsertStockiestInheritence"; SqlCommand command = new SqlCommand(cmdText); command.CommandType = CommandType.StoredProcedure; if (lstStock.Count == 0) { _objSPData.AddParamToSqlCommandWithTypeName(command, "@TVP_InheritStock", ParameterDirection.Input, SqlDbType.Structured, null, "TVP_InheritStock"); } else { _objSPData.AddParamToSqlCommandWithTypeName(command, "@TVP_InheritStock", ParameterDirection.Input, SqlDbType.Structured, new StockiestDetailsEnumurator(lstStock), "TVP_InheritStock"); } _objSPData.AddParamToSqlCommand(command, "@Result", ParameterDirection.Output, SqlDbType.VarChar, 500, strReturn); _objData.OpenConnection(lstStock[0].Company_Code); _objData.ExecuteNonQuery(command); } finally { _objData.CloseConnection(); } return(strReturn); } } catch { throw; } } }