|
Yes, that would have been a route. But it isn't one I needed for this application.
What I didn't say is this is entirely an in house set of applications. Used to run this business. We have acquired another business and they too will run the applications - but against a different database, on the same server.
Writing something to pass the database name in to the class would have required hours of writing to change all times this class is instantiated.
Because it is in house I have hither to simply changed the CN string in the class before compiling everything to switch from test to production databases. The system is running, and being developed and new things are added - that is constant.
|
|
|
|
|
Presuming the application is a desktop solution, hopefully using click once deployment.
Your DAL should be included in each application project either as a DLL or a referenced project (I usually referenced the project to make debugging easier). EVERY database interaction should go through the DAL using the connection string supplied by the config file. You should only need to change the CN once for each deployment type (production/UAT/development) and this can be automated using compile directives.
A D Rosser wrote: Writing something to pass the database name in to the class would have required hours of writing to change all times this class is instantiated. This makes me think each table class interacts directly with the database, a thoroughly nasty situation. Changing to use a DAL does not have to be a singular task, all new operations should use the DAL and put a junior on changing the existing classes.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Good day programmers. I have an existing application that is already working online (.Nwt Core). Now on another application (.Net Core), I want to export all the images in passport folder in the first application to an excel file the import it to my new project
|
|
|
|
|
Hello po.
Ito po yung current code ko. Please help po.
TIA
Dim dt As New DataTable()
dt.Columns.Add("Name")
dt.Columns.Add("Count")
Dim manpower1 As Integer
Dim present1 As Integer
For Each row As DataGridViewRow In manpower.Rows
dt.Rows.Add(row.Cells(1).Value)
Next
For Each row1 As DataGridViewRow In present.Rows
present1 = (row1.Cells(1).Value)
dt.Rows.Add(manpower1 - present1)
Next
For Each row2 As DataGridViewRow In manpower.Rows
dt.Rows.Add(manpower1 - present1)
Next
absent.DataSource = dt
|
|
|
|
|
You are adding 3 sets of rows to your datatable instead of just 1. Try something like:
For Int row = manpower.RowCount
manpower1 = manpower.Rows(row).Columns(1).Value
present1 = present.Rows(row).Columns(1).Value
dt.Rows.Add(manpower1 - present1)
Next
absent.DataSource = dt
|
|
|
|
|
I have method which was working fine with PDFs has started giving errors, I checked in TFS - I didn't find any changes in that part of the method, I am getting the error: System.IO.InvalidDataException: 'End of Central Directory record could not be found.', but the PDF is valid and other clients told me it has started throwing errors for the pdfs previously were working. Here is the code:
try
{
using (MemoryStream ms = new MemoryStream(fileData))
{
List<string> dangerous_files = new List<string>();
string msgModel = "ZIP: {zip} - ({file})";
using (ZipArchive archive = new ZipArchive(ms))
{
foreach (var entity in archive.Entries)
{
if (denyExtensions.Contains(entity.FullName.Split('.').LastOrDefault().ToLower()))
{
dangerous_files.Add(msgModel.Replace("{zip}", GetRidOfSlash(file.FileName)).Replace("{file}", entity.FullName));
}
}
if (dangerous_files.Count > 0)
{
Response.TrySkipIisCustomErrors = true; Response.StatusCode = 500;
return Json(new
{
error = errMsg,
code = "500.1",
files = dangerous_files
});
}
}
}
}
catch (Exception ex)
{
LogHandler.LogError(4203, "Zip file creation failed Upload - Picture", ex);
throw ex;
}
The place where I am getting the errors is at the following line:
using (ZipArchive archive = new ZipArchive(ms))
Any help would be very very helpful - thanks in advance.
|
|
|
|
|
|
simpledeveloper wrote: I have method which was working fine with PDFs Are you sure? As far as I know PDF files are not in zip archive format.
|
|
|
|
|
which one is use tuple or out varaible . which is best?
|
|
|
|
|
|
If one were "best", there's no reason to keep it around in the framework. You can also use tuples as out variables, which makes your question unclear to me. Can you give us two examples of what you are trying to compare?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I have a SharpGL.openGLControl control installed on a MDI ChildWindow in WinForms. Although the ChildWindow's border is sizable, it cannot be resized using the mouse as the mouse does not "catch" on the ChildWindow's border to extend them. If the SharpGL control is removed, then the ChildWindow's borders become sizable again.
Would anyone have a suggestion how to circumvent this ?
Thanks in advance for any suggestion.
|
|
|
|
|
Hi, I'm making a WinForms app with Entity Framework. I need the computers to connect to a same database so all have the same data. I think this could be achieved with connecting them via Ethernet cables and writing the server, database, user and password, so the connection string updates to the given server.
I don't know how could I achieve this. Could you please help me?
|
|
|
|
|
The server does not broadcast its connection-string; it would make breaking into it too easy.
User and password are not required if your security up to date. If on the same network, all users can share data stored there.
As for help, the answer is "no". There's enough tutorials on accessing databases out there, and if they too complex I don't wanna help anyway. If you get stuck and have a specific question, we'll gladly help.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Using VS VB .NET.
The RichTextBox control does not have a way to disable keyboard/mouse input at least not in any practical way. Is there an RTB viewer control out there or enhanced RTB that can support this?
I have just discovered some of the enhanced RTB controls on this site which I will need to check out.
thx 
|
|
|
|
|
Member 14694895 wrote: The RichTextBox control does not have a way to disable keyboard/mouse input at least not in any practical way. So the "enabled" property does not work for you or what?
Member 14694895 wrote: Is there an RTB viewer control out there You can make your own by simply displaying the results of a RTB without allowing editing. Have you considered converting the RTB to HTML and simply displaying it in a WebBrowser?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
UWP has a "rich text BLOCK" (besides a rich text BOX). UWP controls can now be hosted in at least WPF.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
It turns out setting ReadOnly to True does the trick. I want to be able to view it and use the scroll bars so setting to Enabled False is no good. That grays out the box and disabled the scrollbars. I want to stay away from HTML for now. Thanks for reply's.
|
|
|
|
|
Hi,
I have 3 tables in the back end - I am trying to load them using include statement of Entity Framework TableA is parent of TableB which is parent of TableC
(from a in TableA select a).Include("TableB").Include("TableB.TableC")
Now I want to get List<tablec> using a Linq, how can I do it? I am trying in the below way - its giving me compile error - any help please? Thanks in advance.
List<TableC> cs = (from a in tablea.TableBs select a.TableCs.ToList());
Any help in achieving this, that how can I get the List of TableCs in one list using linq queries
|
|
|
|
|
If you want a list of TableC s, then start with the TableC s. Use the navigation properties to include the parent and grandparent entities if required.
List<TableC> cs = tablea.TablesCs.Include(c => c.TableB.TableA).ToList();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes I did that - thank you for your suggestion 
|
|
|
|
|
I am using Entity Framework Code First - I am getting the following message in deleting any of the tables data - like CaseNov, ViolationsNov and ViolationTypeNov are three tables which are to handle many to many relationships between Case-Nov, Violation-Nov and ViolationType-Nov, I am getting error messages even if I trying to delete the detailed tables like: CaseNov, ViolationsNov, ViolationTypeNov or row directly from NOV table, I am getting the similar type of message - any help please? I am using Entity Framework Code First for deleting it.
The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key
property is set to a null value. If the foreign-key does not support null values, a new relationship
must be defined, the foreign-key property must be assigned another non-null value or the unrelated
object must be deleted.
Here is the code for deleting records any help please:
public bool Delete(NOV nov, bool performCommit = true)
{
System.Data.Entity.DbContextTransaction dbOperation = null;
if (performCommit)
dbOperation = UnitOfWork.BeginTransaction();
try
{
List<ViolationTypeNOV> novRels = UnitOfWork.ViolationTypeNOVRepository
.GetAll().Where(x => x.NOVId == nov.NOVId).ToList();
foreach (ViolationTypeNOV o in novRels)
{
nov.ViolationTypeNOVs.Remove(o);
this.UnitOfWork.ViolationTypeNOVRepository.Delete(o.ViolationTypeNOVId);
}
novRels.RemoveAll(x => x.NOVId == nov.NOVId);
List<ViolationNOV> violationNOVs = UnitOfWork.ViolationNOVRepository
.GetAll().Where(x => x.NOVId == nov.NOVId).ToList();
foreach (ViolationNOV o in violationNOVs)
{
nov.ViolationNOVs.Remove(o);
this.UnitOfWork.ViolationNOVRepository.Delete(o.ViolationNOVId);
}
violationNOVs.RemoveAll(x => x.NOVId == nov.NOVId);
List<CaseNOV> caseNOVs = UnitOfWork.CaseNOVRepository
.GetAll().Where(x => x.NOVId == nov.NOVId).ToList();
foreach (CaseNOV o in caseNOVs)
{
nov.CaseNOVs.Remove(o);
this.UnitOfWork.CaseNOVRepository.Delete(o.CaseNOVId);
}
caseNOVs.RemoveAll(x => x.NOVId == nov.NOVId);
UnitOfWork.NOVRepository.Delete(nov.NOVId);
if (dbOperation != null)
dbOperation.Commit();
LogHandler.LogInfo(2521, "Deleted NOV " + nov.NOVNumber);
return true;
}
catch (Exception ex)
{
LogHandler.LogError(2523, "Commit Fail in NOV Delete", ex);
if (dbOperation != null)
dbOperation.Rollback();
throw ex;
}
}
modified 6-Dec-19 12:54pm.
|
|
|
|
|
If you used "cascading deletes" you wouldn't have to worry so much about the details.
Cascade Delete - EF Core | Microsoft Docs
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
 I have set the cascade delete to true - here is my migration filecode for that
