public static DataTable GetDataTable(string table, string selectClause, string whereClause, string orderByClause) { Log log = new Log(); log.Write("in GetDataTable()"); //String CompanyId = Dynamics.Globals.IntercompanyId.Value.ToString(); ServerConnection Connection = AppConnection.GetGPConnection(); try { string qs = selectClause + " FROM " + table; if (whereClause != "") { qs = qs + " WHERE " + whereClause; } if (orderByClause != "") { qs = qs + " ORDER BY " + orderByClause; } log.Write("GetDataTable():" + qs); Query q = new Query("GetDataTable " + table, qs, dtDataTable, Connection, false); q.Execute(); return(q.dataTableResult); } catch (Exception ex) { logerror("GetDataTable", ex, true); return(null); } }
private bool IsDemoMode() { var appConnection = new AppConnection(); var isDemoModeObj = appConnection.SystemUserConnection.ApplicationData["IsDemoMode"]; return((isDemoModeObj == null) ? true : Convert.ToBoolean(isDemoModeObj)); }
private void SearchButton_Click(object sender, EventArgs e) { if (SearchTextBox.Text != string.Empty) //is the textbox is not empty { using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Students_SearchByStudentName", con)) { cmd.CommandType = CommandType.StoredProcedure; //Passing Parameter cmd.Parameters.AddWithValue("@Filter", SearchTextBox.Text.Trim()); if (con.State != ConnectionState.Open) { con.Open(); } DataTable dtStudent = new DataTable(); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.HasRows) { dtStudent.Load(sdr); StudentDataGridView.DataSource = dtStudent; } else { MessageBox.Show("No Matching Student is found.", "No record", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } }
private void RolesForm_Load(object sender, EventArgs e) { if (this.IsUpdate == true) { using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Roles_ReloadDataForUpdate", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RoleId", RoleId); if (con.State != ConnectionState.Open) { con.Open(); } DataTable dtRole = new DataTable(); SqlDataReader sdr = cmd.ExecuteReader(); dtRole.Load(sdr); DataRow row = dtRole.Rows[0]; TitleTextBox.Text = row["RoleTitle"].ToString(); DescriptionTextBox.Text = row["Description"].ToString(); // Change Controls SaveButton.Text = "Update Role Information"; DeleteButton.Enabled = true; } } } }
private bool IsPasswordVerified() { bool isCorrect = false; using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Users_VerifyPassword", con)) //specify stored procedure { cmd.CommandType = CommandType.StoredProcedure; //declare a command for Stored Procedure cmd.Parameters.AddWithValue("@UserName", LoggedInUser.UserName); cmd.Parameters.AddWithValue("@Password", SecureData.EncryptData(OldPasswordTextBox.Text.Trim())); if (con.State != ConnectionState.Open) //check if connection with database is established { con.Open(); } SqlDataReader sdr = cmd.ExecuteReader(); //read data from database if (sdr.HasRows) { isCorrect = true; } } } return(isCorrect); }
private void DeleteButton_Click(object sender, EventArgs e) { if (this.IsUpdate) { DialogResult result = MessageBox.Show("Are you sure want to delete this Role?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { //Delete record from database using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Roles_DeleteByRoleId", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RoleId", this.RoleId); if (con.State != ConnectionState.Open) { con.Open(); } cmd.ExecuteNonQuery(); MessageBox.Show("Role is successfully deleted from the system.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormControl(); } } } } }
private void DeleteButton_Click(object sender, EventArgs e) { if (this.IsUpdate == true) { DialogResult result = MessageBox.Show("Are you sure, you want to delete this User?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { //Delete user from database using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Student_DeleteStudentById", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@StudentId", this.StudentId); if (con.State != ConnectionState.Open) { con.Open(); } cmd.ExecuteNonQuery(); MessageBox.Show("Student is successfully deleted from the system.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormControl(); } } } else { MessageBox.Show("You cancelled this process", "Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void LoadDataIntoRolesComboBox() { //copy this code from LoadDataIntoDataGridView() in ViewRolesForm.cs using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //fetch data from SQL Server { using (SqlCommand cmd = new SqlCommand("usp_Roles_LoadDataIntoComboBox", con)) //specify stored procedure { cmd.CommandType = CommandType.StoredProcedure; //setting commandtype as a Stored Procedure if (con.State != ConnectionState.Open) //check if connection with database is not established { con.Open(); //make connection to database } DataTable dtRoles = new DataTable(); //create a new DataTable instance that stores the data SqlDataReader sdr = cmd.ExecuteReader(); //read data from database dtRoles.Load(sdr); //load data into dtRoles datatable RolesComboBox.DataSource = dtRoles; //embed data from dtRoles DataTable to RolesComboBox forms object for display RolesComboBox.DisplayMember = "RoleTitle"; //specify what will be displayed in the combobox RolesComboBox.ValueMember = "RoleId"; //assign a value to each item in the combobox } } }
public IAppConnection AcceptConnection( ITransportConnection connection, AppConnectionDescriptor info) { var clientConnection = new AppConnection(connection, info); lock (_connections) { if (_connections.ContainsKey(clientConnection.Id)) { throw new InvalidOperationException($"Connection id already exists: {clientConnection.Id}"); } _connections[clientConnection.Id] = clientConnection; var appInstanceId = clientConnection.Info.ApplicationInstanceId; if (!_appInstanceConnections.TryGetValue(appInstanceId, out var connectionList)) { connectionList = new List <IAppConnection>(); _appInstanceConnections[appInstanceId] = connectionList; } connectionList.Add(clientConnection); clientConnection.Completion .ContinueWithSynchronously((Action <Task, object>)OnClientConnectionCompleted, clientConnection) .IgnoreAwait(Log); if (_connectionWaiters.TryGetValue(appInstanceId, out var waiter)) { waiter.TryComplete(clientConnection); } _connectionWaiters.Remove(info.ApplicationInstanceId); } return(clientConnection); }
public async Task AppConnect(AppConnection connection) { TcpClient client = new TcpClient(); try { Log.Debug("Attempting connect"); await client.ConnectAsync(Host, Port); } catch (Exception e) { Log.Error(e, "Error while connecting to TCP socket"); await connection.Refuse(); } await connection.Accept(); ConnectedPipe pipe = new ConnectedPipe(client, connection); _ = Task.Run(async() => { await pipe.Run(); client.Close(); }); }
private void RegisterReportGenerationCompletionSender(AppConnection appConnection) { var reminderSender = new ReportGenerationCompletionReminderSender(appConnection); var notificationSender = new ReportGenerationCompletionNotificationSender(); notificationSender.SetSuccessor(reminderSender); ClassFactory.Bind <ReportGenerationCompletionSender>(() => notificationSender); }
public AppLog(bool useSql, string logPath = @"C:\Temp\Sinex.log") : base() { includeTime = true; appVersion = AppVersion(); if (useSql) { type = 1; connection = AppConnection.GetLogConnection(); } else { type = 0; Path = logPath; } }
} //allows IsUpdate to be accessed as a global variable private void StudentForm_Load(object sender, EventArgs e) { //For Update Process if (this.IsUpdate == true) { using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Students_ReloadDataForUpdate", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@StudentId", this.StudentId); if (con.State != ConnectionState.Open) { con.Open(); } DataTable dtStudent = new DataTable(); SqlDataReader sdr = cmd.ExecuteReader(); dtStudent.Load(sdr); DataRow row = dtStudent.Rows[0]; StudentNameTextBox.Text = row["StudentName"].ToString(); AgeTextBox.Text = row["Age"].ToString(); GenderTextBox.Text = row["Gender"].ToString(); DescriptionTextBox.Text = row["Description"].ToString(); var pic = row.Field <byte[]>("Image"); if (pic != null) { MemoryStream ms = new MemoryStream(pic); IdPictureBox.Image = Image.FromStream(ms); } // Change Controls SaveButton.Text = "Update Student Information"; DeleteButton.Enabled = true; } } } }
public async Task TcpListen() { Random rand = new Random(); TcpListener listener = new TcpListener(IPAddress.Loopback, Port); listener.Start(); try { while (true) { var apps = await EntryP.DiscoverApps(AppName); if (apps.Length < 1) { Log.Error("No suitable app found on entry point"); break; } var app = apps[rand.Next(0, apps.Length - 1)]; var s = await listener.AcceptTcpClientAsync(); var appConn = new AppConnection(app, EntryP); _ = Task.Run(async() => { try { await appConn.Connect(); ConnectedPipe pipe = new ConnectedPipe(s, appConn); _ = pipe.Run(); } catch (Exception e) { Log.Error(e, "Error while handling"); s.Dispose(); } }); } } catch (Exception e) { Log.Error(e, "Error while accepting"); } Environment.Exit(-1); }
private void LoginButton_Click(object sender, EventArgs e) { if (IsFormValid()) { using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Users_VerifyLoginDetails", con)) //specify stored procedure { cmd.CommandType = CommandType.StoredProcedure; //declare a command for Stored Procedure cmd.Parameters.AddWithValue("@UserName", UserNameTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Password", SecureData.EncryptData(PasswordTextBox.Text.Trim())); if (con.State != ConnectionState.Open) //check if connection with database is established { con.Open(); } DataTable dtUser = new DataTable(); //create a new DataTable that stores the data SqlDataReader sdr = cmd.ExecuteReader(); //read data from database if (sdr.HasRows) { dtUser.Load(sdr); DataRow userRow = dtUser.Rows[0]; //get data from user role database LoggedInUser.UserName = userRow["UserName"].ToString(); //store UserName to LoggeddInUser class LoggedInUser.RoleId = Convert.ToInt32(userRow["RoleId"]); //store RoleId to LoggedInUser class this.Hide(); DashboardForm dashboardForm = new DashboardForm(); //create a new instance of DashboardForm object dashboardForm.ShowDialog(); } else { MessageBox.Show("User Name or Password is incorrect.", "Authentication Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void UserForm_Load(object sender, EventArgs e) { LoadDataIntoRolesComboBox(); //For Update Process if (this.IsUpdate == true) { using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Users_ReloadDataForUpdate", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", this.UserName); if (con.State != ConnectionState.Open) { con.Open(); } DataTable dtUser = new DataTable(); SqlDataReader sdr = cmd.ExecuteReader(); dtUser.Load(sdr); DataRow row = dtUser.Rows[0]; UserNameTextBox.Text = row["UserName"].ToString(); RolesComboBox.SelectedValue = row["RoleId"]; IsActiveCheckBox.Checked = Convert.ToBoolean(row["IsActive"]); DescriptionTextBox.Text = row["Description"].ToString(); // Change Controls SaveButton.Text = "Update User Information"; DeleteButton.Enabled = true; } } } }
public void LoadDataIntoDataGridView() { using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("usp_Students_LoadDataIntoDataGridView ", con)) //specify stored procedure { cmd.CommandType = CommandType.StoredProcedure; //declare a command for Stored Procedure if (con.State != ConnectionState.Open) //check if connection with database is established { con.Open(); } DataTable dtStudents = new DataTable(); //create a new DataTable that stores the data SqlDataReader sdr = cmd.ExecuteReader(); //read data from database dtStudents.Load(sdr); //load data into dtRoles datatable StudentDataGridView.DataSource = dtStudents; //embed data in dtRoles in RolesDataGridView forms object for display //StudentDataGridView.Columns[0].Visible = false; //will be used for future lessons } } }
private void ChangePasswordButton_Click(object sender, EventArgs e) { if (IsFormValid()) { //Verify Existing Password if (IsPasswordVerified()) { // Go and Update Password using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //connect to database using AppConnection class and GetConnectionString method { using (SqlCommand cmd = new SqlCommand("usp_Users_ChangePassword", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", LoggedInUser.UserName); cmd.Parameters.AddWithValue("@NewPassword", SecureData.EncryptData(NewPasswordTextBox.Text.Trim())); cmd.Parameters.AddWithValue("@CreatedBy", LoggedInUser.UserName); if (con.State != ConnectionState.Open) { con.Open(); } cmd.ExecuteNonQuery(); MessageBox.Show("Password is successfully changed.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormControl(); } } } else { MessageBox.Show("Your old password is not correct, please enter correct password.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void SaveButton_Click(object sender, EventArgs e) { if (IsFormValid()) { if (this.IsUpdate == true) { //Do Update Process using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //connect to database using AppConnection class and GetConnectionString method { using (SqlCommand cmd = new SqlCommand("usp_Users_UpdateUserByUserName", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@OldUserName", this.UserName); cmd.Parameters.AddWithValue("@UserName", UserNameTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Password", SecureData.EncryptData(PasswordTextBox.Text.Trim())); cmd.Parameters.AddWithValue("@RoleId", RolesComboBox.SelectedValue); cmd.Parameters.AddWithValue("@IsActive", IsActiveCheckBox.Checked); cmd.Parameters.AddWithValue("@Description", DescriptionTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@CreatedBy", LoggedInUser.UserName); if (con.State != ConnectionState.Open) { con.Open(); } cmd.ExecuteNonQuery(); MessageBox.Show("User is successfully updated in the database.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormControl(); } } } else { //Do Insert Operation using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //connect to database using AppConnection class and GetConnectionString method { using (SqlCommand cmd = new SqlCommand("usp_Users_InsertNewUser", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", UserNameTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Password", SecureData.EncryptData(PasswordTextBox.Text.Trim())); cmd.Parameters.AddWithValue("@RoleId", RolesComboBox.SelectedValue); cmd.Parameters.AddWithValue("@IsActive", IsActiveCheckBox.Checked); cmd.Parameters.AddWithValue("@Description", DescriptionTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@CreatedBy", LoggedInUser.UserName); if (con.State != ConnectionState.Open) { con.Open(); } cmd.ExecuteNonQuery(); MessageBox.Show("User is successfully saved in the database.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormControl(); } } } } }
protected void btnBPK_OnClick(object sender, EventArgs e) { try { LoadData(); //int id = Convert.ToInt32(btn.CommandArgument); ASPxButton btn = sender as ASPxButton; GridViewDataItemTemplateContainer container = btn.NamingContainer as GridViewDataItemTemplateContainer; var Rowindex = container.VisibleIndex; //int id = int.Parse(grid.GetRowValues(Rowindex, "FINNumber").ToString()); string Id = grid.GetRowValues(Rowindex, "Id").ToString(); if (Id != null) { string user = ((User)Session["user"]).UserName; //Update data date and user already confirm string query = @"UPDATE VPCStorage SET BPK = GETDATE(), BPKBy ='" + user + "' WHERE Id=" + Id; using (SqlConnection conn = AppConnection.GetConnection()) { if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = query; cmd.CommandTimeout = 7000; cmd.CommandType = CommandType.Text; cmd.Connection = conn; cmd.ExecuteNonQuery(); } } // SAP DataTable dt = GetOrderNoVPCStorage(Id.ToInt32(0)); //DataTable GrInfo if (dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; //dtBPK = Convert.ToDateTime(dr["BPK"]); string tOrderNo = dr["OrderNo"].ToString(); DataTable GrInfoDt = new DataTable(); using (var con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["AppDb"].ConnectionString)) using (var cmd = new SqlCommand("usp_GetGRInfoToSAPbyProdOrder", con)) using (var da = new SqlDataAdapter(cmd)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@OrderNo", tOrderNo)); da.Fill(GrInfoDt); } if (dr["BuyOutDate"] != DBNull.Value) { string tSAPMessage = ""; string tSAPMessageGR = ""; Ebiz.SAP.UserUtil SendToSAP = new Ebiz.SAP.UserUtil(); bool resultFromSAP = SendToSAP.ConfirmOrderPKW(SAPConfiguration.SAP_CONFIG_NAME, tOrderNo, "TIDS", "0010", out tSAPMessage); System.Threading.Thread.Sleep(2000); DataTable resultFromSAPGR = SendToSAP.GoodReceiptAutomatically(SAPConfiguration.SAP_CONFIG_NAME, tOrderNo, out tSAPMessageGR); if (resultFromSAP == true && string.IsNullOrEmpty(tSAPMessageGR)) { SendToSAP.UpdateVDC(SAPConfiguration.SAP_CONFIG_NAME, tOrderNo, GrInfoDt); ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Check SAP Order Number data successfully');", true); } else { if (!string.IsNullOrEmpty(tSAPMessageGR)) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Error: " + tSAPMessageGR + "');", true); } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Check SAP Order Number:" + tSAPMessage + "');", true); } } } //string tSAPMessage = ""; //string tSAPMessageGR = ""; //Ebiz.SAP.UserUtil SendToSAP = new Ebiz.SAP.UserUtil(); //bool resultFromSAP = SendToSAP.ConfirmOrderPKW(SAPConfiguration.SAP_CONFIG_NAME, tOrderNo, "TIDS", "0010", out tSAPMessage); //if (resultFromSAP == true) //{ // //Update data date and user already confirm // string query = @"UPDATE VPCStorage SET BPK = GETDATE() WHERE Id=" + Id; // using (SqlConnection conn = AppConnection.GetConnection()) // { // if (conn.State == ConnectionState.Closed) conn.Open(); // using (SqlCommand cmd = new SqlCommand()) // { // cmd.CommandText = query; // cmd.CommandTimeout = 7000; // cmd.CommandType = CommandType.Text; // cmd.Connection = conn; // cmd.ExecuteNonQuery(); // } // } // string user = ((User)Session["user"]).UserName; // SqlDataSource1.UpdateCommand = "UPDATE VPCStorage SET BPKBy ='" + user + "' WHERE Id =" + Id; // SqlDataSource1.Update(); // if (dr["BuyOutDate"] == DBNull.Value) // { // ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Confirm BPK is successful');", true); // } // else // { // System.Threading.Thread.Sleep(2000); // DataTable resultFromSAPGR = SendToSAP.GoodReceiptAutomatically(SAPConfiguration.SAP_CONFIG_NAME, tOrderNo, out tSAPMessageGR); // if (string.IsNullOrEmpty(tSAPMessageGR)) // { // SendToSAP.UpdateVDC(SAPConfiguration.SAP_CONFIG_NAME, tOrderNo, GrInfoDt); // //Update data date and user already confirm // query = @"UPDATE VPCStorage SET GRDATE = GETDATE() WHERE Id=" + Id; // using (SqlConnection conn = AppConnection.GetConnection()) // { // if (conn.State == ConnectionState.Closed) conn.Open(); // using (SqlCommand cmd = new SqlCommand()) // { // cmd.CommandText = query; // cmd.CommandTimeout = 7000; // cmd.CommandType = CommandType.Text; // cmd.Connection = conn; // cmd.ExecuteNonQuery(); // } // } // ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Confirm BPK and SAP GR is successful');", true); // } // else // { // if (!string.IsNullOrEmpty(tSAPMessageGR)) // ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Error: " + tSAPMessageGR + "');", true); // else // ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('SAP GR failed:" + tSAPMessage + "');", true); // } // } //if (dr["BuyOutDate"] != DBNull.Value) //} //else //{ // ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Confirm BPK failed:" + tSAPMessage + "');", true); //} } //Response.Redirect(Request.RawUrl); LoadData(); } } catch (Exception ex) { AppLogger.LogError(ex); } }
/// <summary> /// Setups instance of <see cref="EmailMiningAppListener"/> with custom user connection. /// </summary> /// <param name="userConnection">User connection.</param> public EmailMiningAppListener(UserConnection userConnection) { UserConnection = userConnection; AppConnection = userConnection.AppConnection; }
/// <summary> /// Creates inctance of <see cref="CaseRatingManagementService"> type. /// </summary> /// <param name="userConnection">UserConnection.</param> /// <param name="appConnection">AppConnection.</param> public CaseRatingManagementService(UserConnection userConnection, AppConnection appConnection) : this(userConnection) { _appConnection = appConnection; _sysUserName = AppConnection.SystemUserConnection.CurrentUser.Name; SecurityTokenUtilities = new SecurityTokenUtilities(userConnection); }
public EmailEventsProcessor(AppConnection appConnection, IHttpContextAccessor accessor) : base(appConnection, accessor) { }
public ConsultaQueryHandler(AppConnection appConnection) { _appConnection = appConnection; }
private void SaveButton_Click(object sender, EventArgs e) { if (IsFormValid()) { if (this.IsUpdate == true) { //Do Update Process using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //connect to database using AppConnection class and GetConnectionString method { using (SqlCommand cmd = new SqlCommand("usp_Students_UpdateStudentByStudentId", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@StudentId", this.StudentId); cmd.Parameters.AddWithValue("@StudentName", StudentNameTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Age", AgeTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Gender", GenderTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Description", DescriptionTextBox.Text.Trim()); var image = IdPictureBox.Image; using (var ms = new MemoryStream()) { if (image != null) { image.Save(ms, image.RawFormat); cmd.Parameters.AddWithValue("@Image", SqlDbType.VarBinary).Value = ms.ToArray(); } else { cmd.Parameters.Add("@Image", SqlDbType.VarBinary).Value = DBNull.Value; //save null to database } } cmd.Parameters.AddWithValue("@CreatedBy", LoggedInUser.UserName); if (con.State != ConnectionState.Open) { con.Open(); } cmd.ExecuteNonQuery(); MessageBox.Show("Student is successfully updated in the database.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormControl(); } } } else { //Do Insert Process using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //connect to database using AppConnection class and GetConnectionString method { using (SqlCommand cmd = new SqlCommand("usp_Students_InsertNewStudent", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@StudentName", StudentNameTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Age", AgeTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Gender", GenderTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Description", DescriptionTextBox.Text.Trim()); var image = IdPictureBox.Image; using (var ms = new MemoryStream()) { if (image != null) { image.Save(ms, image.RawFormat); cmd.Parameters.AddWithValue("@Image", SqlDbType.VarBinary).Value = ms.ToArray(); } else { cmd.Parameters.Add("@Image", SqlDbType.VarBinary).Value = DBNull.Value; //save null to database } } cmd.Parameters.AddWithValue("@CreatedBy", LoggedInUser.UserName); if (con.State != ConnectionState.Open) { con.Open(); } cmd.ExecuteNonQuery(); MessageBox.Show("Student is successfully added in the database.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormControl(); } } } } }
private void button1_Click(object sender, EventArgs e) { MessageBox.Show(AppConnection.GetConnectionString()); }
public ExchangeEventsProcessor(AppConnection appConnection) : this(appConnection, HttpContext.HttpContextAccessor) { }
/// <summary> /// Initializes a new instance of the <see cref="ReportGenerationCompletionReminderSender"/> class with a specified application connection. /// </summary> /// <param name="appConnection">The application connection.</param> public ReportGenerationCompletionReminderSender(AppConnection appConnection) { _appConnection = appConnection; _remindingUtilities = ClassFactory.Get <RemindingUtilities>(); }
public ConnectedPipe(TcpClient stream1, AppConnection stream2) { Stream1 = stream1; Stream2 = stream2; }
private void saveInformationToolStripMenuItem_Click(object sender, EventArgs e) { if (IsFormValid()) { if (this.IsUpdate) { DialogResult result = MessageBox.Show("Are you sure want to updated this Role?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { //Do Update Operation using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //connect to database using AppConnection class and GetConnectionString method { using (SqlCommand cmd = new SqlCommand("usp_Roles_UpdatedRoleByRoleId", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RoleId", this.RoleId); cmd.Parameters.AddWithValue("@RoleTitle", TitleTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Description", DescriptionTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@CreatedBy", LoggedInUser.UserName); if (con.State != ConnectionState.Open) { con.Open(); } cmd.ExecuteNonQuery(); MessageBox.Show("Role is successfully updated in the database.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormControl(); } } } } else { //Do Insert Operation using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //connect to database using AppConnection class and GetConnectionString method { using (SqlCommand cmd = new SqlCommand("usp_Roles_InsertNewRole", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RoleTitle", TitleTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@Description", DescriptionTextBox.Text.Trim()); cmd.Parameters.AddWithValue("@CreatedBy", LoggedInUser.UserName); if (con.State != ConnectionState.Open) { con.Open(); } cmd.ExecuteNonQuery(); MessageBox.Show("Role is successfully saved in the database.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormControl(); } } } } }