Ejemplo n.º 1
0
 public Shipping(int id, String name, float price, ShippingType shippingType, float capacity)
 {
     ID = id;
     Name = name;
     Price = price;
     ShippingType = shippingType;
     Capacity = capacity;
 }
Ejemplo 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 (shippingTypes == 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;
                }
            }
            ShippingType shippingTypeItem = new ShippingType(0, "");
            if (dataGridView1.Rows[e.RowIndex].Cells["ShippingTypeColumn"].Value != null)
                shippingTypeItem = getShippingType(dataGridView1.Rows[e.RowIndex].Cells["ShippingTypeColumn"].Value.ToString());
            if (shippingTypeItem.ID == 0) return;

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

            float price = 0;
            if ((dataGridView1.Rows[e.RowIndex].Cells["PriceColumn"].Value != null) && (dataGridView1.Rows[e.RowIndex].Cells["PriceColumn"].Value.ToString()!=""))
                price = float.Parse(dataGridView1.Rows[e.RowIndex].Cells["PriceColumn"].Value.ToString());
            else return;

            float capacity = 0;
            if ((dataGridView1.Rows[e.RowIndex].Cells["CapacityColumn"].Value != null) && (dataGridView1.Rows[e.RowIndex].Cells["CapacityColumn"].Value.ToString() != ""))
                capacity = float.Parse(dataGridView1.Rows[e.RowIndex].Cells["CapacityColumn"].Value.ToString());
            else return;

            if (name == "") return;

            int id = 0;
            if (!rowsAdded) id = items[e.RowIndex].ID;/* id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells["IDColumn"].Value.ToString());*/
            Shipping ShippingItem = new Shipping(
                 (int)parseCell(0,e.RowIndex,"IDColumn"),
                 name,
                 price,
                 shippingTypeItem,
                 capacity
            );

            if (rowError) return;
            if (rowsAdded)
            {
                Status = "Přidávám novou položku...";
                Shippings.Add(ShippingItem);
                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] != ShippingItem)
                {
                    Status = "Provádím úpravy...";
                    Shippings.Change(ShippingItem);
                    if (!connector.IsConnected()) return;
                }
            }
            rowsAdded = false;
            Status = ".....";
        }
Ejemplo n.º 3
0
 public void Add(String Name, float Price, ShippingType ShippingType, float Capacity)
 {
     SQL.RunQuery(String.Format("INSERT INTO `{0}` VALUES(default,'{1}',{2},{3},{4});", Table, Name.Replace("'", "''"), Price, ShippingType.ID, Capacity));
 }
Ejemplo n.º 4
0
 public void Change(ShippingType item)
 {
     SQL.RunQuery(String.Format("UPDATE `{0}` SET NAME='{1}' WHERE ID={2};", Table, item.Name.Replace("'", "''"), item.ID));
 }