Rewriting search button from web forms application to mvc4 - asp.net-mvc-4

I have a web forms application with a service reference
and I need to rewrite only the front-end of it in mvc4
I'm having trouble with search button (still new to programming)
this is the code of it in web forms
private void btnSearch_Click(object sender, EventArgs e)
{
ClearViewers();
btnSearch.Enabled = false;
btnSyncronise.Enabled = false;
PersonalInformation localInfo = null;
PersonInfo[] registryInfo = null;
needsUpdate = false;
Cursor = Cursors.WaitCursor;
try
{
if ((String.IsNullOrEmpty(txtPersonalNumber.Text)) || (txtPersonalNumber.Text.Length != 11) || (Regex.Match(txtPersonalNumber.Text, "^\\d{11}$").Success == false))
{
MessageBox.Show(#"blabla" + Environment.NewLine + #"blablabla" + Environment.NewLine + #"blabla", #"blabla", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
using (PersonalInfoServiceClient proxy = new PersonalInfoServiceClient())
{
try
{
localInfo = proxy.GetLocalInfoForPerson(txtPersonalNumber.Text.Trim());
if (localInfo != null)
{
ssStatusLocal.ForeColor = Color.Green;
ssStatusLocal.Text = #"found personal ID";
lblFirstName.Text = localInfo.FirstName;
lblLastName.Text = localInfo.LastName;
lblMiddleName.Text = localInfo.MiddleName;
lblBirthDate.Text = String.Format("{0:MM/dd/yyyy}", localInfo.BirthDate);
if (localInfo.PersonStatus == PersonStatus.Active)
lblStatus.Text = #"active";
else if (localInfo.PersonStatus == PersonStatus.Rejected)
lblStatus.Text = #"passive";
else if (localInfo.PersonStatus == PersonStatus.Dead)
lblStatus.Text = #"dead";
else
lblStatus.Text = #"unknown";
lblSex.Text = (Convert.ToInt32(localInfo.Sex) == 1) ? #"male" : #"female";
lblAddress.Text = localInfo.Address;
lbBirthPlace.Text = localInfo.BirthPlace;
lbCitizenShip.Text = (string.IsNullOrEmpty(localInfo.CitizenShip) && string.IsNullOrEmpty(localInfo.CitizenShipCode)) ? localInfo.CitizenShip : localInfo.CitizenShip + " / " + localInfo.CitizenShipCode;
lbDoubleCitizenShip.Text = (string.IsNullOrEmpty(localInfo.DoubleCitizenShip) && string.IsNullOrEmpty(localInfo.DoubleCitizenShipCode)) ? localInfo.DoubleCitizenShip : localInfo.DoubleCitizenShip + " / " + localInfo.DoubleCitizenShipCode;
lblRegion.Text = localInfo.RegionName;
if (localInfo.Photo != null)
{
MemoryStream MS = new MemoryStream(localInfo.Photo);
pictureBox2.Image = Image.FromStream(MS);
}
documentInformationBindingSource1.DataSource = localInfo.Documents;
}
else
{
ssStatusLocal.ForeColor = Color.Red;
ssStatusLocal.Text = #"personal ID not found";
}
}
catch
{
ssStatusLocal.ForeColor = Color.Red;
ssStatusLocal.Text = #"error";
throw;
}
try
{
registryInfo = proxy.GetRegistryInfoForPerson(txtPersonalNumber.Text.Trim());
if (registryInfo != null && registryInfo.Length > 0)
{
ssStatusCivil.ForeColor = Color.Green;
ssStatusCivil.Text = #"found personal ID";
btnSyncronise.Enabled = true;
RegistryPersonInfos list = new RegistryPersonInfos();
foreach (PersonInfo personInfo in registryInfo)
{
RegistryPersonInfo registryPersonInfo = new RegistryPersonInfo()
{
BirthDate = personInfo.BirthDate
,
IsDead = (personInfo.IsPersonDead) ? "yes" : "no"
,
FirstName = personInfo.FirstName
,
LastName = personInfo.LastName
,
MiddleName = personInfo.MiddleName
,
DocumentStatusName = personInfo.DocumentStatusStr
,
DocumentStatus = personInfo.DocumentStatusEnum.ToString()
,
PersonalNumber = personInfo.PrivateNumber
,
DocumentRejectDate = personInfo.RejectedDate
,
DocumentType = (personInfo.IsIdCard) ? (string.IsNullOrEmpty(personInfo.IdCardNumber)) ? "one" : "two" : "three"
,
DocumentSerie = (personInfo.IsIdCard) ? personInfo.IdCardSerial : string.Empty
,
DocumentNumber = (personInfo.IsIdCard) ? (string.IsNullOrEmpty(personInfo.IdCardNumber)) ? string.Empty : personInfo.IdCardNumber : personInfo.PaspNumber
};
list.Add(registryPersonInfo);
}
registryPersonInfoBindingSource.DataSource = list;
}
else
{
ssStatusCivil.ForeColor = Color.Red;
ssStatusCivil.Text = #"Personal ID not found";
}
}
catch
{
ssStatusCivil.ForeColor = Color.Red;
ssStatusCivil.Text = #"error";
throw;
}
}
}
catch (Exception x)
{
lblFirstName.Text = String.Empty;
lblLastName.Text = String.Empty;
lblMiddleName.Text = String.Empty;
lblStatus.Text = String.Empty;
needsUpdate = false;
dgwMain.DataSource = null;
MessageBox.Show(
String.Format(
"error during loading. {0} error: {1} {2} info: {3}",
Environment.NewLine, x.Message, Environment.NewLine,
(x.InnerException == null) ? string.Empty : x.InnerException.Message), #"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Cursor = Cursors.Default;
btnSearch.Enabled = true;
}
}
how do you write this in controller?
the controller can't find labels, there is no picturebox
I have no idea how to get data via service reference
could you help ?

Related

Android MPAndroidChart xAxis.setValueFormatter throws ArrayIndexOutOfBoundsException

Good morning,
I'm struggling with ArrayIndexOutOfBoundsException thrown when i'm inserting the row
xAxis.setValueFormatter(formatter) (commented in code).
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bc = findViewById(R.id.chart);
CaricaStorico cs = new CaricaStorico();
try {
cs.execute().get();
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
List<BarEntry> turno1 = new ArrayList<>();
List<BarEntry> turno2 = new ArrayList<>();
List<BarEntry> turno3 = new ArrayList<>();
String[] date = new String[100];
boolean datiturno1 = false;
boolean datiturno2 = false;
boolean datiturno3 = false;
for (int i = 0; i < storicoMacchina.size(); i++) {
Storico st = storicoMacchina.get(i);
System.out.println(st.getData() + " - " + st.getProduzione1() + " - " + st.getProduzione2() + " - " + st.getProduzione3());
turno1.add(new BarEntry(i, st.getProduzione1()));
turno2.add(new BarEntry(i, st.getProduzione2()));
turno3.add(new BarEntry(i, st.getProduzione3()));
if (st.getProduzione1() != 0) {
datiturno1 = true;
}
if (st.getProduzione2() != 0) {
datiturno2 = true;
}
if (st.getProduzione3() != 0) {
datiturno3 = true;
}
Calendar c = Calendar.getInstance();
c.setTime(st.getData());
String dataMese = c.get(Calendar.DAY_OF_MONTH) + "/" + (c.get(Calendar.MONTH) + 1);
xLabels.add(dataMese);
}
ValueFormatter formatter = new ValueFormatter() {
#Override
public String getAxisLabel(float value, AxisBase axis) {
return xLabels.get((int) value);
}
};
BarDataSet set1 = null;
BarDataSet set2 = null;
BarDataSet set3 = null;
set1 = new BarDataSet(turno1, "Turno 1");
set2 = new BarDataSet(turno2, "Turno 2");
set3 = new BarDataSet(turno3, "Turno 3");
System.out.println(datiturno1 + "," + datiturno2 + "," + datiturno3);
float groupSpace = 0.04f;
float barSpace = 0.02f;
float barWidth = 0.3f;
// set1.setColors(new int[] { R.color.red, R.color.red1, R.color.red2, R.color.red3 },MainActivity.this);
set1.setColor(getResources().getColor(R.color.turno1));
set2.setColor(getResources().getColor(R.color.turno2));
set3.setColor(getResources().getColor(R.color.turno3));
BarData barData;
if (datiturno3 == false) {
barData = new BarData(set1, set2);
groupSpace = 0.06f;
barSpace = 0.02f;
barWidth = 0.45f;
} else {
barData = new BarData(set1, set2, set3);
}
barData.setBarWidth(barWidth);
bc.setData(barData);
Description desc = new Description();
desc.setText("Produzione ultima settimana");
bc.setDescription(desc);
bc.groupBars(0, groupSpace, barSpace);
XAxis xAxis = bc.getXAxis();
xAxis.setCenterAxisLabels(true);
xAxis.setPosition(XAxis.XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1);
xAxis.setAxisMaximum(storicoMacchina.size());
// xAxis.setValueFormatter(formatter);
bc.invalidate();
}
without this line code is working fine except for the labels in xAxis that i'm trying to set with this line.
Anyone can help me to find what i'm doing wrong?
Thank you for your help
your text
I'have found workaround to solve my problem changing the code above with this
If anyone can explain me the reason value index differs from my xlabel, dataset size will be appreciated.
Thanks again
public String getAxisLabel(float value, AxisBase axis) {
String label = "";
if ((value >= 0) && (value <= xLabels.size() -1)) {
label = xLabels.get((int) value);
}
return label;
}

Pdf file renaming and deleting not working in Android 10 using MediaStore

I create an app that fetch all pdf documents from Phone storage... But in Android 10 devices , all pdfs not retrieved ... and even when I shall be tried to rename the pdf file , the pdf file is gone...
this is my code :
#NonNull
public ArrayList getAllPdfs(#NonNull Context context1) {
String str = null;
Uri collection;
ArrayList<PdfModel> arrayList = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
collection = MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL);
} else {
collection = MediaStore.Files.getContentUri("external");
}
// collection = MediaStore.Files.getContentUri("external");
try {
final String[] projection = new String[]{
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DISPLAY_NAME,
MediaStore.Files.FileColumns.DATE_ADDED,
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.MIME_TYPE,
};
Context context = getActivity();
SharedPreferences save_preferences = homeContext.getSharedPreferences(MY_SORT_PREF,
MODE_PRIVATE);
SharedPreferences preferencesOrder = homeContext.getSharedPreferences("Order", MODE_PRIVATE);
String order_by_descending = preferencesOrder.getString("order", "descending");
String order = null;
switch (order_by_descending) {
case "descending":
String sort = save_preferences.getString("sorting", "SortByDate");
switch (sort) {
case "SortByName":
order = MediaStore.Files.FileColumns.DISPLAY_NAME + " DESC";
break;
case "SortByDate":
order = MediaStore.Files.FileColumns.DATE_ADDED + " DESC";
break;
case "SortBySize":
order = MediaStore.Files.FileColumns.SIZE + " DESC";
break;
}
break;
case "ascending":
String sort_date = save_preferences.getString("sorting", "SortByDate");
switch (sort_date) {
case "SortByName":
order = MediaStore.Files.FileColumns.DISPLAY_NAME + " ASC";
break;
case "SortByDate":
order = MediaStore.Files.FileColumns.DATE_ADDED + " ASC";
break;
case "SortBySize":
order = MediaStore.Files.FileColumns.SIZE + " ASC";
break;
}
break;
}
final String selection = MediaStore.Files.FileColumns.MIME_TYPE + " = ?";
final String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf");
final String[] selectionArgs = new String[]{mimeType};
CursorLoader cursorLoader = new CursorLoader(context1, collection, projection, selection,
selectionArgs, order);
Cursor cursor = cursorLoader.loadInBackground();
if (cursor != null && cursor.moveToFirst()) {
do {
int columnName = cursor.getColumnIndex(MediaStore.Files.FileColumns.DISPLAY_NAME);
int columnData = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
String path = cursor.getString(columnData);
if (new File(path).exists()) {
#SuppressLint("Range")
File file = new
File(cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA)));
if (file.exists()) {
Log.d(TAG, "getAllPdfs: a " + file.length());
PdfModel pdfModel = new PdfModel();
//------------------------------Remove (.pdf) extension------------------------
String fileName = file.getName();
if (fileName.indexOf(".") > 0)
fileName = fileName.substring(0, fileName.lastIndexOf("."));
Uri imageUri = Uri.fromFile(file.getAbsoluteFile());
Log.d(TAG, "getAllPdfs: bb " + file.getName());
pdfModel.setId(file.getName());
pdfModel.setName(removeExtension(file.getName()));
pdfModel.setAbsolutePath(file.getAbsolutePath());
pdfModel.setParentFilePath(Objects.requireNonNull(file.getParentFile()).getName());
pdfModel.setPdfUri(file.toString());
pdfModel.setLength(file.length());
pdfModel.setLastModified(file.lastModified());
//pdfModel.setThumbNailUri(file.);
arrayList.add(pdfModel);
} else {
Log.d(TAG, "getAllPdfs: ");
}
}
} while (cursor.moveToNext());
cursor.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return arrayList;
}
Please solve this problem ....

connect to ssrs srevice in asp.net core

I get exception when connection with ssrs service last for more than 5 minutes
var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;
binding.MaxBufferSize = 2147483647;
binding.SendTimeout = TimeSpan.FromMinutes(_SendTimeout);
binding.OpenTimeout = TimeSpan.FromMinutes(_SendTimeout);
binding.ReceiveTimeout = TimeSpan.FromMinutes(_SendTimeout);
binding.CloseTimeout = TimeSpan.FromMinutes(_SendTimeout);
var rsExec = new rsexec2005.ReportExecutionServiceSoapClient(binding, new
EndpointAddress(SSRSReportExecutionUrl));
var clientCredentials = new NetworkCredential(SSRSUsername, SSRSPassword,
SSRSDomain);
if (rsExec.ClientCredentials != null)
{
rsExec.ClientCredentials.Windows.AllowedImpersonationLevel =
System.Security.Principal.TokenImpersonationLevel.Impersonation;
rsExec.ClientCredentials.Windows.ClientCredential = clientCredentials;
}
LoadReportResponse report = null;
try
{
rsExec.Endpoint.EndpointBehaviors.Add(new
ReportingServicesEndpointBehavior());
report = await rsExec.LoadReportAsync(null, "/" + SSRSFolderPath + "/" +
reportName, null);
}
catch (Exception ex1)
{
return new Response { code = 1, report = null, message = ex1.InnerException +"
# "+ ex1.Message };
}
rsexec2005.ParameterValue[] reportParam = new
rsexec2005.ParameterValue[report.executionInfo.Parameters.ToList().Count];
var Count = 0;
foreach (var item in report.executionInfo.Parameters.ToList())
{
var Paramkay = Params.Keys.SingleOrDefault(i => i.ToLower() ==
item.Name.ToLower());
if (Paramkay != null)
{
reportParam[Count] = new rsexec2005.ParameterValue();
reportParam[Count].Name = item.Name;
reportParam[Count].Value = Params[Paramkay];
Count++;
}
}
await rsExec.SetExecutionParametersAsync(null, null, reportParam, "en-us");
RenderResponse response = null;
try
{
const string deviceInfo = #"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
response = await rsExec.RenderAsync(new RenderRequest(null, null, extention, deviceInfo));
}
catch (TimeoutException ex4)
{
return new Response { code = 4, report = null , message= ex4.InnerException + " # " + ex4.Message };
}
catch (Exception ex2)
{
return new Response { code = 2, report = null , message = ex2.InnerException + " # " + ex2.Message };
}

Error: Only primitive types or enumeration types are supported in this context

[HttpPost]
public ActionResult Dep_Save_Attachments(int in_queue_id, HttpPostedFileBase httpfile, string authorized_by, string authorized_to, string confirmed_by, string approved_by)
{
if (httpfile != null)
{
var folder = Server.MapPath("~/Attachments/Laptops/" + in_queue_id + "/");
var prev_fa = db.File_Attachments.Where(x => x.inventory_table_id == in_queue_id).Where(x => x.is_active == true).ToList();
var prev_hfa = db.HW_Authorization_Forms.Where(x => x.file_attachments_id == prev_fa.FirstOrDefault().file_attachments_id).Where(x => x.is_active == true).ToList();
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
if (prev_fa.Count != 0)
{
foreach (var pf in prev_fa)
{
pf.is_active = false;
db.Entry(pf).State = EntityState.Modified;
db.SaveChanges(); ;
}
}
if (prev_hfa.Count != 0)
{
foreach (var hpf in prev_hfa)
{
hpf.is_active = false;
db.Entry(hpf).State = EntityState.Modified;
db.SaveChanges(); ;
}
}
try
{
string path = System.Web.HttpContext.Current.Server.MapPath("~/Attachments/Laptops/" + in_queue_id + "/") + System.IO.Path.GetFileName(httpfile.FileName);
httpfile.SaveAs(path);
File_Attachments fa = new File_Attachments();
fa.file_attachments_id = 1;
fa.inventory_table_name = "Laptops_Transactions";
fa.inventory_table_id = in_queue_id;
fa.file_name = System.IO.Path.GetFileName(httpfile.FileName);
fa.file_path = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/Attachments/Laptops/" + httpfile.FileName;
fa.created_by = #User.Identity.Name.Remove(0, 9).ToLower();
fa.created_date = System.DateTime.Now;
fa.is_active = true;
db.File_Attachments.Add(fa);
db.SaveChanges();
Laptops_Transactions laptops_trans = db.Laptops_Transactions.Find(in_queue_id);
laptops_trans.lp_trans_type = "deployed";
laptops_trans.lp_date_returned = System.DateTime.Now;
db.Entry(laptops_trans).State = EntityState.Modified;
db.SaveChanges();
HW_Authorization_Forms hwf = new HW_Authorization_Forms();
hwf.hw_authorization_forms_id = 1;
hwf.file_attachments_id = fa.file_attachments_id;
hwf.hw_authorized_by = authorized_by;
hwf.hw_authorized_to = authorized_to;
hwf.hw_confirmed_by = confirmed_by;
hwf.hw_approved_by = approved_by;
hwf.hw_approved_date = fa.created_date;
hwf.created_by = fa.created_by;
hwf.created_date = fa.created_date;
hwf.hw_authorized_date = fa.created_date;
hwf.hw_confirmed_date = fa.created_date;
hwf.is_active = true;
db.HW_Authorization_Forms.Add(hwf);
db.SaveChanges();
}
catch
{
}
}
else
{
return Content("<script language='javascript' type='text/javascript'>alert('Please Attach the Deployment Authorization Form! Kindly go back to previous page');</script>");
}
return RedirectToAction("Index");
}
The error is on this line:
var prev_hfa = db.HW_Authorization_Forms.Where(x => x.file_attachments_id == prev_fa.FirstOrDefault().file_attachments_id).Where(x => x.is_active == true).ToList();
This is my code in the controller, actually this is working already but it suddenly have a error. I really don't have an idea why i have this kind of error where before it works perfectly.
Please help me with this. Need some advice. Thanks in advance.
The error is because of Datatype issue i guess, you need to confirm you are doing with correct datatype, file_attachments_id of database and from your comparing value must be same.
Also, is_active must be of datatype Boolean. Correcting this may solve your error.

Gridview_RowEditing empty values

I have a gridview control that i am manually binding the data in. When i edit a row and update it the values of the text boxes that are sent are always the Old Values. I've found a few threads on this but have not had any luck extracting the new values.
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
Private Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim gv As GridView = sender
For i As Integer = 0 To gv.Columns.Count Step 1
Dim cell As DataControlFieldCell = gv.Rows(e.RowIndex).Cells(i)
gv.Columns(0).ExtractValuesFromCell(e.NewValues, cell, DataControlRowState.Edit, True)
Next
For Each s As DictionaryEntry In e.NewValues
Debug.Print(s.Key & " | " & s.Value)
Next
ds.Tables("testTable").Rows(e.RowIndex).BeginEdit()
[ ... ]
ds.Tables("testTable").Rows(e.RowIndex).EndEdit()
GridView1.EditIndex = -1
BindData()
End Sub
I also want to point out that the ExtractValuesFromCell code is just my most recent attempt to get the New Data. Prior to that i was using something like this
Dim tb as TextBox = sender.Rows(e.RowIndex).Cells(1).Controls(0)
Label1.Text = tb.Text
Also here is how the data looks to start
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (ds.Tables.Count = 0) Then
ds.Tables.Add("testTable")
ds.Tables("testTable").Columns.Add("Driver Name")
ds.Tables("testTable").Columns.Add("Total")
ds.Tables("testTable").Columns.Add("# Of Calls")
ds.Tables("testTable").Columns("Total").ReadOnly = True
ds.Tables("testTable").Columns("# Of Calls").ReadOnly = True
Dim newRow As DataRow = ds.Tables("testTable").NewRow()
newRow("Driver Name") = ""
newRow("Total") = ""
newRow("# Of Calls") = ""
ds.Tables("testTable").Rows.Add(newRow)
End If
BindData()
End Sub
You should DataBind your GridView only if Not Page.IsPostback, otherwise the new values are overwritten.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdating.aspx
public static void filedownload(string Path)
{
string str = "";
FileInfo file = new FileInfo(Path);
// Checking if file exists
if (file.Exists)
{
// Clear the content of the response
HttpContext.Current.Response.ClearContent();
// LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
// Add the file size into the response header
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
// Set the ContentType
HttpContext.Current.Response.ContentType = CommonStrings.returnextension(file.Extension.ToLower());
// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
HttpContext.Current.Response.WriteFile(file.FullName);
// End the response
HttpContext.Current.Response.End();
}
else
{
// 9-vgrfu8i "File Not Found!";
}
// Response.Redirect(e.CommandArgument.ToString());
}
public static string GetBarCodeid(ListBox lbListBox)
{
string strCode = "";
if (lbListBox.Items.Count > 0)
{
for (int i = 0; i < lbListBox.Items.Count; i++)
{
if (lbListBox.Items[i].Selected == true)
{
if (strCode == "")
{
strCode = lbListBox.Items[i].Value.ToString();
}
else
{
strCode += "," + lbListBox.Items[i].Value.ToString();
}
}
}
}
return strCode;
}
public static string GetBarCodeName(ListBox lbListBox)
{
string strBarCodeName = "";
if (lbListBox.Items.Count > 0)
{
for (int i = 0; i < lbListBox.Items.Count; i++)
{
if (lbListBox.Items[i].Selected == true)
{
if (strBarCodeName == "")
{
strBarCodeName = lbListBox.Items[i].Text.ToString();
}
else
{
strBarCodeName += "," + lbListBox.Items[i].Text.ToString();
}
}
}
}
return strBarCodeName;
}
public static double GetBarCodeCount(ListBox lbListBox, double Count)
{
double intBarCodeCount = 0;
if (lbListBox.Items.Count > 0)
{
for (int i = 0; i < lbListBox.Items.Count; i++)
{
if (lbListBox.Items[i].Selected == true)
{
if (intBarCodeCount == 0)
{
intBarCodeCount = 1;
}
else
{
intBarCodeCount++;
}
}
}
}
return intBarCodeCount;
}
public static void SelectListBox(ListBox lbListBox, string strBarCodeId)
{
ExecuteProcedures ex = new ExecuteProcedures(1, MasterCommonStrings.ConnectionString);
ex.Parameters.Add("#vcrBarCodeid", SqlDbType.VarChar, 500, strBarCodeId);
DataTable dt = (DataTable)ex.LoadTableWithProcedure("Proc_Erp_Trn_Get_BarCode_Bata");
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < lbListBox.Items.Count; j++)
{
if (dt.Rows[i]["data"].ToString() == lbListBox.Items[j].Value.ToString())
{
lbListBox.Items[j].Selected = true;
break;
}
}
}
}
}
public static string GetgridBarCode(DataTable dt, string strColumnName)
{
string strBarCodeCount = "";
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (Convert.ToInt32(dt.Rows[i]["intStatus"]) != 2)
{
if (dt.Rows[i][strColumnName].ToString() != "")
if (strBarCodeCount == "")
{
strBarCodeCount = dt.Rows[i][strColumnName].ToString();
}
else
{
strBarCodeCount += dt.Rows[i][strColumnName].ToString();
}
}
}
}
return strBarCodeCount;
}
public static DataTable CheckBarCodeExistsOrNot(ListBox lbListbox, string strColumeName, string strReplacegridBarCodeid, DataView dvDescription)
{
DataTable dtDescription = new DataTable();
dtDescription = (DataTable)dvDescription.Table;
string strgridBarCode = CommonFunctions.GetgridBarCode(dtDescription, strColumeName);
string strSelectBarCode = CommonFunctions.GetBarCodeid(lbListbox);
ExecuteProcedures ex = new ExecuteProcedures(3, MasterCommonStrings.ConnectionString);
ex.Parameters.Add("#vcrgridBarcodeid", SqlDbType.VarChar, 500, strgridBarCode);
ex.Parameters.Add("#vcrSelectBarcodeid", SqlDbType.VarChar, 500, strSelectBarCode);
ex.Parameters.Add("#vcrReplaceBarCodeid", SqlDbType.VarChar, 500, strReplacegridBarCodeid);
DataTable dt = (DataTable)ex.LoadTableWithProcedure("Proc_Erp_Trn_Check_BarCode_Exists_Or_Not");
return dt;
}
public static int BarcodeUpdateIntoBarCodeDrec(string strBarCode_Description_Drec_id, SqlTransaction sqlTran, SqlConnection Con)
{
ExecuteProcedures ex = new ExecuteProcedures(1, MasterCommonStrings.ConnectionString);
ex.Parameters.Add("#intBarCode_Description_Drec_id", SqlDbType.VarChar, 8000, strBarCode_Description_Drec_id);
int i = Convert.ToInt32(ex.InvokeProcedure("Proc_Erp_Trn_Update_erp_mst_BarCode_Drec", sqlTran, ValueDataType.Number, Con));
if (i != 0)
{
return i;
}
else
{
return 0;
}
}
public static string AddBarcodeToListBox(TextBox txtScanBarcode, ListBox lbScanBarCode, ListBox lbSystemBarCode)
{
string barcodePresent = "";
if (txtScanBarcode.Text != "")
{
foreach (ListItem li in lbSystemBarCode.Items)
{
if (li.Text != txtScanBarcode.Text)
{
barcodePresent = "Not In Our System";
}
else
{
if (li.Selected == true)
{
barcodePresent = "Barcode Already Scan";
txtScanBarcode.Text = "";
txtScanBarcode.Focus();
break;
}
else
{
lbScanBarCode.Items.Add(txtScanBarcode.Text);
li.Selected = true;
txtScanBarcode.Text = "";
txtScanBarcode.Focus();
barcodePresent = "Barcode Scan Successfully";
break;
}
}
}
if (barcodePresent == "Not In Our System")
{
txtScanBarcode.Text = "";
txtScanBarcode.Focus();
}
}
else
{
barcodePresent = "Please Scan Barcode";
}
return barcodePresent;
}
public static void RemoveBarCodeFromListBox(ListBox lbScanBarCode, ListBox lbSystemBarCode)
{
if (lbScanBarCode.Items.Count > 0)
{
for (int i = 0; i < lbScanBarCode.Items.Count; i++)
{
if (lbScanBarCode.Items[i].Selected)
{
foreach (ListItem li1 in lbSystemBarCode.Items)
{
if (lbScanBarCode.Items[i].Text == li1.Text)
{
li1.Selected = false;
break;
}
}
lbScanBarCode.Items.Remove(lbScanBarCode.Items[i]);
}
}
}
}
public static void AddBarcodeToGridListBox(ListBox lbBarCode, ListBox lbGridScanBarCodeDisplay)
{
if (lbBarCode.Items.Count > 0)
{
for (int i = 0; i < lbBarCode.Items.Count; i++)
{
if (lbBarCode.Items[i].Selected == true)
{
lbGridScanBarCodeDisplay.Items.Add(lbBarCode.Items[i].Text);
}
}
}
}
public static void Alert(string strMessage, System.Web.UI.Page PAGE)
{
HttpContext Current = HttpContext.Current;
string strScript = "<script type=text/javascript>alert('" + strMessage + "')</script>";
if (!PAGE.IsStartupScriptRegistered("Alert"))
{
PAGE.RegisterStartupScript("Alert", strScript);
}
}
public static int DeletedTotalDrec(DataView dv, string strTableName, string strColumnName, string Value, SqlTransaction SqlTra, SqlConnection Con)
{
DataTable dtDrec = new DataTable();
dtDrec = (DataTable)dv.Table;
int i = 0;
if (dtDrec.Rows.Count > 0)
{
ExecuteProcedures one = new ExecuteProcedures(3, MasterCommonStrings.ConnectionString);
one.Parameters.Add("#TableName", SqlDbType.VarChar, 8000, strTableName);
one.Parameters.Add("#ColumnName", SqlDbType.VarChar, 8000, strColumnName);
one.Parameters.Add("#ColumnValue", SqlDbType.VarChar, 8000, Value);
int b = Convert.ToInt32(one.InvokeProcedure("Proc_Erp_Trn_Deleted_Transction_Total_Drec", SqlTra, ValueDataType.Number, Con));
for (int j = 0; j < dtDrec.Rows.Count; j++)
{
ExecuteProcedures EX = new ExecuteProcedures(19, MasterCommonStrings.ConnectionString);
EX.Parameters.Add("#TableName", SqlDbType.VarChar, 8000, strTableName);
EX.Parameters.Add("#FirstColumnName", SqlDbType.VarChar, 8000, dtDrec.Columns[0].ColumnName.ToString());
EX.Parameters.Add("#SecondColumnName", SqlDbType.VarChar, 8000, dtDrec.Columns[1].ColumnName.ToString());
EX.Parameters.Add("#ThiredColumnName", SqlDbType.VarChar, 8000, dtDrec.Columns[2].ColumnName.ToString());
EX.Parameters.Add("#FourColumnName", SqlDbType.VarChar, 8000, dtDrec.Columns[3].ColumnName.ToString());
EX.Parameters.Add("#FiveColumnName", SqlDbType.VarChar, 8000, dtDrec.Columns[4].ColumnName.ToString());
EX.Parameters.Add("#SixtColumnName", SqlDbType.VarChar, 8000, dtDrec.Columns[5].ColumnName.ToString());
EX.Parameters.Add("#SevenColumnName", SqlDbType.VarChar, 8000, dtDrec.Columns[6].ColumnName.ToString());
EX.Parameters.Add("#EightColumnName ", SqlDbType.VarChar, 8000, dtDrec.Columns[7].ColumnName.ToString());
EX.Parameters.Add("#NineColumnName", SqlDbType.VarChar, 8000, strColumnName);
EX.Parameters.Add("#FirstColumnNameValue ", SqlDbType.VarChar, 8000, dtDrec.Rows[j][0].ToString());
EX.Parameters.Add("#SecondColumnNameValue", SqlDbType.VarChar, 8000, dtDrec.Rows[j][1].ToString());
EX.Parameters.Add("#ThiredColumnNameValue", SqlDbType.VarChar, 8000, dtDrec.Rows[j][2].ToString());
EX.Parameters.Add("#FourColumnNameValue ", SqlDbType.VarChar, 8000, dtDrec.Rows[j][3].ToString());
EX.Parameters.Add("#FiveColumnNameValue", SqlDbType.VarChar, 8000, dtDrec.Rows[j][4].ToString());
EX.Parameters.Add("#SixtColumnNameValue", SqlDbType.VarChar, 8000, dtDrec.Rows[j][5].ToString());
EX.Parameters.Add("#SevenColumnNameValue", SqlDbType.VarChar, 8000, dtDrec.Rows[j][6].ToString());
EX.Parameters.Add("#EightColumnNameValue", SqlDbType.VarChar, 8000, dtDrec.Rows[j][7].ToString());
EX.Parameters.Add("#NineColumnNameValue ", SqlDbType.VarChar, 8000, Value);
i = Convert.ToInt32(EX.InvokeProcedure("proc_erp_Trn_Insert_into_Total_Drec", SqlTra, ValueDataType.Number, Con));
}
}
return i;
}
public static bool CheckRows(Manage_Drec Description)
{
if (Description.InTable.Rows.Count > 0)
{
return true;
}else
{
return false;
}
}
#endregion
# region "Procedures"
public static void SetRadiobutton(string strStatus, RadioButton Rbyes, RadioButton rbNo)
{
if (strStatus == "Yes")
{
Rbyes.Checked = true;
}
else
{
Rbyes.Checked = false;
}
if (strStatus == "No")
{
rbNo.Checked = true;
}
else
{
rbNo.Checked = false;
}
}
public static void Set_CheckBox(bool Status, CheckBox ChkName)
{
if (Status == true)
{
ChkName.Checked = true;
}
else
{
ChkName.Checked = false;
}
}
public static void DoSomeFileWritingStuff(string message)
{
//Debug.WriteLine("Writing to file...");
try
{
using (StreamWriter writer = new StreamWriter(LOG_FILE, true))
{
if (message == "")
{
writer.WriteLine("Cache Callback: {0}", DateTime.Now);
}
else
{
writer.WriteLine(message);
}
writer.Close();
}
AspSendEmail smail = new AspSendEmail();
//smail.strHost = mail.intrawebsolns.com
smail.SendEmail("support#intrawebsolns.com", "amit4692#gmail.com", "Exception Error", message, "Error ERP");
}
catch (Exception x)
{
//Debug.WriteLine(x);
DoSomeFileWritingStuff(x.Message);
}
//Debug.WriteLine("File write successful");
}
public static void SetRights(string Rights, Panel pnl)
{
foreach (Control ctrl in pnl.Controls)
{
if (ctrl.GetType().Name == "Button")
{
if ((((Button)ctrl).ID == "btnAdd" && Rights.IndexOf("A") > -1) || (((Button)ctrl).ID == "btnEdit" && Rights.IndexOf("E") > -1)
|| (((Button)ctrl).ID == "btnDelete" && Rights.IndexOf("D") > -1))
{
ctrl.Visible = true;
}
if ((((Button)ctrl).ID == "btnAdd" && Rights.IndexOf("S") > -1) || (((Button)ctrl).ID == "btnEdit" && Rights.IndexOf("S") > -1)
|| (((Button)ctrl).ID == "btnDelete" && Rights.IndexOf("S") > -1))
{
ctrl.Visible = true;
}
}
}
}
#endregion
public static void Enable_Btn_For_Add(Button btnAdd, Button btnCancel, Button btnDelete, Button btnEdit, Button btnUpdate, Button btnexit, Button btnfind)
{
btnEdit.Enabled = false;
btnAdd.Enabled = false;
btnfind.Enabled = false;
btnUpdate.Enabled = true;
btnCancel.Enabled = true;
btnDelete.Enabled = false;
btnexit.Enabled = true;
}
public static bool Check_Entry_exists(string tableName, string columnName, string columnValue)
{
bool result=false;
try
{
ExecuteProcedures ex = new ExecuteProcedures(4, AccountCommonStrings.ConnectionString);
ex.Parameters.Add("#tableName", SqlDbType.VarChar, 100, tableName);
ex.Parameters.Add("#columnName", SqlDbType.VarChar, 100, columnName);
ex.Parameters.Add("#columnValue", SqlDbType.VarChar, 100, #columnValue);
ex.Parameters.Add("#isbitdeleted", SqlDbType.Int, 0);
string temp =Convert.ToString( ex.InvokeProcedure("proc_check_Delete_entry", ValueDataType.String));
if (temp == "false")
{
result = false;
}
else
{
result = true;
}
}
catch (Exception)
{
}
return result;
}
public static bool Check_Entry_exists(string tableName, string columnName, string columnValue,string isbitdeleted)
{
bool result = false;
try
{
ExecuteProcedures ex = new ExecuteProcedures(4, AccountCommonStrings.ConnectionString);
ex.Parameters.Add("#tableName", SqlDbType.VarChar, 100, tableName);
ex.Parameters.Add("#columnName", SqlDbType.VarChar, 100, columnName);
ex.Parameters.Add("#columnValue", SqlDbType.VarChar, 100, #columnValue);
ex.Parameters.Add("#isbitdeleted", SqlDbType.Int, isbitdeleted);
string temp = Convert.ToString(ex.InvokeProcedure("proc_check_Delete_entry", ValueDataType.String));
if (temp == "false")
{
result = false;
}
else
{
result = true;
}
}
catch (Exception)
{
}
return result;
}
}