Beispiel #1
0
 public void Add(String Name, float Price, float Amount, Company Company, int InvoiceNumber, Unit Unit, MaterialType MaterialType, Month Month, int Year, Currency Currency, DateTime ShippingDate, DateTime CourseDate, float Course, float Shipping, Deadline Deadline)
 {
     //String courseDateString = String.Format("{0:0000}-{1:00}-{2:00}",CourseDate.Year,CourseDate.Month,CourseDate.Day).Replace(" ","");
     String queryString = String.Format("INSERT INTO `{0}` VALUES(default,'{1}',{2},{3},{4},{5},{6},{7},{8},{9},{10},'{11}','{12}',{13},{14},{15});",
         _table, Name.Replace("'", "''"), Price.ToString().Replace(',', '.'), Amount.ToString().Replace(',', '.'), Company.ID, InvoiceNumber, Unit.ID, MaterialType.ID, Month.ID, Year, Currency.ID, DateTimeUtils.DateTimeToSQLDate(ShippingDate), DateTimeUtils.DateTimeToSQLDate(CourseDate), Course.ToString().Replace(',', '.'), Shipping.ToString().Replace(',', '.'), Deadline.ID);
     _SQL.RunQuery(queryString);
 }
Beispiel #2
0
 public ProductExport(int id, Product product, float amount, Unit unit, String description, Month month, int year, Deadline deadline)
 {
     ID = id;
     Product = product;
     Amount = amount;
     Unit = unit;
     Description = description;
     Month = month;
     Year = year;
     Deadline = deadline;
 }
Beispiel #3
0
        public List<ProductExport> getList(int year, Month month, int startID = 0)
        {
            List<ProductExport> rv = new List<ProductExport>();
            String query = String.Format("SELECT * FROM `{0}` WHERE YEAR={1} AND MONTH={2} AND ID>{3};", _table, year, month.ID, startID);
            String netString = _SQL.RunQuery(query);
            String[] lines = netString.Split('\n');

            foreach (String line in lines)
            {
                if (line == "") continue;

                rv.Add(parseLine(line));
            }

            return rv;
        }
Beispiel #4
0
 public Material(int id, String name, float price, float amount, Company company, int invoiceNumber, Unit unit,
     MaterialType materialType, Month month, int year, Currency currency, DateTime shippingDate, DateTime courseDate,
     float course, float shipping, Deadline deadline)
 {
     ID = id;
     Name = name;
     Price = price;
     Amount = amount;
     Company = company;
     InvoiceNumber = invoiceNumber;
     Unit = unit;
     MaterialType = materialType;
     Month = month;
     Year = year;
     Currency = currency;
     ShippingDate = shippingDate;
     CourseDate = courseDate;
     Course = course;
     ShippingPrice = shipping;
     Deadline = deadline;
 }
Beispiel #5
0
 public void Add(Product Product, float Amount, Unit Unit, String Description, Month Month, int Year, Deadline Deadline)
 {
     _SQL.RunQuery(String.Format("INSERT INTO `{0}` VALUES(default,{1},{2},{3},'{4}',{5},{6},{7});",
         _table, Product.ID, Amount, Unit.ID, Description.Replace("'", "''"), Month.ID, Year, Deadline.ID));
 }
Beispiel #6
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 = ".....";
        }
        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 (products == 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 = "";
                }
            }

            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;

            Product productItem;
            if (dataGridView1.Rows[e.RowIndex].Cells["ProductColumn"].Value == null) productItem = new Product(0, "");
            else
            {
                productItem = getProduct(dataGridView1.Rows[e.RowIndex].Cells["ProductColumn"].Value.ToString());
            }

            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");
            }
            //if (dataGridView1.Rows[e.RowIndex].Cells["PriceColumn"].Value == null) return;

            String description = "";
            if (dataGridView1.Rows[e.RowIndex].Cells["DescriptionColumn"].Value != null)
                description = dataGridView1.Rows[e.RowIndex].Cells["DescriptionColumn"].Value.ToString();

            int id = 0;
            if (!rowsAdded) id = items[e.RowIndex].ID;/* id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells["IDColumn"].Value.ToString());*/
            ProductExport productExportItem = new ProductExport(
                 (int)parseCell(0,e.RowIndex,"IDColumn"),
                 productItem,
                 parseCell(0,e.RowIndex,"AmountColumn"),
                 unitItem,
                 description,
                 monthItem,
                 year,
                 lastDeadline
            );

            if (rowError) return;
            if (rowsAdded)
            {
                Status = "Přidávám novou položku...";
                ProductExports.Add(productExportItem);
                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.Rows[dataGridView1.NewRowIndex].ReadOnly = false;
                dataGridView1.Rows[dataGridView1.NewRowIndex].DefaultCellStyle = dataGridView1.DefaultCellStyle;
                refresh();
            }
            else
            {
                if (items[e.RowIndex] != productExportItem)
                {
                    Status = "Provádím úpravy...";
                    ProductExports.Change(productExportItem);
                    if (!connector.IsConnected()) return;
                }
            }
            rowsAdded = false;
            Status = ".....";
        }