Example #1
0
 public ProductExports(MySQLDriver driver)
 {
     this._SQL = driver;
     _units = new Units(_SQL);
     _products = new Products(_SQL);
     _months = new Months();
     _deadlines = new Deadlines(_SQL);
 }
Example #2
0
 public Inventory(MySQLDriver driver)
 {
     _SQL = driver;
     _deadlines = new Deadlines(_SQL);
     _materialTypes = new MaterialTypes(_SQL);
     _units = new Units(_SQL);
     _companies = new Companies(_SQL);
     _currencies = new Currencies(_SQL);
 }
Example #3
0
 public Transfers(MySQLDriver driver)
 {
     this._SQL = driver;
     _deadlines = new Deadlines(_SQL);
     _units = new Units(_SQL);
     _companies = new Companies(_SQL);
     _materialTypes = new MaterialTypes(_SQL);
     _currencies = new Currencies(_SQL);
 }
Example #4
0
 public Materials(MySQLDriver driver, Companies companies, Units units, Deadlines deadlines)
 {
     this._SQL = driver;
     _companies = companies;
     _units = units;
     _currencies = new Currencies(_SQL);
     _materialTypes = new MaterialTypes(_SQL);
     _deadlines = deadlines;
 }
Example #5
0
 public void refreshData()
 {
     listBox1.Items.Clear();
     Deadlines = new Deadlines(SQL);
     List<Deadline> tbl = Deadlines.getList("DESC");
     foreach (Deadline collumn in tbl)
     {
         listBox1.Items.Add(collumn);
     }
     button3.Enabled = false;
     HandleSecurity();
 }
Example #6
0
        public InventoryForm()
        {
            InitializeComponent();
            connector = Authorization.login(AppSettings.Nick, AppSettings.Password);
            SQL = new MySQLDriver(connector);
            Inventory = new Inventory(SQL);
            Corrections = new Corrections(SQL);
            Deadlines = new Deadlines(SQL);
            Auth = new Authorization(SQL);

            dateTimePicker1.Value = DateTime.Now;

            resizeByDataGrid(dataGridView1);
        }
 private void button4_Click_1(object sender, EventArgs e)
 {
     Deadlines deadlines = new Deadlines(SQL);
     deadlines.Add(dateTimePicker1.Value);
     Deadline deadline = deadlines.GetLast();
     Status = "Naskladňuji...";
     foreach (DataGridViewRow row in dataGridView1.Rows) {
         int id = 0;
         if ((row.Cells["IDColumn"].Value != null) && (int.TryParse(row.Cells["IDColumn"].Value.ToString(), out id) == true)) {
             Transfer item = Transfers.GetRecord(id);
             item.Deadline = deadline;
             Transfers.Change(item);
         }
     }
     Status = "....";
     dataGridView1.Enabled = false;
     button4.Enabled = false;
 }
Example #8
0
 public Corrections(MySQLDriver driver)
 {
     _SQL = driver;
     _materialTypes = new MaterialTypes(_SQL);
     _deadlines = new Deadlines(_SQL);
 }
