示例#1
0
 public void Add(ProductExport item)
 {
     Add(item.Product, item.Amount, item.Unit, item.Description, item.Month, item.Year, item.Deadline);
 }
示例#2
0
 public void Change(ProductExport item)
 {
     _SQL.RunQuery(String.Format("UPDATE `{0}` SET ID_PRODUCT={1}, AMOUNT={2}, ID_UNIT={3}, DESCRIPTION='{4}', ID_DEADLINE={5} WHERE ID={6};",
         _table, item.Product.ID, item.Amount, item.Unit.ID, item.Description.Replace("'", "''"), item.Deadline.ID, item.ID));
 }
示例#3
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 (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 = ".....";
        }