public string InsertUpdate(string ADTCCode, string BDTCCode, string CDTCCode, string DDTCCode, bool DTCCodeAI, bool DTCCodeBI, bool DTCCodeCI, bool DTCCodeDI, string Operation, string Conclusion, string Smiley, string btnSave, string HFV) { string insQry = "Failure"; bool Status = false; bool StatusA = false; bool StatusB = false; bool StatusC = false; bool StatusD = false; bool temp = false; using (miniSmartDataContext datacontext = new miniSmartDataContext()) { tab_CA_EMS_DTC_LOGIC_BUILD build = new tab_CA_EMS_DTC_LOGIC_BUILD(); string Result = "0"; SqlDataReader objDR = null; string DTCCodeA = ""; string DTCCodeB = ""; string DTCCodeC = ""; string DTCCodeD = ""; string DTClogicA = ""; string DTClogicB = ""; string DTClogicC = ""; string DTClogicD = ""; string[] wordA = ADTCCode.Split('_'); DTCCodeA = Convert.ToString(wordA[0]); DTClogicA = Convert.ToString(wordA[1]); string[] wordB = BDTCCode.Split('_'); DTCCodeB = Convert.ToString(wordB[0]); if (wordB.Length > 1) { DTClogicB = Convert.ToString(wordB[1]); } string[] wordC = CDTCCode.Split('_'); DTCCodeC = Convert.ToString(wordC[0]); if (wordC.Length > 1) { DTClogicC = Convert.ToString(wordC[1]); } string[] wordD = DDTCCode.Split('_'); DTCCodeD = Convert.ToString(wordD[0]); if (wordD.Length > 1) { DTClogicD = Convert.ToString(wordD[1]); } string ConQuery = string.Empty; if (btnSave == "Add") { if ((DTCCodeB == "0" || DTCCodeB == "-1") && (DTCCodeC == "0" || DTCCodeC == "-1") && (DTCCodeD == "0" || DTCCodeD == "-1")) { ConQuery = "select count(dtc_LOGIC_BUILD_PK) as BuildCount from tab_CA_EMS_DTC_LOGIC_BUILD where dtc_DTC_CODE_A = '" + DTCCodeA + "' and dtc_DTC_LOGIC_A = '" + DTClogicA + "'"; ConQuery += " and dtc_DTC_CODE_B is null and dtc_DTC_CODE_C is null and dtc_DTC_CODE_D is null "; } else { ConQuery = "select count(dtc_LOGIC_BUILD_PK) as BuildCount from tab_CA_EMS_DTC_LOGIC_BUILD where "; if (DTCCodeA != "0" && DTCCodeA != "-1") { ConQuery += " dtc_DTC_CODE_A = '" + DTCCodeA + "' and dtc_DTC_LOGIC_A = '" + DTClogicA + "'"; } else { ConQuery += " dtc_DTC_CODE_A = is null"; } if (DTCCodeB != "0" && DTCCodeB != "-1") { ConQuery += " and dtc_DTC_CODE_B ='" + DTCCodeB + "' and dtc_DTC_LOGIC_B = '" + DTClogicB + "'"; } else { ConQuery += " and dtc_DTC_CODE_B is null"; } if (DTCCodeC != "0" && DTCCodeC != "-1") { ConQuery += " and dtc_DTC_CODE_C ='" + DTCCodeC + "' and dtc_DTC_LOGIC_C = '" + DTClogicC + "'"; } else { ConQuery += " and dtc_DTC_CODE_C is null"; } if (DTCCodeD != "0" && DTCCodeD != "-1") { ConQuery += " and dtc_DTC_CODE_D ='" + DTCCodeD + "' and dtc_DTC_LOGIC_D = '" + DTClogicD + "'"; } else { ConQuery += " and dtc_DTC_CODE_D is null"; } ConQuery += " and dtc_LOGIC_OPERATION='" + Operation + "'"; } } else { if ((DTCCodeB == "0" || DTCCodeB == "-1") && (DTCCodeC == "0" || DTCCodeC == "-1") && (DTCCodeD == "0" || DTCCodeD == "-1")) { ConQuery = "select count(dtc_LOGIC_BUILD_PK) as BuildCount from tab_CA_EMS_DTC_LOGIC_BUILD where dtc_DTC_CODE_A = '" + DTCCodeA + "' and dtc_DTC_LOGIC_A = '" + DTClogicA + "' and dtc_DTC_CODE_A_INVERT = '" + DTCCodeAI + "'"; ConQuery += " and dtc_DTC_CODE_B is null and dtc_DTC_CODE_C is null and dtc_DTC_CODE_D is null "; ConQuery += " and dtc_LOGIC_BUILD_PK <> " + Convert.ToInt32(HFV) + " "; } else { ConQuery = "select count(dtc_LOGIC_BUILD_PK) as BuildCount from tab_CA_EMS_DTC_LOGIC_BUILD where "; if (DTCCodeA != "0" && DTCCodeA != "-1") { ConQuery += " dtc_DTC_CODE_A = '" + DTCCodeA + "' and dtc_DTC_LOGIC_A = '" + DTClogicA + "' and dtc_DTC_CODE_A_INVERT = '" + DTCCodeAI + "'"; } else { ConQuery += " dtc_DTC_CODE_A = is null"; } if (DTCCodeB != "0" && DTCCodeB != "-1") { ConQuery += " and dtc_DTC_CODE_B ='" + DTCCodeB + "' and dtc_DTC_LOGIC_B = '" + DTClogicB + "' and dtc_DTC_CODE_B_INVERT = '" + DTCCodeBI + "'"; } else { ConQuery += " and dtc_DTC_CODE_B is null"; } if (DTCCodeC != "0" && DTCCodeC != "-1") { ConQuery += " and dtc_DTC_CODE_C ='" + DTCCodeC + "' and dtc_DTC_LOGIC_C = '" + DTClogicC + "' and dtc_DTC_CODE_C_INVERT = '" + DTCCodeCI + "'"; } else { ConQuery += " and dtc_DTC_CODE_C is null"; } if (DTCCodeD != "0" && DTCCodeD != "-1") { ConQuery += " and dtc_DTC_CODE_D ='" + DTCCodeD + "' and dtc_DTC_LOGIC_D = '" + DTClogicD + "' and dtc_DTC_CODE_D_INVERT = '" + DTCCodeDI + "'"; } else { ConQuery += " and dtc_DTC_CODE_D is null"; } ConQuery += " and dtc_LOGIC_OPERATION='" + Operation + "'"; ConQuery += " and dtc_LOGIC_BUILD_PK <> " + Convert.ToInt32(HFV) + " "; } } objDR = DBL.ExecuteReader(Config.getConnString(), CommandType.Text, ConQuery); if (objDR.HasRows) { objDR.Read(); Result = Convert.ToString(objDR[0]); } else { Result = "0"; } if (!objDR.IsClosed) { objDR.Close(); } if (Result != "0") { insQry = "DTC Build Logic already Exist"; } else { if (btnSave == "Add") { if (DTCCodeA != "0" && DTCCodeA != "-1") { build.dtc_DTC_CODE_A = DTCCodeA; build.dtc_DTC_LOGIC_A = DTClogicA; string qryStatus = "select dtc_LOGIC_RESULT from tab_CA_EMS_DTC_LOGIC_Add where dtc_DTC_CODE = '" + DTCCodeA + "' and dtc_LOGIC = '" + DTClogicA + "'"; StatusA = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qryStatus)); if (DTCCodeAI) { StatusA = !StatusA; } build.dtc_DTC_CODE_A_INVERT = DTCCodeAI; } if (DTCCodeB != "0" && DTCCodeB != "-1") { build.dtc_DTC_CODE_B = DTCCodeB; build.dtc_DTC_LOGIC_B = DTClogicB; string qryStatus = "select dtc_LOGIC_RESULT from tab_CA_EMS_DTC_LOGIC_Add where dtc_DTC_CODE = '" + DTCCodeB + "' and dtc_LOGIC = '" + DTClogicB + "'"; StatusB = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qryStatus)); if (DTCCodeBI) { StatusB = !StatusB; } build.dtc_DTC_CODE_B_INVERT = DTCCodeBI; } if (DTCCodeC != "0" && DTCCodeC != "-1") { build.dtc_DTC_CODE_C = DTCCodeC; build.dtc_DTC_LOGIC_C = DTClogicC; string qryStatus = "select dtc_LOGIC_RESULT from tab_CA_EMS_DTC_LOGIC_Add where dtc_DTC_CODE = '" + DTCCodeC + "' and dtc_LOGIC = '" + DTClogicC + "'"; StatusC = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qryStatus)); if (DTCCodeCI) { StatusC = !StatusC; } build.dtc_DTC_CODE_C_INVERT = DTCCodeCI; } if (DTCCodeD != "0" && DTCCodeD != "-1") { build.dtc_DTC_CODE_D = DTCCodeD; build.dtc_DTC_LOGIC_D = DTClogicD; string qryStatus = "select dtc_LOGIC_RESULT from tab_CA_EMS_DTC_LOGIC_Add where dtc_DTC_CODE = '" + DTCCodeD + "' and dtc_LOGIC = '" + DTClogicD + "'"; StatusC = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qryStatus)); if (DTCCodeDI) { StatusD = !StatusD; } build.dtc_DTC_CODE_D_INVERT = DTCCodeDI; } if (Operation == "AND") { if (StatusA) { Status = true; if (DTCCodeB != "0" && DTCCodeB != "-1") { if (StatusB) { Status = true; } else { Status = false; } } } else { Status = false; } if (DTCCodeC != "0" && DTCCodeC != "-1") { if (StatusC && Status) { Status = true; } else { Status = false; } } if (DTCCodeD != "0" && DTCCodeD != "-1") { if (StatusD && Status) { Status = true; } else { Status = false; } } } else if (Operation == "OR") { if (StatusA || StatusB || StatusC || StatusD) { Status = true; } else { Status = false; } } else { if (StatusA || StatusB || StatusC || StatusD) { Status = true; } else { Status = false; } } build.dtc_LOGIC_SMILEY = Smiley; build.dtc_LOGIC_OPERATION = Operation; build.dtc_LOGIC_CONCLUSION = Conclusion; build.dtc_LOGIC_STATUS = Status; datacontext.tab_CA_EMS_DTC_LOGIC_BUILDs.InsertOnSubmit(build); datacontext.SubmitChanges(); insQry = "DTC Logic Build added successfully"; } else if (btnSave == "Update") { var buildDetails = datacontext.tab_CA_EMS_DTC_LOGIC_BUILDs.FirstOrDefault(x => x.dtc_LOGIC_BUILD_PK == Convert.ToInt32(HFV)); if (buildDetails != null) { if (DTCCodeA != "0" && DTCCodeA != "-1") { Status = true; buildDetails.dtc_DTC_CODE_A = DTCCodeA; buildDetails.dtc_DTC_LOGIC_A = DTClogicA; buildDetails.dtc_DTC_CODE_A_INVERT = DTCCodeAI; string qrytemp = "select dtc_DTC_CODE_A_INVERT from tab_CA_EMS_DTC_LOGIC_BUILD where dtc_LOGIC_BUILD_PK = " + Convert.ToInt32(HFV) + " and dtc_DTC_CODE_A = '" + DTCCodeA + "'"; temp = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qrytemp)); string qryStatus = "select dtc_LOGIC_RESULT from tab_CA_EMS_DTC_LOGIC_Add where dtc_DTC_CODE = '" + DTCCodeA + "' and dtc_LOGIC = '" + DTClogicA + "'"; StatusA = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qryStatus)); bool vartemp = temp; if (DTCCodeAI != temp) { vartemp = !temp; } if (vartemp) { StatusA = !StatusA; } } if (DTCCodeB != "0" && DTCCodeB != "-1") { buildDetails.dtc_DTC_CODE_B = DTCCodeB; buildDetails.dtc_DTC_LOGIC_B = DTClogicB; buildDetails.dtc_DTC_CODE_B_INVERT = DTCCodeBI; string qrytemp = "select dtc_DTC_CODE_B_INVERT from tab_CA_EMS_DTC_LOGIC_BUILD where dtc_LOGIC_BUILD_PK = " + Convert.ToInt32(HFV) + " and dtc_DTC_CODE_B = '" + DTCCodeB + "'"; temp = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qrytemp)); string qryStatus = "select dtc_LOGIC_RESULT from tab_CA_EMS_DTC_LOGIC_Add where dtc_DTC_CODE = '" + DTCCodeB + "' and dtc_LOGIC = '" + DTClogicB + "'"; StatusB = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qryStatus)); bool vartemp = temp; if (DTCCodeBI != temp) { vartemp = !temp; } if (vartemp) { StatusB = !StatusB; } } else { buildDetails.dtc_DTC_CODE_B = null; } if (DTCCodeC != "0" && DTCCodeC != "-1") { buildDetails.dtc_DTC_CODE_C = DTCCodeC; buildDetails.dtc_DTC_LOGIC_C = DTClogicC; buildDetails.dtc_DTC_CODE_C_INVERT = DTCCodeCI; string qrytemp = "select dtc_DTC_CODE_C_INVERT from tab_CA_EMS_DTC_LOGIC_BUILD where dtc_LOGIC_BUILD_PK = " + Convert.ToInt32(HFV) + " and dtc_DTC_CODE_C = '" + DTCCodeC + "'"; temp = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qrytemp)); string qryStatus = "select dtc_LOGIC_RESULT from tab_CA_EMS_DTC_LOGIC_Add where dtc_DTC_CODE = '" + DTCCodeC + "' and dtc_LOGIC = '" + DTClogicC + "'"; StatusC = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qryStatus)); bool vartemp = temp; if (DTCCodeCI != temp) { vartemp = !temp; } if (vartemp) { StatusC = !StatusC; } } else { buildDetails.dtc_DTC_CODE_C = null; } if (DTCCodeD != "0" && DTCCodeD != "-1") { buildDetails.dtc_DTC_CODE_D = DTCCodeD; buildDetails.dtc_DTC_LOGIC_D = DTClogicD; buildDetails.dtc_DTC_CODE_D_INVERT = DTCCodeDI; string qrytemp = "select dtc_DTC_CODE_D_INVERT from tab_CA_EMS_DTC_LOGIC_BUILD where dtc_LOGIC_BUILD_PK = " + Convert.ToInt32(HFV) + " and dtc_DTC_CODE_D = '" + DTCCodeD + "'"; temp = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qrytemp)); string qryStatus = "select dtc_LOGIC_RESULT from tab_CA_EMS_DTC_LOGIC_Add where dtc_DTC_CODE = '" + DTCCodeD + "' and dtc_LOGIC = '" + DTClogicD + "'"; StatusD = Convert.ToBoolean(DBL.executeScalar(ConnectionString.GetDBConnectionString(), CommandType.Text, qryStatus)); bool vartemp = temp; if (DTCCodeDI != temp) { vartemp = !temp; } if (vartemp) { StatusD = !StatusD; } } else { buildDetails.dtc_DTC_CODE_D = null; } if (Operation == "AND") { if (StatusA) { Status = true; if (DTCCodeB != "0" && DTCCodeB != "-1") { if (StatusB) { Status = true; } else { Status = false; } } } else { Status = false; } if (DTCCodeC != "0" && DTCCodeC != "-1") { if (StatusC && Status) { Status = true; } else { Status = false; } } if (DTCCodeD != "0" && DTCCodeD != "-1") { if (StatusD && Status) { Status = true; } else { Status = false; } } } else if (Operation == "OR") { if (StatusA || StatusB || StatusC || StatusD) { Status = true; } else { Status = false; } } else { if (StatusA || StatusB || StatusC || StatusD) { Status = true; } else { Status = false; } } buildDetails.dtc_LOGIC_SMILEY = Smiley; buildDetails.dtc_LOGIC_OPERATION = Operation; buildDetails.dtc_LOGIC_CONCLUSION = Conclusion; buildDetails.dtc_LOGIC_STATUS = Status; datacontext.SubmitChanges(); insQry = "DTC Logic Build Updated successfully"; } } } return(insQry); } }
private void GetLoginDetails() { secureData objSecure = new secureData(); SqlDataReader objDr = null; //var UserType = Convert.ToInt32(hfvUserType.Value); var Sautation = ""; var UserName = txtAccessCode.Text; var Password = objSecure.DESEncrypt(txtPassword.Text); objSecure = null; string selectQry = "SP_CheckLogin"; SqlParameter[] objParameter = new SqlParameter[2]; //objParameter[0] = new SqlParameter("@userType", UserType); objParameter[0] = new SqlParameter("@loginID", UserName); objParameter[1] = new SqlParameter("@password", Password); try { objDr = DBL.ExecuteReader(ConnectionString, CommandType.StoredProcedure, selectQry, objParameter); if (objDr.HasRows) { objDr.Read(); Session["AccessCode"] = Convert.ToInt32(objDr["user_ID_PK"]); Session["DealerID"] = null; Session["UserType"] = Convert.ToString(objDr["user_ROLE"]); if (objDr["user_GENDER"] != DBNull.Value) { if (Convert.ToInt32(objDr["user_GENDER"]) == 0) { Sautation = "Mr."; } else { Sautation = "Ms."; } } Session["LoginName"] = Convert.ToString(objDr["user_FIRST_NAME"]) + " " + Convert.ToString(objDr["user_LAST_NAME"]); int iRole = Convert.ToInt32(objDr["user_ROLE"]); Session["AdminRole"] = Convert.ToString(objDr["user_ROLE"]); if (objDr.IsClosed == false) { objDr.Close(); Response.Redirect("~/Modules/DTC/Vehicle_DTC.aspx?MnuID=DSsID"); } if (objDr.IsClosed == false) { objDr.Close(); objDr.Dispose(); } } else { Response.Redirect("default.aspx?err=EUP"); } } catch (Exception ex) { Response.Write(ex.Message); } finally { if (objDr != null) { if (!objDr.IsClosed) { objDr.Close(); } objDr.Dispose(); } } }