Ejemplo n.º 1
0
        /// <summary>
        /// delete phone and all the childrens and operations
        /// </summary>
        /// <param name="phoneNode"> target phone node </param>
        void DeletePhone(TreeNode phoneNode)
        {
            foreach (TreeNode node in phoneNode.Nodes)
            {
                if (node.Text == "Operations")
                {
                    List <TreeNode> rem = new List <TreeNode>();
                    foreach (TreeNode opNode in node.Nodes)
                    {
                        DeleteOperation(opNode);
                        rem.Add(opNode);
                    }

                    foreach (TreeNode nds in rem)
                    {
                        node.Nodes.Remove(nds);
                    }
                }
                else
                {
                    DeletePhone(node);
                }
            }

            phoneNode.Nodes.Clear();

            PhoneModel phone = phoneNode.Tag as PhoneModel;

            SQLWorker.GetInstance().SqlComm("delete from tblPhoneModels where id=" + phone.id);
            parentPhoneBox.Items.Remove(phone);

            deletePhoneModelEvent?.Invoke(phone);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Change phone's name and parent model
        /// </summary>
        void EditPhoneModel()
        {
            PhoneModel phone = selectedNode.Tag as PhoneModel;

            phone.name = phoneNameBox.Text;

            var node = selectedNode;

            PhoneModel parentModel = (parentPhoneBox.SelectedItem as PhoneModel);

            if (parentModel.id != phone.parentId)
            {
                var parentNode = FindNodeById(parentModel.id);
                if (parentNode != node)
                {
                    selectedNode.Parent.Nodes.Remove(node);
                    phone.parentId = parentModel.id;
                    parentNode.Nodes.Add(node);
                }
                else
                {
                    return;
                }
            }

            node.Text = phone.name;

            SQLWorker.GetInstance().SqlComm("update tblPhoneModels set Name='" + phone.name + "' " +
                                            (phone.parentId > 0 ? ", ParentId=" + phone.parentId.ToString() : " ") +
                                            " where Id=" + phone.id + "; ");

            changePhoneModelEvent?.Invoke(phone);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// loading subInvoices then invoice is selected
        /// </summary>
        private void ListView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count < 1)
            {
                return;
            }

            Invoice inv  = listView1.SelectedItems[0].Tag as Invoice;
            string  comm = "select * from tblSubInvoices where(InvoiceID=" + inv.id.ToString() + ")";

            selectedSubInvoices = SQLWorker.GetInstance().ReadTable <SubInvoice>(comm, (result, subinvoice) =>
            {
                subinvoice.id          = Convert.ToInt32(result[0]);
                subinvoice.device      = Convert.ToString(result[2]);
                subinvoice.description = Convert.ToString(result[3]);
                subinvoice.price       = Convert.ToInt32(result[4]);
                subinvoice.count       = Convert.ToInt32(result[5]);
                return(subinvoice);
            });

            listView2.Items.Clear();
            foreach (SubInvoice sbinv in selectedSubInvoices)
            {
                ListViewItem itm = new ListViewItem();
                itm.Text = sbinv.device;
                itm.SubItems.Add(sbinv.description);
                itm.SubItems.Add(sbinv.count.ToString());
                itm.SubItems.Add(((float)sbinv.price / 100.0f).ToString());
                itm.SubItems.Add((sbinv.count * (float)sbinv.price / 100.0f).ToString());
                itm.Tag = sbinv;
                listView2.Items.Add(itm);
            }
        }
