public bool InsertMesureCodes(MesureC MesureCs) { bool ignoreres = true; bool cancelling = false; using (SqlConnection con = ConexionSQL.Cadenaconexion("ATX_POS")) { try { con.Open(); SqlCommand command = new SqlCommand(); command.Parameters.Clear(); command.Connection = con; command.CommandText = ("Select COUNT(ItemMeasure) from MeasureItem where ItemMeasure = @CodeMesureNav"); command.Parameters.AddWithValue("@CodeMesureNav", MesureCs.Code.ToString()); int Exist = (int)command.ExecuteScalar();// command.ExecuteNonQuery().ToString(); if (Exist == 0) { command.Parameters.Clear(); command.CommandText = ("Insert into MeasureItem(IdItemMeausere,ItemMeasure,Description, DateInserted) values(@IdItemMeausere,@ItemCodeNav, @DesciptionNAV, @DatePosted)"); command.Parameters.AddWithValue("@IdItemMeausere", MesureCs.Code.ToString()); command.Parameters.AddWithValue("@ItemCodeNav", MesureCs.Code.ToString()); command.Parameters.AddWithValue("@DesciptionNAV", MesureCs.Description.ToString()); //command.Parameters.AddWithValue("@InternationalCode", MesureCs.International_Standard_Code.ToString()); command.Parameters.AddWithValue("@DatePosted", DateWork); command.ExecuteScalar(); } else if (Exist != 0) { if (continueprocess) { if (remplaceall == false) { YesAllNoAll yestoall = new YesAllNoAll(); DialogResult resultYesall = yestoall.ShowDialog(); if (resultYesall == DialogResult.Cancel) { continueprocess = false; cancelling = true; } if (resultYesall == DialogResult.Yes) { remplaceall = true; } if (resultYesall == DialogResult.Ignore) { ignoreres = false; } if (resultYesall == DialogResult.OK) { yesone = true; } if (resultYesall == DialogResult.No) { noall = true; cancelling = true; } } if (continueprocess) { if (noall == false) { if (remplaceall && (noall == false)) { command.Parameters.Clear(); command.CommandText = ("UPDATE MeasureItem set ItemMeasure = @ItemCodeNav, Description = @DesciptionNAV, LastModify = @DateModify where IdItemMeausere = @ItemCodeNav"); //command.CommandText = ("Insert into MeasureItem(ItemMeasure,Description,International_Code) values(@ItemCodeNav, @DesciptionNAV, @InternationalCode)"); command.Parameters.AddWithValue("@ItemCodeNav", MesureCs.Code.ToString()); command.Parameters.AddWithValue("@DesciptionNAV", MesureCs.Description.ToString()); //command.Parameters.AddWithValue("@InternationalCode", MesureCs.International_Standard_Code.ToString()); command.Parameters.AddWithValue("@DateModify", DateWork); command.ExecuteScalar(); } else if (yesone && ignoreres && (noall == false)) { command.Parameters.Clear(); command.CommandText = ("UPDATE MeasureItem set ItemMeasure = @ItemCodeNav, Description = @DesciptionNAV, LastModify = @DateModify where IdItemMeausere = @ItemCodeNav"); //command.CommandText = ("Insert into MeasureItem(ItemMeasure,Description,International_Code) values(@ItemCodeNav, @DesciptionNAV, @InternationalCode)"); command.Parameters.AddWithValue("@ItemCodeNav", MesureCs.Code.ToString()); command.Parameters.AddWithValue("@DesciptionNAV", MesureCs.Description.ToString()); //command.Parameters.AddWithValue("@InternationalCode", MesureCs.International_Standard_Code.ToString()); command.Parameters.AddWithValue("@DateModify", DateWork); command.ExecuteScalar(); } } } } } con.Close(); } catch (SqlException sqlex) { MessageBox.Show(sqlex.Message); } catch (WebException webex) { MessageBox.Show(webex.Message); } } return(cancelling); }
private bool InsertItemPrice(PriceItems PI) { bool ignoreres = true; bool cancelling = false; using (SqlConnection con = ConexionSQL.Cadenaconexion("ATX_POS")) { con.Open(); SqlCommand command = new SqlCommand(); command.Parameters.Clear(); command.Connection = con; try { if (PI.Bar_Code != null) { command.CommandText = ("Select BarCode from Items where BarCode = @CodeRefNAV"); command.Parameters.AddWithValue("@CodeRefNAV", PI.Bar_Code); string Exist = (string)command.ExecuteScalar(); if (Exist == null) { command.Parameters.Clear(); command.CommandText = "Insert into Items(ItemName,ItemCode,Barcode,Price,IdMeasure,LastDateModified,[VAT Prod_ Posting Group],NoCodeNAV) values(@ItemName, @ItemCode,@Barcode,@Price,(select IdItemMeausere from MeasureItem where ItemMeasure=@IdMeasure),@LastDateModified,@VATPG,@NoCodeNAV)"; string vatIvaGrup = ""; string NameDescription = GetItemNameDescrip(PI.Item_No, ref vatIvaGrup); command.Parameters.AddWithValue("@ItemName", NameDescription); command.Parameters.AddWithValue("@ItemCode", PI.Bar_Code); command.Parameters.AddWithValue("@BarCode", PI.Bar_Code); command.Parameters.AddWithValue("@Price", PI.Unit_Price); command.Parameters.AddWithValue("@IdMeasure", PI.Unit_of_Measure_Code); command.Parameters.AddWithValue("@LastDateModified", DateWork); command.Parameters.AddWithValue("@NoCodeNAV", PI.Item_No); command.Parameters.AddWithValue("@VATPG", vatIvaGrup); //command.Parameters.AddWithValue("@Alias","" ); //command.Parameters.AddWithValue("@NameBankNav", PI.Name.ToString()); command.ExecuteScalar(); } else if (Exist != null) { if (continueprocess) { if (remplaceall == false) { YesAllNoAll yestoall = new YesAllNoAll(); DialogResult resultYesall = yestoall.ShowDialog(); if (resultYesall == DialogResult.Cancel) { continueprocess = false; cancelling = true; } if (resultYesall == DialogResult.Yes) { remplaceall = true; } if (resultYesall == DialogResult.Ignore) { ignoreres = false; } if (resultYesall == DialogResult.OK) { yesone = true; } if (resultYesall == DialogResult.No) { noall = true; cancelling = true; } } if (continueprocess) { if (remplaceall && (noall == false)) { command.Parameters.Clear(); command.CommandText = ("UPDATE Items set Price = @Price, IdMeasure =(select IdItemMeausere from MeasureItem where ItemMeasure = @ItemMeasure), LastDateModified = @LastDateModified where BarCode = @BarCode"); command.Parameters.AddWithValue("@Price", PI.Unit_Price); command.Parameters.AddWithValue("@ItemMeasure", PI.Unit_of_Measure_Code); command.Parameters.AddWithValue("@LastDateModified", DateWork); command.Parameters.AddWithValue("@BarCode", PI.Bar_Code); command.ExecuteScalar(); } else if (yesone && ignoreres && (noall == false)) { command.Parameters.Clear(); command.CommandText = ("UPDATE Items set Price = @Price, IdMeasure =(select IdItemMeausere from MeasureItem where ItemMeasure = @ItemMeasure), LastDateModified = @LastDateModified where BarCode = @BarCode"); command.Parameters.AddWithValue("@Price", PI.Unit_Price); command.Parameters.AddWithValue("@ItemMeasure", PI.Unit_of_Measure_Code); command.Parameters.AddWithValue("@LastDateModified", DateWork); command.Parameters.AddWithValue("@BarCode", PI.Bar_Code); command.ExecuteScalar(); } } } } con.Close(); } } catch (SqlException sqlex) { MessageBox.Show(sqlex.Message); } catch (WebException webex) { MessageBox.Show(webex.Message); } } return(cancelling); }