public override void Up()
{
DropForeignKey("dbo.Violations", "NOVId", "dbo.NOVs");
DropIndex("dbo.Violations", new[] { "NOVId" });
CreateTable(
"dbo.ViolationTypeNOVs",
c => new
{
ViolationTypeNOVId = c.Int(nullable: false, identity: true),
NOVId = c.Int(nullable: false),
ViolationTypeId = c.Int(nullable: false),
})
.PrimaryKey(t => t.ViolationTypeNOVId)
.ForeignKey("dbo.NOVs", t => t.NOVId, cascadeDelete: true)
.ForeignKey("dbo.ViolationTypes", t => t.ViolationTypeId, cascadeDelete: true)
.Index(t => new { t.NOVId, t.ViolationTypeId }, unique: true, name: "IX_UniqueConstraintViolationTypeNOV");
CreateTable(
"dbo.CaseNOVs",
c => new
{
CaseNOVId = c.Int(nullable: false, identity: true),
NOVId = c.Int(nullable: false),
CaseId = c.Int(nullable: false),
})
.PrimaryKey(t => t.CaseNOVId)
.ForeignKey("dbo.Cases", t => t.CaseId, cascadeDelete: true)
.ForeignKey("dbo.NOVs", t => t.NOVId, cascadeDelete: true)
.Index(t => new { t.NOVId, t.CaseId }, unique: true, name: "IX_UniqueConstraintCaseNov");
CreateTable(
"dbo.ViolationNOVs",
c => new
{
ViolationNOVId = c.Int(nullable: false, identity: true),
NOVId = c.Int(nullable: false),
ViolationId = c.Int(nullable: false),
})
.PrimaryKey(t => t.ViolationNOVId)
.ForeignKey("dbo.NOVs", t => t.NOVId, cascadeDelete: true)
.ForeignKey("dbo.Violations", t => t.ViolationId, cascadeDelete: true)
.Index(t => new { t.NOVId, t.ViolationId }, unique: true, name: "IX_UniqueConstraintNOVViolation");
AlterColumn("dbo.OneToManies", "ParentEntity", c => c.String());
AlterColumn("dbo.OneToManies", "ChildEntity", c => c.String());
}
Still why is it not deleting it? Any help please? One more information I am able to delete the records from SSMS though - so it must be something to do with Entity Framework Code First only though.
Unit of Work Code:
public DataAccessUnitOfWork UnitOfWork { get; set; }
public RoleManager<ApplicationRole> RoleManager { get; set; }
public UserManager<ApplicationUser> UserManager { get; set; }
public ApplicationUser CurrentUser { get; set; }
public DomainLogicManager(DataAccessUnitOfWork unitOfWork)
{
this.UnitOfWork = unitOfWork;
this.RoleManager = new RoleManager<ApplicationRole>(new RoleStore<ApplicationRole>(UnitOfWork.Context));
this.UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(UnitOfWork.Context));
}
Delete method in one of the repository classes is as follows:
public bool Delete(IdT id)
{
T item = this.DbSet.Find(id);
var entry = this.Context.Entry(item);
entry.State = EntityState.Deleted;
this.DbSet.Attach(item);
this.DbSet.Remove(item);
this.Context.SaveChanges();
BuildMetaData(item, false, false);
return true;
}
Any help please - thank you.
modified 6-Dec-19 14:34pm.
|
|
|
|
|
Gerry Schmitz wrote: If you used "cascading deletes" you wouldn't have to worry so much about the details.
Yes I did but still I am going to through this issue - is there anyway I can find which foreign key constraint its failing at or its complaining about. Its just giving me a general statement - its not helpful for me right - if I know column name or foreign key constraint name - then it would be useful - thank you buddy.
|
|
|
|
|