You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
7.7 KiB
177 lines
7.7 KiB
3 months ago
|
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 FinalStep : Form
|
||
|
{
|
||
|
Holder holder;
|
||
|
string Loc;
|
||
|
SqlConnection cn;
|
||
|
SqlCommand cm, cm1, cm2;
|
||
|
SqlDataReader dr;
|
||
|
DatabaseConn conn = new DatabaseConn();
|
||
|
SqlTransaction transaction;
|
||
|
string branchidentity = "";
|
||
|
public FinalStep(Holder hol, string previous)
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
cn = new SqlConnection(conn.MyConnection());
|
||
|
holder = hol;
|
||
|
Loc = previous;
|
||
|
}
|
||
|
|
||
|
private void Button2_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
if (Loc == "NewComp")
|
||
|
{
|
||
|
holder.moveToNewCompany();
|
||
|
}
|
||
|
else if (Loc == "Branch")
|
||
|
{
|
||
|
holder.moveToBranch(BranchSetup.forlo);
|
||
|
}
|
||
|
}
|
||
|
public string branchID()
|
||
|
{
|
||
|
cm2 = new SqlCommand("Select Count(branchID) from tblBranches", cn);
|
||
|
dr = cm2.ExecuteReader();
|
||
|
dr.Read();
|
||
|
string branch_id = "BRID" + dr[0].ToString();
|
||
|
dr.Close();
|
||
|
branchidentity = branch_id;
|
||
|
return branch_id;
|
||
|
}
|
||
|
private async void Button1_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
|
||
|
if (password.Text.Equals(passwordConfirmation.Text))
|
||
|
{
|
||
|
if (!String.IsNullOrEmpty(serverLocation.Text) && !String.IsNullOrEmpty(password.Text) && !String.IsNullOrEmpty(txtusername.Text))
|
||
|
{
|
||
|
Task<int> task = new Task<int>(() =>
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
serverLocation.Invoke(new Action(() =>
|
||
|
{
|
||
|
if (!String.IsNullOrEmpty(portNumber.Text))
|
||
|
{
|
||
|
Settings.Default["Connection"] = passwordEncryption.Encrypt("Data Source=" + serverLocation.Text + "," + portNumber.Text + ";Database=BISK_POS;User ID= " + txtusername.Text +
|
||
|
";Password=" + password.Text);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Settings.Default["Connection"] = passwordEncryption.Encrypt("Data Source=" + serverLocation.Text + ";Database=BISK_POS;User ID= " + txtusername.Text +
|
||
|
";Password=" + password.Text);
|
||
|
}
|
||
|
Settings.Default.Save();
|
||
|
cn = new SqlConnection(conn.MyConnection());
|
||
|
createEntity();
|
||
|
Settings.Default.BranchAddress = NewCompany.branch_address;
|
||
|
Settings.Default.BranchCity = NewCompany.branch_city;
|
||
|
Settings.Default.BranchID = branchidentity;
|
||
|
Settings.Default.BranchName = NewCompany.branchAlias;
|
||
|
Settings.Default.BranchTelephone = NewCompany.branch_telephone;
|
||
|
Settings.Default.Configured = true;
|
||
|
Settings.Default.CompanyName = NewCompany.company_name;
|
||
|
Settings.Default.vatNumber = NewCompany.company_vat;
|
||
|
Settings.Default.Save();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
cn.Close();
|
||
|
return 2;
|
||
|
}
|
||
|
|
||
|
});
|
||
|
holdup.Visible = true;
|
||
|
button1.Enabled = false;
|
||
|
button2.Enabled = false;
|
||
|
task.Start();
|
||
|
int result = await task;
|
||
|
if (result == 1)
|
||
|
{
|
||
|
Settings.Default.Configured = true;
|
||
|
holder.moveToLogin();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string title = "Unable to connect to server";
|
||
|
string message = "Sorry we are unable to connect to the company's database at this time, please verify the " +
|
||
|
"credentials provided are correct and try again !!";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
holdup.Visible = false;
|
||
|
button1.Enabled = true;
|
||
|
button2.Enabled = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
a1.Visible = true;
|
||
|
a2.Visible = true;
|
||
|
a3.Visible = true;
|
||
|
a4.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();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public void createEntity()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
cn.Open();
|
||
|
string id = branchID();
|
||
|
transaction = cn.BeginTransaction();
|
||
|
cm = new SqlCommand("Insert into tblCompanyDetails (company_name,address,website,email,tin,vatno,main_telephone) values (" +
|
||
|
"@company_name,@address,@website,@email,@tin,@vatno,@main_telephone)", cn);
|
||
|
cm.Parameters.AddWithValue("@company_name", NewCompany.company_name);
|
||
|
cm.Parameters.AddWithValue("@address", NewCompany.company_address);
|
||
|
cm.Parameters.AddWithValue("@website", NewCompany.company_website);
|
||
|
cm.Parameters.AddWithValue("@email", NewCompany.company_email);
|
||
|
cm.Parameters.AddWithValue("@tin", NewCompany.company_tin);
|
||
|
cm.Parameters.AddWithValue("@vatno", NewCompany.company_vat);
|
||
|
cm.Parameters.AddWithValue("@main_telephone", NewCompany.company_telephone);
|
||
|
cm.Transaction = transaction;
|
||
|
cm.ExecuteNonQuery();
|
||
|
cm1 = 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);
|
||
|
cm1.Parameters.AddWithValue("@branchName", NewCompany.branchAlias);
|
||
|
cm1.Parameters.AddWithValue("@address", NewCompany.branch_address);
|
||
|
cm1.Parameters.AddWithValue("@city", NewCompany.branch_city);
|
||
|
cm1.Parameters.AddWithValue("@state_or_province", NewCompany.branch_province);
|
||
|
cm1.Parameters.AddWithValue("@branch_telephone", NewCompany.branch_telephone);
|
||
|
cm1.Parameters.AddWithValue("@branchID", id);
|
||
|
cm1.Transaction = transaction;
|
||
|
cm1.ExecuteNonQuery();
|
||
|
transaction.Commit();
|
||
|
cn.Close();
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
transaction.Rollback();
|
||
|
cn.Close();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|