Esempio n. 1
0
 public void Change(Material item)
 {
     /*
     String courseDateString = String.Format("{0:0000}-{1:00}-{2:00}", item.CourseDate.Year, item.CourseDate.Month, item.CourseDate.Day);
     if (courseDateString == "0001-01-01")
         courseDateString = "0000-00-00";
     */
     String queryString = String.Format("UPDATE `{0}` SET NAME='{1}', PRICE={2}, AMOUNT={3}, ID_COMPANY={4}, INVOICE_NUMBER={5}, ID_UNIT={6}, ID_MATERIALTYPE={7}, MONTH={8}, YEAR={9}, CURRENCY={10}, SHIPPINGDATE='{11}', COURSEDATE='{12}', COURSE={13}, SHIPPINGPRICE={14}, ID_DEADLINE={16} WHERE ID={15};",
         _table, item.Name.Replace("'", "''"), item.Price.ToString().Replace(',', '.'), item.Amount.ToString().Replace(',', '.'), item.Company.ID, item.InvoiceNumber, item.Unit.ID, item.MaterialType.ID, item.Month.ID, item.Year, item.Currency.ID, DateTimeUtils.DateTimeToSQLDate(item.ShippingDate), DateTimeUtils.DateTimeToSQLDate(item.CourseDate), item.Course.ToString().Replace(',', '.'), item.ShippingPrice.ToString().Replace(',', '.'), item.ID, item.Deadline.ID);
     _SQL.RunQuery(queryString);
 }
Esempio n. 2
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 = ".....";
        }
Esempio n. 3
0
 private float CountTotalPrice(Material item)
 {
     float totalPrice = item.Price;
     if (item.ShippingPrice != 0)
     {
         if (item.Course != 0)
         {
             totalPrice = (item.ShippingPrice / item.Course) + item.Price;
         }
     }
     return totalPrice;
 }
Esempio n. 4
0
 public void Add(Material item)
 {
     Add(item.Name, item.Price, item.Amount, item.Company, item.InvoiceNumber, item.Unit, item.MaterialType, item.Month, item.Year, item.Currency, item.ShippingDate, item.CourseDate, item.Course, item.ShippingPrice, item.Deadline);
 }