private bool GenerateID() { string strCol = "invoice_id"; //string strQuery = "SELECT DISTINCT " + strCol + " FROM " + m_strOrderTxn //+ " WHERE " //+ " 1 = 1 " //+ " AND " + m_strCustomerID + "=" + m_nCustomerID //; ////creating problem because invoice id can be duplicate of this ////if (chkWithDate.Checked == true) //{ // strQuery = strQuery // + " AND " + m_strOrderTxn + "." + m_strModifiedOn + " = '" + dtpDate.Value.ToString("yyyy-MM-dd") + "'"; //} string strQuery = SingletonSonar.Instance.OrderDistinctInvoiceSelectQuery( m_nCustomerID, dtpDate.Value.ToString("yyyy-MM-dd")); string strDataValue; strDataValue = dbConnect.GetDataValue(strQuery, strCol); if (String.IsNullOrEmpty(strDataValue) == false) { m_nInvoiceID = Convert.ToInt32(strDataValue); } else { strCol = "COL"; //strQuery = "SELECT COUNT(*) " + strCol + " FROM " + m_strTableInvoice; strQuery = SingletonSonar.Instance.OrderInvoiceColCountSelectQuery(); strDataValue = dbConnect.GetDataValue(strQuery, strCol); int nCount = Convert.ToInt32(strDataValue); if (nCount > 0) { //strQuery = "SELECT MAX(" + m_strID + ") " + strCol + " FROM " + m_strTableInvoice; strQuery = SingletonSonar.Instance.OrderInvoiceMaxIDSelectQuery(); strDataValue = dbConnect.GetDataValue(strQuery, strCol); int nInvoiceID = Convert.ToInt32(strDataValue); m_nInvoiceID = nInvoiceID + 1; } else { m_nInvoiceID = 1; } } return(true); }
private string GetDataValue(int nCategoryId) { //string strTableCategory = "category"; //string query = // " SELECT " // + m_strValue // + " FROM " + m_strTableName // + " JOIN " + strTableCategory // + " ON (" + m_strTableName + ".category_id = " + strTableCategory + ".id) " // + " WHERE " // + " 1 = 1 " // + " AND " + m_strTableName + "." + m_strModifiedOn + " = '" + m_strModifiedOnValue+"'" // + " AND " + strTableCategory + ".id " + "=" + nCategoryId // ; string query = SingletonSonar.Instance.SettingGetValueQuery(nCategoryId); string strDataValue; strDataValue = dbConnect.GetDataValue(query, m_strValue); return(strDataValue); }
private void btnSave_Click(object sender, EventArgs e) { bool bReturn = false; if (txtName.Text != "") { bReturn = true; } else { MessageBox.Show("Name sould not be empty"); } if (bReturn == true) { DialogResult dialogResult = MessageBox.Show("Your are trying to Insert record", "Insert", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { bReturn = true; } else if (dialogResult == DialogResult.No) { bReturn = false; } } if (bReturn == true) { //string strTableCategory = "category"; //string strQueryID = // " SELECT " // + m_strID // + " FROM " // + strTableCategory // + " WHERE " // + " 1 = 1 " // + " AND " + strTableCategory + "." + m_strType + " like '%" + cmbCategory.Text + "%'" // ; string strQueryID = SingletonSonar.Instance.ProductCategorySelectQuery(cmbCategory.Text); string strDataValue; strDataValue = dbConnect.GetDataValue(strQueryID, m_strID); int nID = Convert.ToInt32(strDataValue); //string strQuery = // "INSERT INTO " // + m_strTableName // + "(" // + m_strName + "," // + m_strDetails + "," // + m_strCategoryID // + ") VALUES(" // + "'" + txtName.Text + "', " // + "'" + txtDetails.Text + "', " // + nID // + ")"; string strQuery = SingletonSonar.Instance.ProductInsertQuery(txtName.Text, txtDetails.Text, nID); bReturn = dbConnect.Insert(strQuery); if (bReturn == true) { MessageBox.Show("Record inserted"); ClearData(); DisplayData(); } } }