private void btnSaveContainer_Click(object sender, EventArgs e) { if (!IsAllRequiredTextFilled() || (cmbCtr3.Text.Trim() == string.Empty)) { MessageBox.Show("لطفا همه فیلدها را پر کنید"); ActiveControl = cmbBlNo; return; } try { //Save or Edit Ctr CTRViewModel ctr = new CTRViewModel { txt1 = "CTR", BolRef = int.Parse(cmbBlNo.SelectedValue.ToString()), BolNo = cmbBlNo.Text, txt2 = txtCtr1.Text, txt3 = txtCtr2.Text, txt4 = lblCtr3.Text, txt5 = txtCtr4.Text }; if (ContainerEditID == 0) { CTR.Insert(ctr); } else //Update { ctr.ID = int.Parse(dgvContainer.CurrentRow.Cells["ID"].Value.ToString()); CTR.Update(ctr); cmbBlNo.Enabled = true; } //Empty All Textboxes foreach (Control c in gbContainer.Controls) { if (c is TextBox) { c.Text = string.Empty; } } cmbCtr3.Text = ""; txtCtr4.Text = "0"; progressBar3.Value = 50; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { dgvContainer.DataSource = CTR.GetAllData(); RefreshCTR_cmb(); btnSaveContainer.Text = "ذخیره کانتینر"; ContainerEditID = 0; gbKalaStatus(); } }
public static string[] WriteCtr(CTRViewModel _ct) { string[] _c = new string[5]; _c[0] = _ct.txt1; _c[1] = _ct.txt2; _c[2] = _ct.txt3; _c[3] = _ct.txt4; _c[4] = _ct.txt5; return(_c.AddQutation()); }
public static bool Update(CTRViewModel _ctr) { try { using (IDbConnection db = new SQLiteConnection(DataAccess.GetConnectionString())) { string query = "UPDATE CTR SET BolRef =@BolRef, BolNo =@BolNo, txt1 =@txt1, txt2 =@txt2, txt3 =@txt3, txt4 =@txt4, txt5 =@txt5 where ID=@ID"; db.Execute(query, _ctr); } return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }
public static bool Insert(CTRViewModel _ctr) { try { using (IDbConnection db = new SQLiteConnection(DataAccess.GetConnectionString())) { string query = "INSERT INTO CTR (BOLRef, BolNo, txt1, txt2, txt3, txt4, txt5) VALUES(@BOLRef, @BolNo, @txt1, @txt2, @txt3, @txt4, @txt5)"; db.Execute(query, _ctr); } return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }
private void btnSave_Click(object sender, EventArgs e) { if (!IsAllRequiredTextFilled() || (cmb08.Text.Trim() == string.Empty)) { MessageBox.Show("لطفا همه فیلدها را پر کنید"); ActiveControl = cmbBlNo; return; } try { //Save or Edit Ctr CTRViewModel ctr = new CTRViewModel { ID = 1, txt1 = "CTR", BolRef = int.Parse(cmbBlNo.SelectedValue.ToString()), txt2 = chkFake.Checked ? "FAKE123456-1" : txtCtr1.Text, txt3 = txtCtr2.Text, txt4 = lblCtr3.Text, txt5 = txtCtr4.Text }; if (CTR.IsFirstRecord()) //Save { CTR.Insert(ctr); } else //Update { CTR.Update(ctr); } //============================= Save or Edit Cons ================================= CONNViewModel cons = new CONNViewModel { CTRRef = 1, BolRef = int.Parse(cmbBlNo.SelectedValue.ToString()), BolNo = cmbBlNo.Text, txt1 = "CON", txt2 = txt01.Text, txt3 = txt02.Text, txt4 = txt03.Text, txt6 = txt05.Text, txt7 = txt06.Text, txt8 = cmb08.Text, txt9 = cmb07.Text, txt10 = txt09.Text, txt11 = txt10.Text, txt12 = txt11.Text, txt13 = cmb12.Text, txt19 = cmb18.Text, }; if (EditID == 0)//Save { CONN.Insert(cons); } else //Edit { cons.ID = int.Parse(dgv.CurrentRow.Cells["ID"].Value.ToString()); CONN.Update(cons); } //Empty All Textboxes foreach (Control c2 in TabPage1.Controls) { if (c2 is TextBox) { c2.Text = string.Empty; } } //Refresh dgv dgv.DataSource = null; dgv.DataSource = CONN.GetAllDataSortedByBolNo(); EditID = 0; btnSave.Text = "دخیره کالا"; } catch (Exception ex) { MessageBox.Show(ex.Message); } }