Example #9
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if ((dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)&&(cellValue=="")) return;
            else if ((dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value!=null)&&(cellValue == dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()))
                return;
            if ((addID != -1) && (addID != e.RowIndex))
                rowsAdded = false;
            else if ((addID != -1) && (addID == e.RowIndex))
                rowsAdded = true;

            if (initState) return;
            if (units == null) return;
            if (companies == null) return;

            foreach(String collumn in nummericIntCollums){
                int intOut = 0;
                if (dataGridView1.Rows[e.RowIndex].Cells[collumn].Value == null) continue;
                if (!int.TryParse(dataGridView1.Rows[e.RowIndex].Cells[collumn].Value.ToString(), out intOut))
                {
                    dataGridView1.Rows[e.RowIndex].Cells[collumn].ErrorText = "Zadejte číselnou hodnotu!";
                }
                else {
                    dataGridView1.Rows[e.RowIndex].Cells[collumn].ErrorText = "";
                }
            }
            foreach (String collumn in nummericFloatCollums)
            {
                float floatOut = 0;
                if (dataGridView1.Rows[e.RowIndex].Cells[collumn].Value == null) continue;
                if (!float.TryParse(dataGridView1.Rows[e.RowIndex].Cells[collumn].Value.ToString().Replace('.',','), out floatOut))
                {
                    dataGridView1.Rows[e.RowIndex].Cells[collumn].ErrorText = "Zadejte číselnou hodnotu!";
                }
                else
                {
                    dataGridView1.Rows[e.RowIndex].Cells[collumn].ErrorText = "";
                }
            }
            if (dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].Value != null)
            {
                String shippingDateStr = dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].Value.ToString();
                String[] dateParts = shippingDateStr.Split('.');
                int intVal = 0;
                if (!shippingDateStr.Contains("."))
                {
                    dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText = "Datum nemá správný formát(dd.mm.yyyy)";
                }
                else if (dateParts.Length != 3)
                {
                    dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText = "Datum nemá správný formát(dd.mm.yyyy)";
                }
                else if (!int.TryParse(dateParts[0], out intVal) || !int.TryParse(dateParts[1], out intVal) || !int.TryParse(dateParts[2], out intVal))
                {
                    dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText = "Datum nemá správný formát(dd.mm.yyyy)";
                }
                else
                {
                    dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText = "";
                }
                if (dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].Value.ToString() == "")
                    dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText = "";
            }
            else {
                dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText = "";
            }

            bool rowError = false;
            foreach (DataGridViewCell cell in dataGridView1.Rows[e.RowIndex].Cells) {
                if (cell.ErrorText != "")
                {
                    rowError = true;
                    break;
                }
            }

            if (dataGridView1.Rows[e.RowIndex].Cells["UnitColumn"].Value == null) return;
            Unit unitItem = getUnit(dataGridView1.Rows[e.RowIndex].Cells["UnitColumn"].Value.ToString());
            if (unitItem.ID == 0) return;

            if (dataGridView1.Rows[e.RowIndex].Cells["CompanyColumn"].Value == null) return;
            Company companyItem = getCompany(dataGridView1.Rows[e.RowIndex].Cells["CompanyColumn"].Value.ToString());
            if (companyItem.ID == 0) return;

            Month monthItem = new Month(0, "");
            if (dataGridView1.Rows[e.RowIndex].Cells["MonthColumn"].Value == null)
            {
                monthItem = (new Months()).getMonth(monthComboBox.Text);
            }
            else {
                monthItem = (new Months()).getMonth(dataGridView1.Rows[e.RowIndex].Cells["MonthColumn"].Value.ToString());
            }

            int year = 0;
            if (dataGridView1.Rows[e.RowIndex].Cells["YearColumn"].Value == null)
            {
                year = (int)yearUpDown.Value;
            }
            else {
                year = (int)parseCell(0, e.RowIndex, "YearColumn");
            }
            DateTime shippingDate = new DateTime();
            if (dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].Value == null)
            {
                shippingDate = new DateTime();
            }
            else
            {
                if ((!rowError) && (dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].Value.ToString() != ""))
                {
                    String[] dateParts = dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].Value.ToString().Split('.');
                    shippingDate = new DateTime(int.Parse(dateParts[2]), int.Parse(dateParts[1]), int.Parse(dateParts[0]));
                    if (shippingDate < lastDeadline.EventDate.Date)
                    {
                        dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText = "Zadané datum spadá do předešlého období!";
                        return;
                    }
                    else {
                        if (dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText == "Zadané datum spadá do předešlého období!")
                            dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText = "";
                    }
                }
            }

            //if (dataGridView1.Rows[e.RowIndex].Cells["PriceColumn"].Value == null) return;
            if (dataGridView1.Rows[e.RowIndex].Cells["MaterialTypeColumn"].Value == null) return;
            MaterialType materialTypeItem = getMaterialType(dataGridView1.Rows[e.RowIndex].Cells["MaterialTypeColumn"].Value.ToString());
            if (materialTypeItem.ID == 0) return;

            String name = "";
            if (dataGridView1.Rows[e.RowIndex].Cells["NameColumn"].Value != null)
                name = dataGridView1.Rows[e.RowIndex].Cells["NameColumn"].Value.ToString();
            Currency currencyItem;
            if (dataGridView1.Rows[e.RowIndex].Cells["CurrencyColumn"].Value == null) currencyItem = new Currency(0, "");
            else currencyItem = getCurrency(dataGridView1.Rows[e.RowIndex].Cells["CurrencyColumn"].Value.ToString());
            if (currencyItem.ID == 0) return;
            float course = 0;
            DateTime courseDate = new DateTime();
            if (((dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].Value == null) || (dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].Value.ToString()=="")) && (shippingDate != new DateTime()))
            {
                dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].Value = DateTimeUtils.DateToString(DateTimeUtils.GetFirstWorkDay(shippingDate.Month, shippingDate.Year));
                courseDate = DateTimeUtils.GetFirstWorkDay(shippingDate.Month, shippingDate.Year);
            }
            if ((dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].Value != null)&&(courseDate == new DateTime()))
            {
                if (/*(!rowError) &&*/ (dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].Value.ToString() != ""))
                {
                    String[] dateParts = dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].Value.ToString().Split('.');
                    if (dateParts.Length != 3) {
                        dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].ErrorText = "Zadané datum má špatný formát!";
                        return;
                    }
                    try
                    {
                        courseDate = new DateTime(int.Parse(dateParts[2]), int.Parse(dateParts[1]), int.Parse(dateParts[0]));
                    }
                    catch {
                        dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].ErrorText = "Zadané datum má špatný formát!";
                        return;
                    }
                    dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].ErrorText = "";
                }
            }
            if ((dataGridView1.Rows[e.RowIndex].Cells["CurrencyColumn"].Value != null) && (dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].Value != null) && (dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].ErrorText == "") && (dataGridView1.Rows[e.RowIndex].Cells["ShippingDateColumn"].Value.ToString() != ""))
            {
                //dataGridView1.Rows[e.RowIndex].Cells["CourseDateColumn"].Value = DateTimeUtils.DateToString(courseDate);
                course = ExchangeRates.getByDate(Currencies.getCurrency(dataGridView1.Rows[e.RowIndex].Cells["CurrencyColumn"].Value.ToString()), courseDate);
            }
            else {
                course = 0;
            }
            dataGridView1.Rows[e.RowIndex].Cells["CourseColumn"].Value = course.ToString();
            Deadline deadline = Deadlines.Default;
            if (dataGridView1.Rows[e.RowIndex].Cells["DeadlineColumn"].Value != null)
            {
                deadline = new Deadlines(SQL).GetRecord(int.Parse(dataGridView1.Rows[e.RowIndex].Cells["DeadlineColumn"].Value.ToString()));
            }
            int id = 0;
            if (!rowsAdded) id = items[e.RowIndex].ID;/* id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells["IDColumn"].Value.ToString());*/
            Material materialItem = new Material(
                 (int)parseCell(0,e.RowIndex,"IDColumn"),
                 name,
                 parseCell(0,e.RowIndex,"PriceColumn"),
                 parseCell(0,e.RowIndex,"AmountColumn"),
                 companyItem,
                 (int)parseCell(0,e.RowIndex,"InvoiceColumn"),
                 unitItem,
                 materialTypeItem,
                 monthItem,
                 year,
                 currencyItem,
                 shippingDate,
                 courseDate,
                 course,
                 parseCell(0, e.RowIndex, "ShippingColumn"),
                 deadline
            );

            if (rowError) return;
            if (rowsAdded)
            {
                Status = "Přidávám novou položku...";
                //dataGridView1.AllowUserToAddRows = true;
                Materials.Add(materialItem);
                if (!connector.IsConnected()) return;
                dataGridView1.BeginInvoke(new Action(()=>{
                    reload();
                    dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
                    //dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells.Count - 1].Selected = true;
                    //dataGridView1.BeginEdit(true);
                }));
                addID = -1;
                //dataGridView1.AutoGenerateColumns = true;
                //dataGridView1.AllowUserToAddRows = true;
                //dataGridView1.Rows[dataGridView1.Rows.GetLastRow(DataGridViewElementStates.None)];
                dataGridView1.Rows[dataGridView1.NewRowIndex].ReadOnly = false;
                dataGridView1.Rows[dataGridView1.NewRowIndex].DefaultCellStyle = dataGridView1.DefaultCellStyle;
                refresh();
                dataGridView1.Rows[dataGridView1.NewRowIndex-1].Cells["TotalPriceColumn"].Value = CountTotalPrice(materialItem).ToString();
            }
            else
            {
                if (items[e.RowIndex] != materialItem)
                {
                    Status = "Provádím úpravy...";
                    Materials.Change(materialItem);
                    if (!connector.IsConnected()) return;
                    if ((dataGridView1.Columns[e.ColumnIndex].Name == "PriceColumn") || (dataGridView1.Columns[e.ColumnIndex].Name == "AmountColumn") || (dataGridView1.Columns[e.ColumnIndex].Name == "CurrencyColumn") || (dataGridView1.Columns[e.ColumnIndex].Name == "CourseDateColumn") || (dataGridView1.Columns[e.ColumnIndex].Name == "ShippingColumn"))
                    {
                        refresh();
                        dataGridView1.Rows[e.RowIndex].Cells["TotalPriceColumn"].Value = CountTotalPrice(materialItem).ToString();
                    }
                }
            }
            rowsAdded = false;
            Status = ".....";
        }