Exemple #1
0
 public void Change(Composition item)
 {
     _SQL.RunQuery(String.Format("UPDATE `{0}` SET ID_PRODUCT={1}, ID_MATERIALTYPE={2}, AMOUNT={3}, ID_UNIT={4} WHERE ID={5};",
         _table, item.Product.ID, item.MaterialType.ID, item.Amount.ToString().Replace(',', '.'), item.Unit.ID, item.ID));
 }
        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 (MaterialTypes == null) return;
            if (Compositions == 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 (dataGridView1.Rows[e.RowIndex].Cells[collumn].Value.ToString() == "") {
                    dataGridView1.Rows[e.RowIndex].Cells[collumn].Value = "0";
                }
                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;
                }
            }

            MaterialType materialTypeItem;
            if (dataGridView1.Rows[e.RowIndex].Cells["MaterialTypeColumn"].Value == null) return;
            else
            {
                materialTypeItem = getMaterialType(dataGridView1.Rows[e.RowIndex].Cells["MaterialTypeColumn"].Value.ToString());
            }

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

            int id = 0;
            if (!rowsAdded) id = items[e.RowIndex].ID;/* id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells["IDColumn"].Value.ToString());*/
            Composition compositionItem = new Composition(
                 (int)parseCell(0,e.RowIndex,"IDColumn"),
                 EditedProduct,
                 materialTypeItem,
                 parseCell(0,e.RowIndex,"AmountColumn"),
                 unitItem
            );

            if (rowError) return;
            if (rowsAdded)
            {
                Status = "Přidávám novou položku...";
                Compositions.Add(compositionItem);
                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] != compositionItem)
                {
                    Status = "Provádím úpravy...";
                    Compositions.Change(compositionItem);
                    if (!connector.IsConnected()) return;
                }
            }
            rowsAdded = false;
            Status = ".....";
        }
Exemple #3
0
 public void Add(Composition item)
 {
     Add(item.Product, item.MaterialType, item.Amount, item.Unit);
 }