using BiskLog_Point_Of_Sale.Multiple_Login; using BiskLog_Point_Of_Sale.Properties; using Point_Of_Sale_Managment; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace BiskLog_Point_Of_Sale.Company_Setup { public partial class FinalBranch : Form { Holder holder; SqlConnection cn; SqlCommand cm, cm1; SqlDataReader dr; DatabaseConn conn = new DatabaseConn(); string branchidentity; public FinalBranch(Holder holding) { InitializeComponent(); holder = holding; cn = new SqlConnection(conn.MyConnection()); } private async void BtnNext_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtBranchName.Text) && !String.IsNullOrEmpty(txtBranchTelephone.Text) && !String.IsNullOrEmpty(txtBranchCity.Text)) { Task task = new Task(() => { try { cn.Open(); cm = new SqlCommand("Insert into tblBranches (branchID,branchName,address,city,state_or_province," + "branch_telephone) values (@branchID,@branchName,@address,@city,@state_or_province,@branch_telephone)", cn); txtBranchName.Invoke(new Action(() => { cm.Parameters.AddWithValue("@branchName", txtBranchName.Text); })); txtBranchAddress.Invoke(new Action(() => { cm.Parameters.AddWithValue("@address", txtBranchAddress.Text); })); txtBranchCity.Invoke(new Action(() => { cm.Parameters.AddWithValue("@city", txtBranchCity.Text); })); txtBranchState.Invoke(new Action(() => { cm.Parameters.AddWithValue("@state_or_province", txtBranchState.Text); })); txtBranchTelephone.Invoke(new Action(() => { cm.Parameters.AddWithValue("@branch_telephone", txtBranchTelephone.Text); })); cm.Parameters.AddWithValue("@branchID", branchID()); cm.ExecuteNonQuery(); cn.Close(); return 1; } catch { cn.Close(); return 2; } }); loading.Visible = true; btnNext.Enabled = false; btnPrev.Enabled = false; task.Start(); int result = await task; if (result == 1) { Settings.Default.BranchID = branchidentity; Settings.Default.BranchCity = txtBranchCity.Text; Settings.Default.BranchAddress = txtBranchAddress.Text; Settings.Default.BranchName = txtBranchName.Text; Settings.Default.BranchTelephone = txtBranchTelephone.Text; Settings.Default.Configured = true; Settings.Default.CompanyName = DatabaseLocation.company; Settings.Default.Save(); holder.moveToLogin(); } else { string title = "Error setting a new branch"; string message = "Sorry unable to set up a branch at this time, please try again later"; NoAction noAction = new NoAction(title, message); noAction.BringToFront(); noAction.ShowDialog(); loading.Visible = false; btnNext.Enabled = true; btnPrev.Enabled = true; } } else { a1.Visible = true; a2.Visible = true; a3.Visible = true; string title = "Essential fields empty"; string message = "Fields with asterisk have to be filled to continue"; NoAction noAction = new NoAction(title, message); noAction.BringToFront(); noAction.ShowDialog(); } } private void BtnPrev_Click(object sender, EventArgs e) { holder.moveToDBLocation(); } public string branchID() { cm1 = new SqlCommand("Select Count(branchID) from tblBranches", cn); dr = cm1.ExecuteReader(); dr.Read(); string branch_id = "BRID" + dr[0].ToString(); dr.Close(); branchidentity = branch_id; return branch_id; } } }