private void CreateContract(string template)
        {
            //construct data
            OwnerInformation    owner = new OwnerInformation(directorName.Text, directorSurname.Text, directorMail.Text, directorPhone.Text);
            BusinessInformation businessInformation = new BusinessInformation(companyNameTextbox.Text, companyAddress.Text, companyCityTextbox.Text, companyPIBTextbox.Text, companyRegistryTextbox.Text, dinarskiTextbox.Text, devizniTextbox.Text);
            ContractInformation contractInfo        = new ContractInformation(contractLengthCombobox.SelectedIndex + 1, packageCombobox.SelectedIndex, owner, businessInformation);
            string contractNumber = DateTime.Now.ToString("MMddyyyymmssf");

            contractInfo.ContractNumber = contractNumber;

            Document doc = new Document();

            doc.LoadFromFile(template);
            doc.Replace("@companyName", contractInfo.GymInformation.Name, true, true);
            doc.Replace("@directorName", contractInfo.GymOwnerInformation.Name, true, true);
            doc.Replace("@directorSurname", contractInfo.GymOwnerInformation.Surname, true, true);
            doc.Replace("@companyCity", contractInfo.GymInformation.City, true, true);
            doc.Replace("@companyAddress", contractInfo.GymInformation.Address, true, true);
            doc.Replace("@PIB", contractInfo.GymInformation.PIB, true, true);
            doc.Replace("@companyRegistryNumber", contractInfo.GymInformation.RegistryNumber, true, true);
            doc.Replace("@dinarski", contractInfo.GymInformation.Dinarski, true, true);
            doc.Replace("@devizni", contractInfo.GymInformation.Devizni, true, true);
            doc.Replace("@directorNumber", contractInfo.GymOwnerInformation.Mobile, true, true);
            doc.Replace("@dateOfSigning", DateTime.Now.ToShortDateString(), true, true);
            doc.Replace("@package", (contractInfo.ContractPackage == 0) ? "Po iskoriscenosti" : "Flat fee", true, true);
            doc.Replace("@duration", contractInfo.ContractLength.ToString(), true, true);
            doc.Replace("@contractNumber", contractInfo.ContractNumber, true, true);
            doc.SaveToFile(contractNumber + ".docx");

            ProcessStartInfo info = new ProcessStartInfo(contractNumber + ".docx");

            Process.Start(info);
        }
Beispiel #2
0
        public List <ContractInformation> GetAllContracts()
        {
            List <ContractInformation> toReturn = new List <ContractInformation>();

            using (var conn = GetConnection())
            {
                conn.Open();

                using (var com = new MySqlCommand("SELECT * FROM contracts INNER JOIN business ON contracts.business_id = business.business_id INNER JOIN owners ON business.owner_id = owners.owner_id", conn))
                {
                    using (var reader = com.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            BusinessInformation businessInfo = new BusinessInformation(reader.GetString(8), reader.GetString(9), reader.GetString(10), reader.GetString(11), reader.GetString(12), reader.GetString(13), reader.GetString(14));
                            OwnerInformation    ownerInfo    = new OwnerInformation(reader.GetString(16), reader.GetString(17), reader.GetString(18), reader.GetString(19));
                            ContractInformation contractInfo = new ContractInformation(reader.GetInt32(1), reader.GetInt32(2), ownerInfo, businessInfo);
                            contractInfo.ContractNumber = reader.GetString(4);

                            if (!reader.IsDBNull(5))
                            {
                                contractInfo.DateSigned = reader.GetDateTime(5);
                            }
                            toReturn.Add(contractInfo);
                        }
                    }
                }
            }
            return(toReturn);
        }