Ejemplo n.º 4
0
        public MainForm()
        {
            InitializeComponent();
            SQLWorker.GetInstance();
            LoginForm lg = new LoginForm();

            lg.ShowDialog();
            /// TabPage class cannot be designed by designManager. For this reason, in the debug mode,
            /// ..Page classes inherited from Form page and can be launched by pressing buttons
#if DEBSYMB
            this.button1.Click += new System.EventHandler(this.Button1_Click);
            this.button2.Click += new System.EventHandler(this.Button2_Click);
            this.button3.Click += new System.EventHandler(this.Button3_Click);
            this.button4.Click += new System.EventHandler(this.Button4_Click);

            this.Controls.Add(this.button4);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
#else
            if (currentUser != null)
            {
                FillTabs();
                this.Controls.Add(this.AllTabs);
            }
#endif
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add new function from the form.
        /// Also, save it in the database
        /// </summary>
        void AddNewFunction()
        {
            if (operationNameBox.Text.Length == 0)
            {
                MessageBox.Show("Sorry, operation or phone model should be typed",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (operationPriceBox.Text.Length == 0)
            {
                MessageBox.Show("Sorry, price of operation should be typed",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Function func = new Function();

            func.id    = lastFunctionId + 1;
            func.name  = operationNameBox.Text;
            func.price = (int)(float.Parse(operationPriceBox.Text) * 100.0f);

            AddFunction(func);
            allFunctions.Add(func);
            SQLWorker.GetInstance().SqlComm("insert into tblFunctions values(" + func.id + ",'" +
                                            func.name + "'," + func.price + ");");

            addFunctionEvent?.Invoke(func);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Prepearing. Filling comboboses and treeView
        /// </summary>
        void FillTables()
        {
            //fill functions
            allFunctions = SQLWorker.GetInstance().ReadFunctions();
            operations   = treeView1.Nodes.Add("Operations");
            foreach (Function func in allFunctions)
            {
                AddFunction(func);
            }

            //fill phones
            allPhones = SQLWorker.GetInstance().ReadPhones();
            phones    = treeView1.Nodes.Add("Phones");
            foreach (var phone in allPhones)
            {
                AddPhone(phone);
            }

            //fill operations
            allOperations = SQLWorker.GetInstance().ReadOperations();
            foreach (Operation op in allOperations)
            {
                AddOperation(op);
            }

            treeView1.ExpandAll();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Construct of the class.
 /// It should get all the users from database and fill the listView
 /// </summary>
 public UsersPage()
 {
     InitializeComponent();
     users = SQLWorker.GetInstance().ReadUsers();
     FillListBox();
     delBtn.Visible = false;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// delete operation
        /// </summary>
        /// <param name="opNode"> target operation </param>
        void DeleteOperation(TreeNode opNode)
        {
            Operation op = opNode.Tag as Operation;

            SQLWorker.GetInstance().SqlComm("delete from tblOperations where id=" + op.id + ";");

            deleteOperationEvent?.Invoke(op);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Fiiling comboboxes and making events
        /// </summary>
        void FillBoxes()
        {
            deleteButton.Visible = false;

            functions   = SQLWorker.GetInstance().ReadFunctions();
            phoneModels = SQLWorker.GetInstance().ReadPhones();
            operations  = SQLWorker.GetInstance().ReadOperations();

            deviceBox.DataSource      = phoneModels;
            descriptionBox.DataSource = functions;

            if (objectsPage != null)
            {
                objectsPage.addOperationEvent += delegate(Operation op) { operations.Add(op); };
                objectsPage.addFunctionEvent  += delegate(Function func)
                {
                    descriptionBox.DataSource = null;
                    functions.Add(func);
                    descriptionBox.DataSource = functions;
                };
                objectsPage.addPhoneModelEvent += delegate(PhoneModel phone)
                {
                    deviceBox.DataSource = null;
                    phoneModels.Add(phone);
                    deviceBox.DataSource = phoneModels;
                };

                objectsPage.changeFunctionEvent += delegate(Function func)
                {
                    ChangeObject(functions, func, descriptionBox);
                };

                objectsPage.changePhoneModelEvent += delegate(PhoneModel phone)
                {
                    ChangeObject(phoneModels, phone, deviceBox);
                };

                objectsPage.changeOperationEvent += delegate(Operation op)
                {
                    ChangeObject(operations, op);
                };

                objectsPage.deleteFunctionEvent += delegate(Function func)
                {
                    DeleteObject(functions, func, descriptionBox);
                };

                objectsPage.deletePhoneModelEvent += delegate(PhoneModel phone)
                {
                    DeleteObject(phoneModels, phone, deviceBox);
                };

                objectsPage.deleteOperationEvent += delegate(Operation op)
                {
                    DeleteObject(operations, op);
                };
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// delete selected function
        /// </summary>
        void DeleteFunction()
        {
            Function func = selectedNode.Tag as Function;

            DeleteFunctionFromPhone(phones, func);

            SQLWorker.GetInstance().SqlComm("delete from tblFunctions where id=" + func.id);
            operationNameBox.Items.Remove(func);

            deleteFunctionEvent?.Invoke(func);
        }
Ejemplo n.º 11
0
        public MakeInvoicePage()
        {
            InitializeComponent();
            qtyBox.Text   = "1";
            priceBox.Text = "0";

            priceBox.Enabled = MainForm.currentUser.GetStringRights().Contains('P');

            FillBoxes();
            maxInvoice      = SQLWorker.GetInstance().GetMaxId("tblInvoices");
            InvoiceBox.Text = (maxInvoice + 1).ToString();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add new phone from the form.
        /// Also, save it in the database
        /// </summary>
        /// <param name="parent"> parent phone </param>
        void AddNewPhone(int parent)
        {
            PhoneModel model = new PhoneModel();

            model.id       = lastPhoneId + 1;
            model.parentId = parent;
            model.name     = phoneNameBox.Text;
            SQLWorker.GetInstance().SqlComm("insert into tblPhoneModels values("
                                            + model.id + ",'" + model.name + "'," + model.parentId + ")");
            AddPhone(model);

            addPhoneModelEvent?.Invoke(model);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Add new operation from the form.
        /// Also, save it in the database
        /// </summary>
        /// <param name="parent">parent phone</param>
        void AddNewOperation(int parent)
        {
            if (parent == 0)
            {
                return;
            }

            int      opId   = 0;
            string   opName = operationNameBox.Text; //it could be changed
            Function basefnc;

            if (operationNameBox.SelectedIndex >= 0)
            {
                basefnc = (Function)operationNameBox.SelectedItem;
                opId    = basefnc.id;
            }
            else
            {
                foreach (TreeNode node in operations.Nodes)
                {
                    if (node.Text == opName)
                    {
                        basefnc = node.Tag as Function;
                        opId    = basefnc.id;
                        break;
                    }
                }
            }

            if (opId == 0)
            {
                AddNewFunction();
                AddNewOperation(parent);
                return;
            }

            Operation op = new Operation();

            op.id         = lastOperationId + 1;
            op.deviceID   = parent;
            op.functionID = opId;
            op.price      = (int)(float.Parse(operationPriceBox.Text) * 100.0f);

            SQLWorker.GetInstance().SqlComm("insert into tblOperations values("
                                            + op.id + "," + op.deviceID + "," + op.functionID + "," + op.price + ")");

            AddOperation(op);
            allOperations.Add(op);

            addOperationEvent?.Invoke(op);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// change operation phone model and price
        /// </summary>
        void EditOperation()
        {
            Operation op = selectedNode.Tag as Operation;

            op.price = (int)(float.Parse(operationPriceBox.Text) * 100.0f);

            PhoneModel parentModel = (parentPhoneBox.SelectedItem as PhoneModel);

            if (op.deviceID != parentModel.id)
            {
                op.deviceID = parentModel.id;
                var parNode = FindNodeById(op.deviceID);

                var node = selectedNode;
                selectedNode.Parent.Nodes.Remove(node);

                TreeNode oper = null;
                foreach (TreeNode opNode in parNode.Nodes)
                {
                    if (opNode.Text == "Operations")
                    {
                        oper = opNode;
                        break;
                    }
                }

                if (oper == null)
                {
                    oper = parNode.Nodes.Add("Operations");
                }

                oper.Nodes.Add(node);
            }

            Function func = operationNameBox.SelectedItem as Function;

            if (op.functionID != func.id)
            {
                op.functionID     = func.id;
                selectedNode.Text = func.name;
            }

            phoneNameBox.Enabled           = true;;
            operationNameBox.DropDownStyle = ComboBoxStyle.DropDown;

            SQLWorker.GetInstance().SqlComm("update tblOperations set DeviceId=" + op.deviceID +
                                            ", FunctionId=" + op.functionID +
                                            ", Price=" + op.price + " where Id=" + op.id + "; ");

            changeOperationEvent?.Invoke(op);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Change function description and default price
        /// Also, defaily description will be changed in the all operations
        /// </summary>
        void EditFunction()
        {
            Function func = selectedNode.Tag as Function;

            func.name         = operationNameBox.Text;
            func.price        = (int)(float.Parse(operationPriceBox.Text) * 100.0f);
            selectedNode.Text = func.name;

            ChangeOperationDescription(phones, func);

            SQLWorker.GetInstance().SqlComm("update tblFunctions set Name='" + func.name +
                                            "', Price=" + func.price + " where Id=" + func.id + "; ");

            changeFunctionEvent?.Invoke(func);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Delete selected user from listview and database
        /// </summary>
        private void DelBtn_Click(object sender, EventArgs e)
        {
            if (!isSelected)
            {
                return;
            }

            string id = listView1.SelectedItems[0].Text;

            SQLWorker.GetInstance().SqlComm(() =>
            {
                SqlCommand comm = new SqlCommand("delete from tblUsers where(ID=@id)");
                comm.Parameters.Add(new SqlParameter("@id", id));
                return(comm);
            });

            listView1.Items.Remove(listView1.SelectedItems[0]);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Login button pressed
        /// Check login name and password
        /// </summary>
        private void Button1_Click(object sender, EventArgs e)
        {
            var usersList = SQLWorker.GetInstance().ReadUser(nameBox.Text);

            if (usersList.Count == 0)
            {
                ShowError();
                return;
            }

            foreach (var usr in usersList)
            {
                if (usr.Value.ComparePasswords(passwordBox.Text))
                {
                    MainForm.currentUser = usr.Value;
                    isSomeoneLogged      = true;
                    Close();
                    return;
                }
            }
            ShowError();
        }
Ejemplo n.º 18
0
        /// <summary>
        /// save invoice from the form to database
        /// </summary>
        /// <param name="price"> summ with grd </param>
        /// <param name="devices">  string with all the devices </param>
        void SaveInvoiceToDatabase(int price, string devices)
        {
            Logger.GetInstance().SaveLog("SaveInvoiceToDatabase entered ");
            int invoiceId = int.Parse(InvoiceBox.Text);

            {
                string     comm    = "insert into tblInvoices values( @InvoiceId, @Date, @CustomName, @UserID, @TotalPrice, @devices)";
                SqlCommand command = new SqlCommand(comm);
                command.Parameters.Add(new SqlParameter("InvoiceId", invoiceId));
                command.Parameters.Add(new SqlParameter("Date", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")));
                command.Parameters.Add(new SqlParameter("CustomName", CustNameBox.Text));
                command.Parameters.Add(new SqlParameter("UserID", MainForm.currentUser.id));
                command.Parameters.Add(new SqlParameter("TotalPrice", price));
                command.Parameters.Add(new SqlParameter("devices", devices));

                SQLWorker.GetInstance().SqlComm(command);
            }

            int subId = SQLWorker.GetInstance().GetMaxId("tblSubInvoices");

            foreach (ListViewItem itm in listView1.Items)
            {
                subId++;
                string     subInvoice = "insert into tblSubInvoices values(@Id,@InvoiceId, @device,@description,@price, @count);";
                SqlCommand command    = new SqlCommand(subInvoice);
                command.Parameters.Add(new SqlParameter("Id", subId));
                command.Parameters.Add(new SqlParameter("InvoiceId", invoiceId));
                command.Parameters.Add(new SqlParameter("device", itm.Text));
                command.Parameters.Add(new SqlParameter("description", itm.SubItems[1].Text));
                command.Parameters.Add(new SqlParameter("price", (float.Parse(itm.SubItems[3].Text) * 100)));
                command.Parameters.Add(new SqlParameter("count", itm.SubItems[2].Text));

                SQLWorker.GetInstance().SqlComm(command);
            }
            Logger.GetInstance().SaveLog("SaveInvoiceToDatabase exit ");
        }
Ejemplo n.º 19
0
        /// <summary>
        /// add/edit customer
        /// </summary>
        private void Button1_Click(object sender, EventArgs e)
        {
            if (PassBox.TextLength == 0 && !isSelected)
            {
                MessageBox.Show("Sorry, password cannot be empty", "Password Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (NameBox.TextLength == 0 && !isSelected)
            {
                MessageBox.Show("Sorry, user name cannot be empty", "Name Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            User cust = null;

            string rights = "";

            rights += InvoceCheckBox.Checked ?      "I" :"";
            rights += DeviceCheckBox.Checked ?      "D" : "";
            rights += PriceCheckBox.Checked ?       "P" : "";
            rights += CustomersCheckBox.Checked ?   "U" : "";
            rights += LogsCheckBox.Checked ?        "L" : "";



            if (isSelected)
            {
                int id = Int32.Parse(listView1.Items[selectedPos].Text);
                if (ChangeDetails(id, rights, out cust))
                {
                    SQLWorker.GetInstance().SqlComm(cust.UpdateSqlCommand);
                }
                else
                {
                    return;
                }
            }
            else
            {
                foreach (var usr in users)
                {
                    if (usr.Value.name == NameBox.Text)
                    {
                        MessageBox.Show("Sorry, user name is used", "Name Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                cust    = new User();
                cust.id = users.Count > 0 ? users.Last().Value.id + 1 : 1;
                users.Add(cust.id, cust);

                ChangeDetails(cust.id, rights, out cust);

                SQLWorker.GetInstance().SqlComm(cust.InsertNewUser);
            }

            ListViewItem itm = new ListViewItem(cust.id.ToString());

            itm.SubItems.Add(NameBox.Text);
            itm.SubItems.Add(PhoneBox.Text);
            itm.SubItems.Add(rights);

            if (isSelected)
            {
                isSelected = false;
                listView1.Items[selectedPos] = itm;
                Add.Text = "Add";
            }
            else
            {
                listView1.Items.Add(itm);
            }


            CleanFields();
        }
Ejemplo n.º 20
0
        /// <summary>
        /// search button click. Load invoices from database
        /// </summary>
        private void Button1_Click(object sender, EventArgs e)
        {
            if (searchCondBox.SelectedIndex > 1 && searchBox.Text == "")
            {
                MessageBox.Show("Sorry, search box could not be empty", "Search error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            int        selected = searchCondBox.SelectedIndex;
            SqlCommand command  = new SqlCommand();

            selected = selected > -1 ? selected : 0;
            string comm = "select * from tblInvoices,tblUsers where (UserId = tblUsers.Id and ";

            switch (selected)
            {
            case 0:
                comm += "Date >=@DateFrom and Date <=@DateTo);";
                command.Parameters.Add(new SqlParameter("DateFrom", fromDateTimePicker.Value.ToString("yyyy-MM-dd")));
                command.Parameters.Add(new SqlParameter("DateTo", toDateTimePicker.Value.ToString("yyyy-MM-dd")));
                break;

            case 1:
                comm += "CustName=@CustomerName)";
                command.Parameters.Add(new SqlParameter("CustomerName", searchBox.Text));
                break;

            case 2:
                comm += "tblUsers.Name=@UserName)";
                command.Parameters.Add(new SqlParameter("UserName", searchBox.Text));
                break;

            case 3:
                comm += "tblInvoices.Id=@InvoiceId)";
                command.Parameters.Add(new SqlParameter("InvoiceId", searchBox.Text));
                break;
            }

            command.CommandText = comm;
            selectedInvoices    = SQLWorker.GetInstance().ReadTable <Invoice>(command, (result, invoice) =>
            {
                invoice.id         = Convert.ToInt32(result[0]);
                invoice.date       = Convert.ToString(result[1]);
                invoice.custName   = Convert.ToString(result[2]);
                invoice.userId     = Convert.ToInt32(result[3]);
                invoice.totalPrice = Convert.ToInt32(result[4]);
                invoice.devices    = Convert.ToString(result[5]);
                invoice.userName   = Convert.ToString(result[7]);
                return(invoice);
            });

            listView1.Items.Clear();
            foreach (Invoice inv in selectedInvoices)
            {
                ListViewItem itm = new ListViewItem();
                itm.Text = inv.id.ToString();
                itm.SubItems.Add(inv.date);
                itm.SubItems.Add(inv.userName);
                itm.SubItems.Add(inv.custName);
                itm.SubItems.Add(inv.devices);
                itm.SubItems.Add(((float)inv.totalPrice / 100.0f).ToString());
                itm.Tag = inv;
                listView1.Items.Add(itm);
            }
        }