public static bool Update(VOYViewModel _voy) { try { using (IDbConnection db = new SQLiteConnection(DataAccess.GetConnectionString())) { string query = "UPDATE VOY SET txt1 =@txt1, txt2 =@txt2, txt3 =@txt3, txt4 =@txt4, txt5 =@txt5, txt6 =@txt6, txt7 =@txt7, txt8 =@txt8, txt9 =@txt9, txt10 =@txt10, txt11 =@txt11 where ID=@ID"; db.Execute(query, _voy); } return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); throw; } }
public static bool Insert(VOYViewModel _voy) { try { using (IDbConnection db = new SQLiteConnection(DataAccess.GetConnectionString())) { string query = "INSERT INTO VOY (ID, txt1, txt2, txt3, txt4, txt5, txt6, txt7, txt8, txt9, txt10, txt11) VALUES(@ID, @txt1, @txt2, @txt3, @txt4, @txt5, @txt6, @txt7, @txt8, @txt9, @txt10, @txt11)"; db.Execute(query, _voy); } return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); System.Windows.Forms.MessageBox.Show(ex.Message); return(false); throw; } }
public static string[] WriteVOY(VOYViewModel _v) { string[] _str = new string[11]; _str[0] = _v.txt1; _str[1] = _v.txt2; _str[2] = _v.txt3; _str[3] = _v.txt4; _str[4] = _v.txt5; _str[5] = _v.txt6; _str[6] = _v.txt7; _str[7] = _v.txt8; _str[8] = _v.txt9; _str[9] = _v.txt10; _str[10] = _v.txt11; ////Add double cotation //for (int i = 0; i < _str.Length; i++) //{ // _str[i] = "\"" + _str[i] + "\""; //} return(_str.AddQutation()); }
private void btnBolSave_Click(object sender, EventArgs e) { //========== Voy ==================== //Check empty textboxes if (!IsAllRequiredTextFilled()) { MessageBox.Show("لطفا همه فیلدها را پر کنید"); ActiveControl = txtVoy3; return; } //Check empty ComboBox if (!IsAllRequiredComboboxesFilled()) { MessageBox.Show("لطفا همه فیلدها را پر کنید"); ActiveControl = txtVoy3; return; } //Save or Edit VOY txtVoy3.Enabled = false; txtVoy4.Enabled = false; cmbVoy5.Enabled = false; txtVoy7.Enabled = false; dtVoy6.Enabled = false; txtVoy10.Enabled = false; try { //if (EditID == 0) //{ VOYViewModel _voy = new VOYViewModel { ID = 1, txt1 = "VOY", txt2 = txtVoy1.Text.Trim(), txt3 = txtVoy2.Text.Trim(), txt4 = (Mode == 3) ? cmbVoy3.Text : txtVoy3.Text.Trim(), txt5 = txtVoy4.Text.Trim(), txt6 = cmbVoy5.Text.Trim(), txt7 = dtVoy6.Text.Trim(), txt8 = "", txt9 = "MFI", txt10 = "0", txt11 = txtVoy10.Text.Trim() }; //There is just ONE Voyage so... if (VOY.GetAllData().Count == 0) { VOY.Insert(_voy); } else { VOY.Update(_voy); } //WriteClass.WriteToFile("tt", WriteClass.WriteVOY(VOY.GetById(1))); //} //Save or Edit BOL BOLViewModel _bol = new BOLViewModel { txt1 = "BOL", txt2 = txt01.Text, txt3 = txt02.Text, txt4 = txt03.Text, txt5 = cmb04.Text, txt6 = cmb05.Text, txt7 = cmb06.Text, txt8 = cmb07.Text, txt9 = dt08.Text, txt10 = "", txt11 = "I", txt12 = "S", txt13 = "", txt14 = "", txt15 = "G", txt16 = "N", txt17 = "D", txt18 = cmb17.Text, txt19 = cmb18.Text, txt20 = txt19.Text, txt21 = txt20.Text, txt22 = txt21.Text, txt23 = txt22.Text, txt24 = "", txt25 = "", txt26 = "", txt27 = txt27.Text, txt28 = txt26.Text, txt29 = "", txt30 = txt29.Text, txt31 = "-", txt32 = txt31.Text, txt33 = "", txt34 = txt33.Text, txt35 = txt34.Text, txt36 = "", txt37 = "", txt38 = "", txt39 = "", txt40 = "", txt41 = "", txt42 = "-", txt43 = "00000000", txt44 = "", txt45 = txt44.Text, txt46 = "-", txt47 = txt44.Text, txt48 = "", txt49 = "", txt50 = "", txt51 = txt50.Text, txt52 = "", txt53 = "0", txt54 = txt53.Text, txt55 = "", txt56 = "", txt57 = "", txt58 = "", txt59 = cmb58.Text, txt60 = "", txt61 = "", txt62 = "", }; if (EditID == 0) { BOL.Insert(_bol); } else { _bol.ID = EditID; BOL.Update(_bol); EditID = 0; btnBolSave.Text = "ذخیره بارنامه"; } Properties.Settings.Default.FileName = txtVoy10.Text; Properties.Settings.Default.Save(); //Empty All Textboxes foreach (Control c2 in TabPage1.Controls) { if (c2 is TextBox) { c2.Text = string.Empty; } if (c2 is ComboBox) { c2.Text = string.Empty; } } txt02.Text = txtVoy1.Text; cmbVoy3.Enabled = false; SetDefaults(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //Refresh dgv dgv.DataSource = null; dgv.DataSource = BOL.GetAllData(); } }