|
Of course it does, when you paste it onto a brand new page it is the only item in the new list so naturally it becomes 1. You just can’t argue with MS logic which knows how you should be doing things.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
When the sixteenth President is alone in a room he doesn't become the first President.
|
|
|
|
|
Now you are just talking sense!
But, according to MS logic, he would be President #1!
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
Ah, but he is the first president in the room since he last checked..
Come on Microsoft, can't you see I have the right stuff to be CEO? Just mail me!
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
Wouldn't that be weird to be pasted in as item #4 when it's the only item in a list?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
We have two functions apiCall and handleChangeEvent . The simplified version below.
function apiCall() {
}
function handleChangeEvent(newData,oldData) {
if(newData !== oldData)
{
apiCall();
}
}
One of my colleagues reports they have a problem with apiCall not being called from handleChangeEvent because of the if condition. They claim that the event is sometimes handled and sometimes not. Suspicious claim, as the apiCall code can be triggered from other locations, but it's an issue they should be able to handle so I didn't investigate further.
Later the cheery colleague says they solved the issue and I decided to review their code. I take a look at their work from time to time to help improve their code and this is the solution they came up with:
function handleChangeEvent(newData,oldData) {
newData = !oldData;
if(newData !== oldData)
{
apiCall();
}
}
I told them that this is not the way to solve the issue, and took the time to show them that that apiCall was in fact called from another location. I also gave them a few solutions that could be made and left to take a break. I hope to help guide them, but I fear that there is no helping them . I'm still puzzled and angry that someone would write such a solution!?
|
|
|
|
|
what about handling null values for new and old data parameters? this has bitten me in the ass before.
|
|
|
|
|
pretty soon all the data in the database will be =false
|
|
|
|
|
The code is sufficient in this case not to check for null . The parameters passed are from an event, and the function is called when the field it is bound to changes. Additionally the apiCall function doesn't change anything, but the overhead of making a request to the api should be avoided, hence it's wrapped in an if statement.
|
|
|
|
|
It looks fine syntax wise however you should add what the solution is meant to do. If this is dealing with a database or with some form of data than parameters should be put there. Someone did say Null values and that can come with some downsides. With handling data some limitations should be added. However as I said I have no idea what data the function is trying to deal with. All I know is that it handles two objects. One newData and Two oldData. I know that if newData and oldData are the same than it will be false and in that instance the API would be called. Could you go in depth a little bit further or what type of data you are dealing with.
|
|
|
|
|
The actual data passed is a timestamp when a change has happened. The handleChangeEvent function is an event handler bound to a field, like an input field onchange event in the browser. The framework takes care of when to call this function, and then the control takes responsibility of what needs to happen.
The point of my semi-rant being that the dev in question tried to fix a problem by doing the wrong thing in the wrong place
|
|
|
|
|
Why does the object even support a logical not operator and what is it supposed to do to the object?
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
It doesn't support it . The actual code created a new string with Date.now().toString() , which would make the subsequent if check fail every time.
|
|
|
|
|
As a matter of curiosity what language is that in? I've never seen that construct !== before
|
|
|
|
|
Probably javascript.
1 == "1" will be true in JavaScript because == casts objects to a common type.
However 1 === "1" is false since one is int and the other is string. === does not cast objects.
!== will be not equal to without casting of objects. If you're sure both sides of the operand are of the same type then using === or !== will be faster.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
I was thinking the same thing ,because you can automatically rule out Vb.net due to structure.
You can rule out C# due to operator types involved. There are some serious violations with C#,C++,C,Objective C and Java. I felt confused by the extended/longer operator types.
Good call on it being javascript!
|
|
|
|
|
Indeed it is javascript
|
|
|
|
|
|
That's eight layers of confusion!
My blog[ ^]
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}
|
|
|
|
|
Now the most fascinating part is, that OP answered the question - twice...
I'm only regret, that this gem will vanish soon...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: I'm only regret, that this gem will vanish soon... That can be easily fixed
EDIT: Not that easily I guess... Copy/paste messes up the HTML a bit... Well, it's a pretty good impression anyway
Someone in QA wrote: ----Add.aspx-----
<%@ Page Title="" Language="C#" MasterPageFile="~/main.Master" AutoEventWireup="true" CodeBehind="Add.aspx.cs" Inherits="indianRailway.Add" %>
<asp:content id="Content1" contentplaceholderid="head" runat="server">
.auto-style1 {
text-align: left;
}
.auto-style3 {
font-size: xx-small;
}
.auto-style4 {
text-align: left;
}
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server">
EMPLOYEE DETAILS
Train No.
<asp:textbox skinid="abc" id="TextBoxTrainNo" runat="server" textmode="Number">
<asp:requiredfieldvalidator cssclass="popout" display="Dynamic" enableclientscript="false" id="RequiredFieldValidator1" runat="server" errormessage="Please specify" forecolor="Red" controltovalidate="TextBoxTrainNo">
Train Name
<asp:textbox skinid="abc" id="TextBoxTrainName" runat="server">
<asp:requiredfieldvalidator cssclass="validat" display="Dynamic" enableclientscript="false" id="RequiredFieldValidator2" runat="server" controltovalidate="TextBoxTrainName" errormessage="Please Specify" forecolor="Red">
Source Station
<asp:textbox skinid="abc" id="TextBoxSourceStation" runat="server">
<asp:requiredfieldvalidator cssclass="validat" display="Dynamic" enableclientscript="false" id="RequiredFieldValidator3" runat="server" controltovalidate="TextBoxSourceStation" errormessage="Please Specify" forecolor="Red">
Destination Station
<asp:textbox id="TextBoxDest" runat="server">
<asp:requiredfieldvalidator id="RequiredFieldValidator8" runat="server" controltovalidate="TextBoxDest" display="Dynamic" enableclientscript="False" errormessage="please specify" forecolor="Red">
Departure Time
<asp:textbox id="TextBoxDepart" skinid="abc" runat="server" textmode="Time">
<asp:requiredfieldvalidator cssclass="validat" display="Dynamic" enableclientscript="false" id="RequiredFieldValidator4" runat="server" controltovalidate="TextBoxDepart" errormessage="Please Specify" forecolor="Red">
Arrival Time
<asp:textbox skinid="abc" id="TextBoxArrival" runat="server" textmode="Time">
<asp:requiredfieldvalidator cssclass="validat" display="Dynamic" enableclientscript="false" id="RequiredFieldValidator5" runat="server" controltovalidate="TextBoxArrival" errormessage="Please Specify" forecolor="Red">
Available Days
(write days & use comma for seperation)
<asp:textbox id="TextBoxAvlbledays" runat="server">
<asp:requiredfieldvalidator cssclass="validat" display="Dynamic" enableclientscript="false" id="RequiredFieldValidator7" runat="server" controltovalidate="TextBoxAvlbledays" errormessage="Please Select" forecolor="Red" initialvalue="--Select--">
<asp:button text="Submit" id="Submit" runat="server" onclick="Submit_Click">
----Add.aspx.cs----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using BllFactory;
using BO;
using BoFactory;
using Types;
namespace indianRailway
{
public partial class Add : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["MySession"] == null)
{
((Button)Master.FindControl("Button1")).Visible = false;
((Label)Master.FindControl("Label1")).Visible = false;
string message = "Oops! for this you have to login...";
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('" + message + "'); window.location='" + Request.ApplicationPath + "MainLogin.aspx';", true);
}
else
{
((Button)Master.FindControl("Button1")).Visible = true;
((Label)Master.FindControl("Label1")).Visible = true;
((Label)Master.FindControl("Label1")).Text = "welcome : " + Convert.ToString(Session["MySession"]);
}
}
protected void Submit_Click(object sender, EventArgs e)
{
if (IsValid)
{
IboAdmin BoObj = BoFactory.BoFactoryAdmin.CreateInstanceOfBo();
BoObj.trainNo = Convert.ToInt64(TextBoxTrainNo.Text);
BoObj.trainName = TextBoxTrainName.Text;
BoObj.sourceStation = TextBoxSourceStation.Text;
BoObj.destinationStation = TextBoxDest.Text;
BoObj.departureTime = TextBoxDepart.Text;
BoObj.availableDyas = TextBoxAvlbledays.Text;
BoObj.arrivalTime = TextBoxArrival.Text;
IbllAdmin BllObj = BllFactory.BllFactoryAdmin.CreateInstanceOfBll();
long IdCatcher = BllObj.AddOfBll(BoObj);
if (IdCatcher == 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('Details not saved... Please try again with Complete & correct details '); window.location='" + Request.ApplicationPath + "Add.aspx';", true);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('Your details saved sucessfully, Please note your detail ID:" + IdCatcher + "'); window.location='" + Request.ApplicationPath + "Add.aspx';", true);
}
}
}
}
}
----main.Master----
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="main.master.cs" Inherits="indianRailway.main" %>
<title>
<asp:contentplaceholder id="head" runat="server">
.auto-style1 {
font-size: xx-large;
}
.auto-style2 {
font-size: small;
}
yourconvenience.com
<asp:label id="Label1" runat="server" font-size="Small" text="Label" visible="False">
<asp:button id="Button1" runat="server" font-size="Small" onclick="Button1_Click" text="Sign Out" visible="False">
Manage Everything Easily
<asp:menu id="Menu1" runat="server" backcolor="#333399" borderstyle="None" font-bold="True" font-italic="True" font-underline="False" forecolor="White" orientation="Horizontal" width="1350px">
<asp:menuitem text="Home" value="Home">
<asp:menuitem text="About Us" value="About Us">
<asp:menuitem text="Contact Us" value="Contact Us">
<asp:menuitem navigateurl="~/Add.aspx" text="Add New" value="Add New">
<asp:menuitem navigateurl="~/Manage.aspx" text="Manage Earlier " value="Manage Earlier ">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
copyrights reserved
----main.Master.cs----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace indianRailway
{
public partial class main : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session.RemoveAll();
Response.Redirect("MainLogin.aspx");
}
}
}
----MainLogin.aspx----
<%@ Page Title="" Language="C#" MasterPageFile="~/main.Master" AutoEventWireup="true" CodeBehind="MainLogin.aspx.cs" Inherits="indianRailway.MainLogin" %>
<asp:content id="Content1" contentplaceholderid="head" runat="server">
.table {
height:300px;
width:400px;
margin-top:20px;
}
td {
font-size:large;
background-color:wheat;
}
.button {
height:30px;
width:150px;
color:whitesmoke;
background-color:blue;
font-size:25px;
}
.button:hover {
color:whitesmoke;
background-color:green;
}
.textbox {
height:30px;
width:150px;
font-size:27px;
}
.auto-style18 {
width: 100%;
}
.auto-style19 {
font-size: x-large;
}
.auto-style20 {
height: 530px;
width: 667px;
}
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server">
Simply login to enjoy our services...
Login
Username:
<asp:textbox id="TextBox1" runat="server">
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" controltovalidate="TextBox1" enableclientscript="False" errormessage="please enter correct username" display="Dynamic" font-size="Small" forecolor="Red">
Password:
<asp:textbox id="TextBox2" runat="server" textmode="Password">
<asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server" controltovalidate="TextBox2" enableclientscript="False" errormessage="please enter correct password" display="Dynamic" font-size="Small" forecolor="Red">
<asp:button id="Button1" runat="server" text="login" width="85px" onclick="Button1_Click1">
-------MainLogin.aspx.cs---------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BO;
using BoFactory;
using BLL;
using BllFactory;
using Types;
namespace indianRailway
{
public partial class MainLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session.RemoveAll();
}
protected void Button1_Click1(object sender, EventArgs e)
{
if (IsValid)
{
IbllLogin BllObj = BllFactory.BllFactoryLogin.CreateInstanceOfBll();
IboLogin BoObj = BoFactory.BoFactoryLogin.CreateInstanceOfBo();
BoObj.name = TextBox1.Text.ToString();
BoObj.password = TextBox2.Text;
int i = BllObj.LoginCheckBll(BoObj);
if (i == 1)
{
Session["MySession"] = TextBox1.Text.ToString();
Response.Redirect("Add.aspx");
}
else
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('Incorrect username or password...Please try again'); window.location='" + Request.ApplicationPath + "MainLogin.aspx';", true);
}
else
{
TextBox1.Style.Add("border", "solid 1px red");
TextBox2.Style.Add("border", "solid 1px red");
}
}
}
}
----Manage.aspx----
<%@ Page Title="" Language="C#" MasterPageFile="~/main.Master" AutoEventWireup="true" CodeBehind="Manage.aspx.cs" Inherits="indianRailway.Manage" %>
<asp:content id="Content1" contentplaceholderid="head" runat="server">
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server">
<asp:panel height="490px" width="1200px" scrollbars="Horizontal" runat="server">
<asp:gridview id="GridView1" pagesize="15" horizontalalign="Center" verticalalign="Center" allowpaging="true" runat="server" autogeneratecolumns="False" cellpadding="4" forecolor="#333333" gridlines="None" onpageindexchanging="GridView1_PageIndexChanging" onrowcancelingedit="GridView1_RowCancelingEdit" onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating">
<asp:templatefield headertext="edit/delete">
<asp:linkbutton id="LinkButton3" commandname="Update" runat="server">Update
<asp:linkbutton id="LinkButton4" commandname="Cancel" runat="server">Cancel
<asp:linkbutton id="LinkButton1" commandname="Edit" runat="server">Edit
<asp:linkbutton id="LinkButton2" commandname="Delete" runat="server" onclientclick="return confirm('Are you sure you want to delete this?');">Delete
<asp:templatefield headertext="trainId" insertvisible="False" sortexpression="trainId">
<asp:label id="Label1" runat="server" text="<%# Eval("trainId") %>">
<asp:label id="Label11" runat="server" text="<%# Eval("trainId") %>">
<asp:templatefield headertext="trainNo" insertvisible="False" sortexpression="trainNo">
<asp:textbox id="TextBoxTrnO" runat="server" text="<%# Eval("trainNo") %>">
<asp:label id="Label111" runat="server" text="<%# Eval("trainNo") %>">
<asp:templatefield headertext="trainName" sortexpression="trainName">
<asp:textbox id="TextBoxTRnM" runat="server" text="<%# Eval("trainName") %>">
<asp:label id="Label2" runat="server" text="<%# Eval("trainName") %>">
<asp:templatefield headertext="sourceStation" sortexpression="sourceStation">
<asp:textbox id="TextBoxSorcStatn" runat="server" text="<%# Eval("sourceStation") %>">
<asp:label id="Label3" runat="server" text="<%# Eval("sourceStation") %>">
<asp:templatefield headertext="destinationStation" sortexpression="destinationStation">
<asp:textbox id="TextBoxDestStatn" runat="server" text="<%# Eval("destinationStation") %>">
<asp:label id="Label4" runat="server" text="<%# Eval("destinationStation") %>">
<asp:templatefield headertext="departureTime" sortexpression="departureTime">
<asp:textbox id="TextBoxDeprtTm" runat="server" text="<%# Eval("departureTime") %>">
<asp:label id="Label5" runat="server" text="<%# Eval("departureTime") %>">
<asp:templatefield headertext="availableDyas" sortexpression="availableDyas">
<asp:textbox id="TextBoxAvailbledays" runat="server" text="<%# Eval("availableDyas") %>">
<asp:label id="Label6" runat="server" text="<%# Eval("availableDyas") %>">
<asp:templatefield headertext="arrivalTime" sortexpression="arrivalTime">
<asp:textbox id="TextBoxArrvlTime" runat="server" text="<%# Eval("arrivalTime") %>">
<asp:label id="Label7" runat="server" text="<%# Eval("arrivalTime") %>">
<%--<asp:templatefield headertext="amount" sortexpression="amount">
<asp:textbox id="TextBoxAmt" runat="server" text="<%# Eval("amount") %>">
<asp:label id="Label8" runat="server" text="<%# Eval("amount") %>">
<asp:templatefield headertext="PreConditions" sortexpression="PreConditions">
<asp:textbox id="TextBoxPreconds" runat="server" text="<%# Eval("PreConditions") %>">
<asp:label id="Label9" runat="server" text="<%# Eval("PreConditions") %>">
<asp:templatefield headertext="PostConditions" sortexpression="PostConditions">
<asp:textbox id="TextBoxPostConds" runat="server" text="<%# Eval("PostConditions") %>">
<asp:label id="Label10" runat="server" text="<%# Eval("PostConditions") %>">
<asp:templatefield headertext="Remarks" sortexpression="Remarks">
<asp:textbox id="TextBoxRemarks" runat="server" text="<%# Eval("Remarks") %>">
<asp:label id="Label12" runat="server" text="<%# Eval("Remarks") %>">
--%>
<headerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White">
<selectedrowstyle backcolor="#E2DED6" font-bold="True" forecolor="#333333">
----Manage.aspx.cs----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BO;
using BoFactory;
using BLL;
using BllFactory;
using Types;
namespace indianRailway
{
public partial class Manage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["MySession"] == null)
{
((Button)Master.FindControl("Button1")).Visible = false;
((Label)Master.FindControl("Label1")).Visible = false;
string message = "Oops! for this you have to login...";
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('" + message + "'); window.location='" + Request.ApplicationPath + "MainLogin.aspx';", true);
}
else
{
((Button)Master.FindControl("Button1")).Visible = true;
((Label)Master.FindControl("Label1")).Visible = true;
((Label)Master.FindControl("Label1")).Text = "welcome : " + Convert.ToString(Session["MySession"]);
}
if (!IsPostBack)
{
Bindgriddata();
}
}
public void Bindgriddata()
{
IbllAdmin BllObj = BllFactory.BllFactoryAdmin.CreateInstanceOfBll();
GridView1.DataSource = BllObj.ViewGridOfBll();
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Bindgriddata();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
Bindgriddata();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow gvr = GridView1.Rows[e.RowIndex];
int id = Convert.ToInt32(((Label)gvr.FindControl("Label11")).Text);
IbllAdmin BllObj = BllFactory.BllFactoryAdmin.CreateInstanceOfBll();
int deleteCheck = BllObj.DeleteGridOfBll(id);
if (deleteCheck == 1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),
"alertkey", "alert('Record deleted sucessfully...');", false);
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(),
"alertkey", "alert('Record not deleted');", false);
}
GridView1.EditIndex = -1;
Bindgriddata();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
Bindgriddata();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
IboAdmin BoObj = BoFactory.BoFactoryAdmin.CreateInstanceOfBo();
GridViewRow gvr = GridView1.Rows[e.RowIndex];
BoObj.trainId = Convert.ToInt64(((Label)gvr.FindControl("Label1")).Text);
BoObj.trainNo = Convert.ToInt64(((TextBox)gvr.FindControl("TextBoxTrnO")).Text);
BoObj.trainName = (((TextBox)gvr.FindControl("TextBoxTRnM")).Text);
BoObj.sourceStation = ((TextBox)gvr.FindControl("TextBoxSorcStatn")).Text;
BoObj.destinationStation = ((TextBox)gvr.FindControl("TextBoxDestStatn")).Text;
BoObj.departureTime = (((TextBox)gvr.FindControl("TextBoxDeprtTm")).Text);
BoObj.arrivalTime = (((TextBox)gvr.FindControl("TextBoxArrvlTime")).Text);
BoObj.availableDyas = (((TextBox)gvr.FindControl("TextBoxAvailbledays")).Text);
IbllAdmin objbll = BllFactory.BllFactoryAdmin.CreateInstanceOfBll();
int CheckUpdate = objbll.UpdateGridOfBll(BoObj);
if (CheckUpdate == 1)
Page.ClientScript.RegisterStartupScript(this.GetType(),
"alertkey", "alert('Details have been updated sucessfully');", false);
else
Page.ClientScript.RegisterStartupScript(this.GetType(),
"alertkey", "alert('Please try again with complete & correct details');", false);
GridView1.EditIndex = -1;
Bindgriddata();
}
}
}
----TypesAdmin.cs----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Types
{
public interface IboAdmin
{
long trainNo { get; set; }
string trainName { get; set; }
string sourceStation { get; set; }
string destinationStation { get; set; }
string departureTime { get; set; }
string arrivalTime { get;set;}
string availableDyas { get; set; }
long trainId { get; set; }
}
public interface IbllAdmin
{
long AddOfBll(IboAdmin BoObj);
List ViewGridOfBll();
int UpdateGridOfBll(IboAdmin BoObj);
int DeleteGridOfBll(int x);
}
public interface IdalAdmin
{
long AddOfDal(IboAdmin BoObj);
List ViewGridOfDal();
bool UpdateGridOfDal(IboAdmin BoObj);
bool DeleteGridOfDal(int Id);
}
}
-----TypesLogin.cs----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Types
{
public interface IboLogin
{
string name { get; set; }
string password { get; set; }
}
public interface IbllLogin
{
int LoginCheckBll(IboLogin BoObj);
}
public interface IdalLogin
{
bool LoginCheckDal(IboLogin BoObj);
}
}
----BoAdmin.cs----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
namespace BO
{
public class BoAdmin : IboAdmin
{
public long trainNo { get; set; }
public string trainName { get; set; }
public string sourceStation { get; set; }
public string destinationStation { get; set; }
public string departureTime { get; set; }
public string arrivalTime { get; set; }
public string availableDyas { get; set; }
public long trainId { get; set; }
}
}
----BoLogin.cs----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
namespace BO
{
public class BoLogin:IboLogin
{
public string name { get; set; }
public string password { get; set; }
}
}
----BoFactoryAdmin.cs----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
using BO;
namespace BoFactory
{
public static class BoFactoryAdmin
{
public static IboAdmin CreateInstanceOfBo()
{
IboAdmin BoObj = new BoAdmin();
return BoObj;
}
}
}
----BoFactoryLogin.cs----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
using BO;
namespace BoFactory
{
public static class BoFactoryLogin
{
public static IboLogin CreateInstanceOfBo()
{
IboLogin BoObj = new BoLogin();
return BoObj;
}
}
}
-----BllAdmin.cs-----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
using DAL;
using DalFactory;
using BO;
namespace BLL
{
public class BllAdmin: IbllAdmin
{
public long AddOfBll(IboAdmin BoObj)
{
long IdCatcher;
IdalAdmin DalObj = DalFactory.DalFactoryAdmin.CreateInstanceOfDal();
IdCatcher = DalObj.AddOfDal(BoObj);
if (IdCatcher != 0)
return IdCatcher;
else
return 0;
}
public List ViewGridOfBll()
{
IdalAdmin DalObj = DalFactory.DalFactoryAdmin.CreateInstanceOfDal();
List list = new List();
list = DalObj.ViewGridOfDal();
return list;
}
public int UpdateGridOfBll(IboAdmin BoObj)
{
bool value;
IdalAdmin DalObj = DalFactory.DalFactoryAdmin.CreateInstanceOfDal();
value = DalObj.UpdateGridOfDal(BoObj);
if (value)
return 1;
else
return 0;
}
public int DeleteGridOfBll(int x)
{
bool value;
IdalAdmin DalObj = DalFactory.DalFactoryAdmin.CreateInstanceOfDal();
value = DalObj.DeleteGridOfDal(x);
if (value)
return 1;
else
return 0;
}
}
}
-----BllLogin.cs-----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
namespace BLL
{
public class BllLogin : IbllLogin
{
public int LoginCheckBll(IboLogin BoObj)
{
IdalLogin DalObj = DalFactory.DalFactroyLogin.CreateInstanceOfDal();
bool value;
value = DalObj.LoginCheckDal(BoObj);
if (value)
return 1;
else
return 0;
}
}
}
-----BllFactoryAdmin.cs-----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BLL;
using Types;
namespace BllFactory
{
public static class BllFactoryAdmin
{
public static IbllAdmin CreateInstanceOfBll()
{
IbllAdmin BllObj = new BllAdmin();
return BllObj;
}
}
}
-------BllFactoryLogin.cs-----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BLL;
using Types;
namespace BllFactory
{
public static class BllFactoryLogin
{
public static IbllLogin CreateInstanceOfBll()
{
IbllLogin BllObj = new BllLogin();
return BllObj;
}
}
}
----------DalAdmin.cs-------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using BoFactory;
namespace DAL
{
public class DalAdmin :IdalAdmin
{
SqlConnection MyConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconnection"].ConnectionString);
public long AddOfDal(IboAdmin BoObj)
{
SqlCommand MyCommand = new SqlCommand();
MyConnection.Open();
MyCommand.Connection = MyConnection;
MyCommand.CommandText = "USP_INSERT_id";
MyCommand.CommandType = CommandType.StoredProcedure;
MyCommand.Parameters.AddWithValue("@trainNo", BoObj.trainNo);
MyCommand.Parameters.AddWithValue("@trainName ", BoObj.trainName);
MyCommand.Parameters.AddWithValue("@sourceStation", BoObj.sourceStation);
MyCommand.Parameters.AddWithValue("@destinationStation", BoObj.destinationStation);
MyCommand.Parameters.AddWithValue("@departureTime", BoObj.departureTime);
MyCommand.Parameters.AddWithValue("@arrivalTime", BoObj.arrivalTime);
MyCommand.Parameters.AddWithValue("@availableDays", BoObj.availableDyas);
MyCommand.Parameters.Add("@trainId", SqlDbType.Int).Value = BoObj.trainId;
MyCommand.Parameters["@trainId"].Direction = ParameterDirection.Output;
long IdCatcher = 0;
try
{
MyCommand.ExecuteNonQuery();
IdCatcher = long.Parse(MyCommand.Parameters["@trainId"].Value.ToString());
BoObj.trainId = IdCatcher;
}
catch (Exception e)
{
throw e;
}
finally
{
MyConnection.Close();
}
if (IdCatcher > 0)
return IdCatcher;
else
return 0;
}
public List ViewGridOfDal()
{
SqlCommand MyCommand = new SqlCommand();
MyCommand.Connection = MyConnection;
MyConnection.Open();
MyCommand.CommandText = "USP_VIEW_id";
MyCommand.CommandType = CommandType.StoredProcedure;
List list1 = new List();
SqlDataReader reader = MyCommand.ExecuteReader();
while (reader.Read())
{
IboAdmin BoObj = BoFactory.BoFactoryAdmin.CreateInstanceOfBo();
BoObj.trainId = Convert.ToInt32(reader["trainId"]);
BoObj.trainName = reader["trainName"].ToString();
BoObj.sourceStation = reader["sourceStation"].ToString();
BoObj.destinationStation= reader["destinationStation"].ToString();
BoObj.departureTime = (reader["departureTime"]).ToString();
BoObj.arrivalTime = (reader["arrivalTime"]).ToString();
BoObj.availableDyas = reader["availableDays"].ToString();
BoObj.trainNo = Convert.ToInt32( reader["trainNo"]);
list1.Add(BoObj);
}
MyConnection.Close();
return list1;
}
public bool UpdateGridOfDal(IboAdmin BoObj)
{
SqlCommand MyCommand = new SqlCommand();
MyCommand.Connection = MyConnection;
MyConnection.Open();
MyCommand.CommandText = "USP_UPDATE_id";
MyCommand.CommandType = CommandType.StoredProcedure;
MyCommand.Parameters.AddWithValue("@trainNo", BoObj.trainNo);
MyCommand.Parameters.AddWithValue("@trainName ", BoObj.trainName);
MyCommand.Parameters.AddWithValue("@sourceStation", BoObj.sourceStation);
MyCommand.Parameters.AddWithValue("@destinationStation", BoObj.destinationStation);
MyCommand.Parameters.AddWithValue("@departureTime", BoObj.departureTime);
MyCommand.Parameters.AddWithValue("@arrivalTime", BoObj.arrivalTime);
MyCommand.Parameters.AddWithValue("@availableDays", BoObj.availableDyas);
MyCommand.Parameters.AddWithValue("@trainId", BoObj.trainId);
MyCommand.ExecuteNonQuery();
MyConnection.Close();
return true;
}
public bool DeleteGridOfDal(int Id)
{
SqlCommand MyCommand = new SqlCommand();
MyCommand.Connection = MyConnection;
MyConnection.Open();
MyCommand.CommandText = "USP_DELETE_id";
MyCommand.CommandType = CommandType.StoredProcedure;
MyCommand.Parameters.AddWithValue("@trainId", Id);
MyCommand.ExecuteNonQuery();
MyConnection.Close();
return true;
}
}
}
---------DalLogin.cs-------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using BoFactory;
namespace DAL
{
public class DalLogin :IdalLogin
{
public bool LoginCheckDal(IboLogin BoObj)
{
SqlConnection MyConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconnection"].ConnectionString);
SqlCommand MyCommand = new SqlCommand();
MyCommand.Connection = MyConnection;
MyConnection.Open();
MyCommand.CommandText = "USP_LOGIN_CHECK_id";
MyCommand.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = MyCommand.ExecuteReader();
int flag = 0;
while (reader.Read())
{
if ((BoObj.name == Convert.ToString(reader["name"])) && (BoObj.password == Convert.ToString(reader["password"])))
{
flag = 1;
break;
}
else
{
flag = 0;
}
}
MyConnection.Close();
if (flag == 1)
return true;
else
return false;
}
}
}
---------DalFactoryAdmin.cs-----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
using DAL;
namespace DalFactory
{
public static class DalFactoryAdmin
{
public static IdalAdmin CreateInstanceOfDal()
{
IdalAdmin DalObj = new DalAdmin();
return DalObj;
}
}
}
------DalFactoryLogin.cs------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Types;
using DAL;
namespace DalFactory
{
public static class DalFactroyLogin
{
public static IdalLogin CreateInstanceOfDal()
{
IdalLogin objdal = new DalLogin();
return objdal;
}
}
}
------Sqls----------
use anythingsaa
drop table trainDetails_id
create table trainDetails_id
(
trainId int identity(10000,1),
trainNo bigint,
trainName varchar(30),
sourceStation varchar(40),
destinationStation varchar(40),
departureTime varchar(28) ,
arrivalTime varchar(28) ,
availableDays varchar(200)
)
select * from
create procedure USP_INSERT_id
(
@trainId int out,
@trainNo bigint,
@trainName varchar(30),
@sourceStation varchar(40),
@destinationStation varchar(40),
@departureTime varchar(28) ,
@arrivalTime varchar(28) ,
@availableDays varchar(200)
)
as
begin
insert into trainDetails_id values (@trainNo,@trainName,@sourceStation,@destinationStation,@departureTime,@arrivalTime,@availableDays)
set @trainId=@@IDENTITY
end
create procedure USP_VIEW_id
as
begin
select * from trainDetails_id
end
execute USP_VIEW_id
create procedure USP_UPDATE_id
(
@trainId int,
@trainNo bigint,
@trainName varchar(30),
@sourceStation varchar(40),
@destinationStation varchar(40),
@departureTime varchar(28) ,
@arrivalTime varchar(28),
@availableDays varchar(200)
)
as
begin
update trainDetails_id set
trainNo=@trainNo,
trainName=@trainName,
sourceStation=@sourceStation,
destinationStation =@destinationStation,
departureTime=@departureTime,
arrivalTime=@arrivalTime,
availableDays=@availableDays
where trainId=@trainId
end
Create procedure USP_DELETE_id
(
@trainId int
)
as
begin
delete from trainDetails_id
where trainId=@trainId
end
--Admin--
create table Admin_id
(
name varchar(40),
password varchar(50)
)
select * from Admin_id
insert into Admin_id values ('ggf','hfgh')
insert into Admin_id values ('dssdd','dffd')
--create procedure usp_check
--@name varchar(40) ,
--@password int
--as
--begin
--select name,password
--from Admin1
--where name=@name and password=@password
--end
create procedure USP_LOGIN_CHECK_id
as
begin
select * from Admin_id
end
insert into Admin_id values ('df','dfdfd')
My blog[ ^]
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: Now the most fascinating part is, that OP answered the question - twice...
There was a question somewhere????
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
Oh, I didn't see this before taking a chainsaw to the fracking thing.
And he's reposted it a couple of times as well. I have a suspicion that he wants to be able to show that he has answered a question on CP either for a class or for a job interview.
modified 21-Dec-14 23:29pm.
|
|
|
|
|
Should just have replied "No".
PooperPig - Coming Soon
|
|
|
|
|