Beispiel #3
0
        public void InsertContract(ContractInformation contract)
        {
            //first insert owner
            using (var conn = GetConnection())
            {
                conn.Open();
                long ownerID    = -1;
                long businessID = -1;

                using (var com = new MySqlCommand("INSERT INTO owners (name,surname,email,phone,google_id) VALUES (@name,@surname,@email,@phone,'NOT SET')", conn))
                {
                    com.Parameters.Add("@name", MySqlDbType.VarChar).Value    = contract.GymOwnerInformation.Name;
                    com.Parameters.Add("@surname", MySqlDbType.VarChar).Value = contract.GymOwnerInformation.Surname;
                    com.Parameters.Add("@email", MySqlDbType.VarChar).Value   = contract.GymOwnerInformation.Email;
                    com.Parameters.Add("@phone", MySqlDbType.VarChar).Value   = contract.GymOwnerInformation.Mobile;

                    com.ExecuteNonQuery();
                    ownerID = com.LastInsertedId;
                }

                if (ownerID >= 0)
                {
                    using (var com = new MySqlCommand("INSERT INTO business (owner_id,name,address,city,pib,registry_number,dinarski,devizni) VALUES (@owner_id,@name,@address,@city,@pib,@registry_number,@dinarski,@devizni)", conn))
                    {
                        com.Parameters.Add("@owner_id", MySqlDbType.Int64).Value          = ownerID;
                        com.Parameters.Add("@name", MySqlDbType.VarChar).Value            = contract.GymInformation.Name;
                        com.Parameters.Add("@address", MySqlDbType.VarChar).Value         = contract.GymInformation.Address;
                        com.Parameters.Add("@city", MySqlDbType.VarChar).Value            = contract.GymInformation.City;
                        com.Parameters.Add("@pib", MySqlDbType.VarChar).Value             = contract.GymInformation.PIB;
                        com.Parameters.Add("@registry_number", MySqlDbType.VarChar).Value = contract.GymInformation.RegistryNumber;
                        com.Parameters.Add("@dinarski", MySqlDbType.VarChar).Value        = contract.GymInformation.Dinarski;
                        com.Parameters.Add("@devizni", MySqlDbType.VarChar).Value         = contract.GymInformation.Devizni;

                        com.ExecuteNonQuery();
                        businessID = com.LastInsertedId;
                    }
                }

                if (businessID >= 0)
                {
                    using (var com = new MySqlCommand("INSERT INTO contracts (contract_length,contract_package,business_id, contract_number, date_signed) VALUES (@length,@package,@id,@number,now())", conn))
                    {
                        com.Parameters.Add("@length", MySqlDbType.Int32).Value   = contract.ContractLength;
                        com.Parameters.Add("@package", MySqlDbType.Int32).Value  = contract.ContractPackage;
                        com.Parameters.Add("@id", MySqlDbType.Int64).Value       = businessID;
                        com.Parameters.Add("@number", MySqlDbType.VarChar).Value = contract.ContractNumber;


                        com.ExecuteNonQuery();
                    }
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //construct data
            OwnerInformation    owner = new OwnerInformation(directorName.Text, directorSurname.Text, directorMail.Text, directorPhone.Text);
            BusinessInformation businessInformation = new BusinessInformation(companyNameTextbox.Text, companyAddress.Text, companyCityTextbox.Text, companyPIBTextbox.Text, companyRegistryTextbox.Text, dinarskiTextbox.Text, devizniTextbox.Text);
            ContractInformation contractInfo        = new ContractInformation(contractLengthCombobox.SelectedIndex + 1, packageCombobox.SelectedIndex, owner, businessInformation);
            string contractNumber = DateTime.Now.ToString("MMddyyyymmssf");

            contractInfo.ContractNumber = contractNumber;
            //upload to the database

            Form1.AllContracts.Add(contractInfo);
            //save locally
            FileStream      fs = new FileStream("contracts.dat", FileMode.Create, FileAccess.Write);
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(fs, Form1.AllContracts);
            fs.Close();

            if (Database.Instance.CanConnect())
            {
                Database.Instance.InsertContract(contractInfo);
            }
            else
            {
                if (Form1.SyncTree == null)
                {
                    Form1.SyncTree = new List <SyncAction>();
                }

                SyncAction syncAction = new SyncAction {
                    Operation = "INSERT", ObjectValue = contractInfo
                };
                Form1.SyncTree.Add(syncAction);
                FileStream      fsSync = new FileStream("syncdata.syn", FileMode.Create, FileAccess.Write);
                BinaryFormatter bfSync = new BinaryFormatter();
                bfSync.Serialize(fsSync, Form1.SyncTree);
                fsSync.Close();
            }
        }
Beispiel #5
0
 public void ModifyContract(ContractInformation contract)
 {
 }
Beispiel #6
0
 public void DeleteContract(ContractInformation contract)
 {
 }