Wednesday, December 29, 2010
Sunday, November 14, 2010
Category and SubCategory Add
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Admin_SubCategoryManagement : System.Web.UI.Page
{
DAL dal = new DAL();
protected void Page_Load(object sender, EventArgs e)
{
if (Request["i"] != null)
{
if (Request["i"].ToString() == "1")
{
td_gridder.Visible = false;
td_editter.Visible = true;
}
else if (Request["i"].ToString() == "2")
{
td_gridder.Visible = true;
td_editter.Visible = false;
}
}
else
{
Response.Redirect("Default.aspx");
}
if (!IsPostBack)
{
dal.FillCombo(ddl_Category, "ProductCategory_Master_Sp 's'", "Category", "PK_ID", "--select Category--", 0);
}
if (ViewState["PK_ID"] != null)
{
btn_edit.Visible = true;
btn_save.Visible = false;
}
else
{
btn_edit.Visible = false;
btn_save.Visible = true;
}
}
protected void ddl_Category_Indexchanged(object sender, EventArgs e)
{
if (ddl_Category.SelectedIndex != 0)
{
dal.FillGrid(grd_News, "ProductSubCategroy_Master_Sp 's','','" + ddl_Category.SelectedValue + "'");
}
else
{
grd_News.DataSource = null;
grd_News.DataBind();
}
}
protected void btn_save_Click(object sender, EventArgs e)
{
if (ddl_Category.SelectedIndex != 0)
{
dal.PutData("ProductSubCategroy_Master_Sp 'i','','" + ddl_Category.SelectedValue + "','" + txt_title.Text + "'");
dal.FillGrid(grd_News, "ProductSubCategroy_Master_Sp 's','','" + ddl_Category.SelectedValue + "'");
}
}
protected void btn_edit_Click(object sender, EventArgs e)
{
dal.PutData("ProductSubCategroy_Master_Sp 'u','" + ViewState["PK_ID"] + "','" + ddl_Category.SelectedValue + "','" + txt_title.Text + "'");
dal.FillGrid(grd_News, "ProductSubCategroy_Master_Sp 's','','" + ddl_Category.SelectedValue + "'");
ControlClear();
btn_edit.Visible = false;
btn_save.Visible = true;
td_gridder.Visible = true;
td_editter.Visible = false;
}
private void ControlClear()
{
txt_title.Text = string.Empty;
ViewState["PK_ID"] = null;
}
protected void btn_cancel_Click(object sender, EventArgs e)
{
ControlClear();
}
protected void btn_grd_delete_click(object sender, CommandEventArgs e)
{
dal.PutData("ProductSubCategroy_Master_Sp 'd','" + e.CommandArgument.ToString() + "'");
dal.FillGrid(grd_News, "ProductSubCategroy_Master_Sp 's','','" + ddl_Category.SelectedValue + "'");
}
protected void btn_grd_edit_click(object sender, CommandEventArgs e)
{
ViewState["PK_ID"] = e.CommandArgument.ToString();
DataTable dt = new DataTable();
dt = dal.GetDataTable("ProductSubCategroy_Master_Sp 'e','" + ViewState["PK_ID"].ToString() + "'");
txt_title.Text = dt.Rows[0]["SubCategory"].ToString();
btn_edit.Visible = true;
btn_save.Visible = false;
td_gridder.Visible = false;
td_editter.Visible = true;
}
}
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Admin_SubCategoryManagement : System.Web.UI.Page
{
DAL dal = new DAL();
protected void Page_Load(object sender, EventArgs e)
{
if (Request["i"] != null)
{
if (Request["i"].ToString() == "1")
{
td_gridder.Visible = false;
td_editter.Visible = true;
}
else if (Request["i"].ToString() == "2")
{
td_gridder.Visible = true;
td_editter.Visible = false;
}
}
else
{
Response.Redirect("Default.aspx");
}
if (!IsPostBack)
{
dal.FillCombo(ddl_Category, "ProductCategory_Master_Sp 's'", "Category", "PK_ID", "--select Category--", 0);
}
if (ViewState["PK_ID"] != null)
{
btn_edit.Visible = true;
btn_save.Visible = false;
}
else
{
btn_edit.Visible = false;
btn_save.Visible = true;
}
}
protected void ddl_Category_Indexchanged(object sender, EventArgs e)
{
if (ddl_Category.SelectedIndex != 0)
{
dal.FillGrid(grd_News, "ProductSubCategroy_Master_Sp 's','','" + ddl_Category.SelectedValue + "'");
}
else
{
grd_News.DataSource = null;
grd_News.DataBind();
}
}
protected void btn_save_Click(object sender, EventArgs e)
{
if (ddl_Category.SelectedIndex != 0)
{
dal.PutData("ProductSubCategroy_Master_Sp 'i','','" + ddl_Category.SelectedValue + "','" + txt_title.Text + "'");
dal.FillGrid(grd_News, "ProductSubCategroy_Master_Sp 's','','" + ddl_Category.SelectedValue + "'");
}
}
protected void btn_edit_Click(object sender, EventArgs e)
{
dal.PutData("ProductSubCategroy_Master_Sp 'u','" + ViewState["PK_ID"] + "','" + ddl_Category.SelectedValue + "','" + txt_title.Text + "'");
dal.FillGrid(grd_News, "ProductSubCategroy_Master_Sp 's','','" + ddl_Category.SelectedValue + "'");
ControlClear();
btn_edit.Visible = false;
btn_save.Visible = true;
td_gridder.Visible = true;
td_editter.Visible = false;
}
private void ControlClear()
{
txt_title.Text = string.Empty;
ViewState["PK_ID"] = null;
}
protected void btn_cancel_Click(object sender, EventArgs e)
{
ControlClear();
}
protected void btn_grd_delete_click(object sender, CommandEventArgs e)
{
dal.PutData("ProductSubCategroy_Master_Sp 'd','" + e.CommandArgument.ToString() + "'");
dal.FillGrid(grd_News, "ProductSubCategroy_Master_Sp 's','','" + ddl_Category.SelectedValue + "'");
}
protected void btn_grd_edit_click(object sender, CommandEventArgs e)
{
ViewState["PK_ID"] = e.CommandArgument.ToString();
DataTable dt = new DataTable();
dt = dal.GetDataTable("ProductSubCategroy_Master_Sp 'e','" + ViewState["PK_ID"].ToString() + "'");
txt_title.Text = dt.Rows[0]["SubCategory"].ToString();
btn_edit.Visible = true;
btn_save.Visible = false;
td_gridder.Visible = false;
td_editter.Visible = true;
}
}
Saturday, October 30, 2010
E-Mail Send - Resevie C# Code
using System; using System.Windows.Forms; using System.Net.Mail; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("your_email_address@gmail.com"); mail.To.Add("to_address@mfc.ae"); mail.Subject = "Test Mail"; mail.Body = "This is for testing SMTP mail from GMAIL"; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); MessageBox.Show("mail Send"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }
Send Email in C# Code
// create mail message object
MailMessage mail = new MailMessage();
mail.From = ""; // put the from address here
mail.To = ""; // put to address here
mail.Subject = ""; // put subject here
mail.Body = ""; // put body of email here
SmtpMail.SmtpServer = ""; // put smtp server you will use here
// and then send the mail
SmtpMail.Send(mail);
==================================================
String server = "127.0.0.1"; private void btnSend_Click(object sender, System.EventArgs e) { MailAddress to = new MailAddress("admin@.mail.adr"); MailAddress from = new MailAddress(txtFrom.Text); MailMessage message = new MailMessage(from, to); message.Subject = txtSubject.Text; message.Body = @"" txtContent.Value; SmtpClient client = new SmtpClient(server); try { client.Send(message); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
Other Example
using System; using System.Text; using System.Net.Mail; using System.Net; namespace TestingConsole { class Program { static void Main(string[] args) { try { string to = "to@domain.com"; string from = "from@gmail.com"; string from_pwd = "mypassword"; string subject = "Sample Mail testing"; string body = "Wow this is testing body"; MailMessage mM = new MailMessage(); mM.From = new MailAddress(from); mM.To.Add(to); mM.Subject = subject; mM.Body = body; mM.IsBodyHtml = false; mM.Priority = MailPriority.High; SmtpClient sC = new SmtpClient("smtp.gmail.com"); sC.Port = 587; sC.Credentials = new NetworkCredential(from,from_pwd); sC.EnableSsl = true; sC.Send(mM); } catch (Exception e) { Console.WriteLine(e.Message + " " + e.StackTrace); } } } }
Out Of Date Change UserName and Password
PasswordExpires, Part I
public class PasswordExpires { DomainPolicy policy; const int UF_DONT_EXPIRE_PASSWD = 0x10000; public PasswordExpires() { //get our current domain policy Domain domain = Domain.GetCurrentDomain(); DirectoryEntry root = domain.GetDirectoryEntry(); using (domain) using (root) { this.policy = new DomainPolicy(root); } }
PasswordExpires, Part II
public DateTime GetExpiration(DirectoryEntry user) { int flags = (int)user.Properties["userAccountControl"][0]; //check to see if password is set to expire if(Convert.ToBoolean(flags & UF_DONT_EXPIRE_PASSWD)) { //the user’s password will never expire return DateTime.MaxValue; } long ticks = GetInt64(user, "pwdLastSet"); //user must change password at next login if (ticks == 0) return DateTime.MinValue; //password has never been set if (ticks == -1) { throw new InvalidOperationException( "User does not have a password" ); } //get when the user last set their password; DateTime pwdLastSet = DateTime.FromFileTime( ticks ); //use our policy class to determine when //it will expire return pwdLastSet.Add( this.policy.MaxPasswordAge ); }
PasswordExpires, Part III
public TimeSpan GetTimeLeft(DirectoryEntry user) { DateTime willExpire = GetExpiration(user); if (willExpire == DateTime.MaxValue) return TimeSpan.MaxValue; if (willExpire == DateTime.MinValue) return TimeSpan.MinValue; if (willExpire.CompareTo(DateTime.Now) > 0) { //the password has not expired //(pwdLast + MaxPwdAge)- Now = Time Left return willExpire.Subtract(DateTime.Now); } //the password has already expired return TimeSpan.MinValue; } private Int64 GetInt64(DirectoryEntry entry, string attr) { //we will use the marshaling behavior of //the searcher DirectorySearcher ds = new DirectorySearcher( entry, String.Format("({0}=*)", attr), new string[] { attr }, SearchScope.Base ); SearchResult sr = ds.FindOne(); if (sr != null) { if (sr.Properties.Contains(attr)) { return (Int64)sr.Properties[attr][0]; } } return -1; }
Checking Password Expiration
string adsPath = "LDAP://CN=User1,OU=Users,DC=domain,DC=com"; DirectoryEntry user = new DirectoryEntry( adsPath, null, null, AuthenticationTypes.Secure ); string attrib = "msDS-User-Account-Control-Computed"; using (user) { user.RefreshCache(new string[] { attrib }); int flags = (int)user.Properties[attrib].Value & (int)AdsUserFlags.PasswordExpired); if (Convert.ToBoolean(flags) { //password has expired Console.WriteLine("Expired"); } }
Login Password Case-Sensitive
private void btnlogin_Click(object sender, EventArgs e)
{
login();
}
private void ClearFields()
{
txtusername.Text = String.Empty;
txtpwd.Text = String.Empty;
}
private void btncancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtpwd_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
login();
}
}
private void login()
{
try
{
ConnectionClass l_ConnectionClass = new ConnectionClass();
DataSet l_UserDataSet = l_ConnectionClass.FetchDataInDataSet("select * from tbluserlogin where userName = '" + txtusername.Text.ToLower().Trim() + "' and userPwd = '" + txtpwd.Text.Trim() + "'");
if (l_UserDataSet.Tables[0].Rows.Count > 0)
{
PublicVariables.CheckLoginFlag = true;
PublicVariables.OSUserID = Convert.ToInt16(l_UserDataSet.Tables[0].Rows[0]["userId"]);
PublicVariables.UserRole = l_UserDataSet.Tables[0].Rows[0]["userRole"].ToString();
DateTime getdatefrm = l_ConnectionClass.getlogouttime();
DateTime datenow = DateTime.Now;
if ((getdatefrm.AddMinutes(0) > datenow) && (getdatefrm != DateTime.MinValue))
{
MessageBox.Show("please wait");
ClearFields();
PublicVariables.CheckLoginFlag = false;
}
else
{
l_ConnectionClass.updateuserlogin();
Close();
this.Hide();
}
}
else
{
MessageBox.Show("Login Failed !!!!", "Error", MessageBoxButtons.OK);
PublicVariables.CheckLoginFlag = false;
txtusername.Text = "";
txtpwd.Text = "";
txtusername.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show("Connection Failed. Plz Check your Network Cable Connection", "Error", MessageBoxButtons.OK);
}
}
private void txtusername_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
txtpwd.Focus();
}
}
{
login();
}
private void ClearFields()
{
txtusername.Text = String.Empty;
txtpwd.Text = String.Empty;
}
private void btncancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtpwd_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
login();
}
}
private void login()
{
try
{
ConnectionClass l_ConnectionClass = new ConnectionClass();
DataSet l_UserDataSet = l_ConnectionClass.FetchDataInDataSet("select * from tbluserlogin where userName = '" + txtusername.Text.ToLower().Trim() + "' and userPwd = '" + txtpwd.Text.Trim() + "'");
if (l_UserDataSet.Tables[0].Rows.Count > 0)
{
PublicVariables.CheckLoginFlag = true;
PublicVariables.OSUserID = Convert.ToInt16(l_UserDataSet.Tables[0].Rows[0]["userId"]);
PublicVariables.UserRole = l_UserDataSet.Tables[0].Rows[0]["userRole"].ToString();
DateTime getdatefrm = l_ConnectionClass.getlogouttime();
DateTime datenow = DateTime.Now;
if ((getdatefrm.AddMinutes(0) > datenow) && (getdatefrm != DateTime.MinValue))
{
MessageBox.Show("please wait");
ClearFields();
PublicVariables.CheckLoginFlag = false;
}
else
{
l_ConnectionClass.updateuserlogin();
Close();
this.Hide();
}
}
else
{
MessageBox.Show("Login Failed !!!!", "Error", MessageBoxButtons.OK);
PublicVariables.CheckLoginFlag = false;
txtusername.Text = "";
txtpwd.Text = "";
txtusername.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show("Connection Failed. Plz Check your Network Cable Connection", "Error", MessageBoxButtons.OK);
}
}
private void txtusername_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
txtpwd.Focus();
}
}
Thursday, October 14, 2010
Sql Connection String Examples
Using C#:
using System.Data.SqlClient; ... SqlConnection oSQLConn = new SqlConnection(); oSQLConn.ConnectionString = "Data Source=(local);" + "Initial Catalog=mySQLServerDBName;" + "Integrated Security=yes"; oSQLConn.Open();
If connection to a remote server (via IP address):
oSQLConn.ConnectionString = "Network Library=DBMSSOCN;" & _ "Data Source=xxx.xxx.xxx.xxx,1433;" & _ "Initial Catalog=mySQLServerDBName;" & _ "User ID=myUsername;" & _ "Password=myPassword" Where: - "Network Library=DBMSSOCN" tells SqlConnection to use TCP/IP Q238949
- xxx.xxx.xxx.xxx is an IP address.
- 1433 is the default port number for SQL Server. Q269882 and Q287932
- You can also add "Encrypt=yes" for encryption
Connection String Examples
Data source | Example | Description |
---|---|---|
SQL Server database on the local server | data source="(local)";initial catalog=AdventureWorks | Set data source type to SQL Server. |
SQL Server instance database | Data Source=localhost\MSSQL10_50.InstanceName; Initial Catalog= AdventureWorks | Set data source type to SQL Server. |
SQL Server Express database | Data Source=localhost\MSSQL10_50.SQLEXPRESS; Initial Catalog= AdventureWorks | Set data source type to SQL Server. |
Analysis Services database on the local server | data source=localhost;initial catalog=Adventure Works DW | Set data source type to SQL Server Analysis Services. |
SharePoint List | data source=http://MySharePointWeb/MySharePointSite/ | Set data source type to SharePoint List. |
SQL Server 2000 Analysis Services server | provider=MSOLAP.2;data source= | Set the data source type to OLE DB Provider for OLAP Services 8.0. You can achieve a faster connection to SQL Server 2000 Analysis Services data sources if you set the ConnectTo property to 8.0. To set this property, use the Connection Properties dialog box, Advanced Properties tab. |
Report Models | Not applicable. | You do not need a connection string for a report model. In Report Builder, browse to the report server and select the .smdl file that is the report model. |
Oracle server | data source=myserver | Set the data source type to Oracle. The Oracle client tools must be installed on the Report Builder computer and on the report server. |
SAP NetWeaver BI data source | DataSource=http://mySAPNetWeaverBIServer:8000/sap/bw/xml/soap/xmla | Set the data source type to SAP NetWeaver BI. |
Hyperion Essbase data source | Data Source=http://localhost:13080/aps/XMLA; Initial Catalog=Sample | Set the data source type to Hyperion Essbase. |
Teradata data source | data source= | Set the data source type to Teradata. The connection string is an Internet Protocol (IP) address in the form of four fields, where each field can be from one to three digits. |
Teradata data source | Database= | Set the data source type to Teradata, similar to the previous example. Only use the default database that is specified in the Database tag, and do not automatically discover data relationships. |
XML data source, Web service | data source=http://adventure-works.com/results.aspx | Set the data source type to XML. The connection string is a URL for a web service that supports Web Services Definition Language (WSDL). |
XML data source, XML document | http://localhost/XML/Customers.xml | Set the data source type to XML. The connection string is a URL to the XML document. |
XML data source, embedded XML document | Empty | Set the data source type to XML. The XML data is embedded in the report definition. |
Thursday, September 23, 2010
Tuesday, September 21, 2010
Date Select On Show DataGridView
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
DateTime dt = new DateTime();
dt = Convert.ToDateTime(dateTimePicker1.Value.ToShortDateString());
SqlCommand cmd = new SqlCommand();
string sqlqry = "select mbrchrg AS MemberCharge,costumechrg AS CostumerCharge,Date from swimpool where Date = '" + dt + "'";
dataGridView1.DataSource = "";
cmd.CommandText = sqlqry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "swimpool");
dataGridView1.DataSource = ds.Tables["swimpool"].DefaultView;
-------------------------------------------------------------------------
namespace HotelManagement
{
public partial class User_Record : Form
{
Dbclass db = new Dbclass();
string common;
public User_Record()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void User_Record_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string str = "select Addmminisator,User_Id,User_Type,User_Name,User_Password from user_master";
dt = db.FindFun(str);
grduser_record.DataSource = dt;
totalrecord.Text = Convert.ToInt32(grduser_record.Rows.Count - 1).ToString();
}
private void btnpreview_Click(object sender, EventArgs e)
{
Crstluser_master use = new Crstluser_master();
Frmviewr view = new Frmviewr();
DataTable dt = new DataTable();
string str = " Select * from user_Master";
dt = db.FindFun(str);
use.SetDataSource(dt);
view.crstlviewer.ReportSource = use;
view.Show();
}
}
}
SqlConnection con = new SqlConnection(constring);
DateTime dt = new DateTime();
dt = Convert.ToDateTime(dateTimePicker1.Value.ToShortDateString());
SqlCommand cmd = new SqlCommand();
string sqlqry = "select mbrchrg AS MemberCharge,costumechrg AS CostumerCharge,Date from swimpool where Date = '" + dt + "'";
dataGridView1.DataSource = "";
cmd.CommandText = sqlqry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "swimpool");
dataGridView1.DataSource = ds.Tables["swimpool"].DefaultView;
-------------------------------------------------------------------------
namespace HotelManagement
{
public partial class User_Record : Form
{
Dbclass db = new Dbclass();
string common;
public User_Record()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void User_Record_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string str = "select Addmminisator,User_Id,User_Type,User_Name,User_Password from user_master";
dt = db.FindFun(str);
grduser_record.DataSource = dt;
totalrecord.Text = Convert.ToInt32(grduser_record.Rows.Count - 1).ToString();
}
private void btnpreview_Click(object sender, EventArgs e)
{
Crstluser_master use = new Crstluser_master();
Frmviewr view = new Frmviewr();
DataTable dt = new DataTable();
string str = " Select * from user_Master";
dt = db.FindFun(str);
use.SetDataSource(dt);
view.crstlviewer.ReportSource = use;
view.Show();
}
}
}
Thursday, September 16, 2010
Wednesday, September 8, 2010
Datagridview Data Print
/ dataGridView1 is the DataGridView to print
GridPrintDocument doc = new GridPrintDocument(this.dataGridView1,
this.dataGridView1.Font, true);
doc.DocumentName = "Preview Test";
doc.DefaultPageSettings.Landscape = true;
doc.DefaultPageSettings.PrinterSettings.FromPage = 1;
doc.DefaultPageSettings.PrinterSettings.ToPage = 3;
PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();
printPreviewDialog.ClientSize = new Size(400, 300);
printPreviewDialog.Location = new Point(29, 29);
printPreviewDialog.Name = "Print Preview Dialog";
printPreviewDialog.UseAntiAlias = true;
printPreviewDialog.Document = doc;
printPreviewDialog.ShowDialog();
doc.Dispose();
doc = null;
Saturday, September 4, 2010
Static DroupDownList Us In DataGridView
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace Bar_nd_Hotel
{
public partial class SearchAll : Form
{
DAL obj = new DAL();
DataTable dt = new DataTable();
public SearchAll()
{
InitializeComponent();
}
private void SearchAll_Load(object sender, EventArgs e)
{
}
private void btnsearch_Click(object sender, EventArgs e)
{
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string selectval = Cmboselectitem.SelectedItem.ToString();
if (selectval == "Staff Details")
{
//string qry = "";
SqlCommand cmd = new SqlCommand();
string sqlqry = "Select * from crtstaff ";
if (txtname.Text != "")
{
sqlqry += "where stfname = '" + txtname.Text + "' ";
}
else if (txtpost.Text != "")
{
sqlqry += "where post = '" + txtpost.Text + "' ";
}
else if (txtsalary.Text != "")
{
sqlqry += "where salary='" + txtsalary.Text + "'";
}
else if (txtmobileno.Text != "")
{
sqlqry += "where mobile_no='" + txtmobileno.Text + "'";
}
else if (dateTimePicker1.Value.ToShortDateString() != "")
{
sqlqry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
}
Searchgrid.DataSource = "";
cmd.CommandText = sqlqry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "crtstaff");
Searchgrid.DataSource = ds.Tables["crtstaff"].DefaultView;
}
if (selectval == "Salary Details")
{
string sqlry = "Select * from salarystatus ";
if (txtname.Text != "")
{
sqlry += "where stfname = '" + txtname.Text + "' ";
}
else if (txtworkdays.Text != "")
{
sqlry += "where workdays ='" + txtworkdays.Text + "' ";
}
else if (chkdueamount.Checked == true)
{
sqlry += "where dueamt != '' and dueamt != '0'";
}
else if (chkpaidamount.Checked == true)
{
sqlry += "where paidamt !='' and paidamt != '0'";
}
else if (chkabsent.Checked == true)
{
sqlry += "where absent !='' and absent != '0'";
}
else if (chkdayshift.Checked == true)
{
sqlry += "where dayshift !='' and dayshift != '0'";
}
else if (chknight.Checked == true)
{
sqlry += "where nightshift !='' and nightshift != '0'";
}
else if (dateTimePicker1.Value.ToShortDateString() != "")
{
sqlry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
}
SqlCommand cmd = new SqlCommand();
Searchgrid.DataSource = "";
cmd.CommandText = sqlry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "salarystatus");
Searchgrid.DataSource = ds.Tables["salarystatus"].DefaultView;
}
}
private void Cmboselectitem_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace Bar_nd_Hotel
{
public partial class SearchAll : Form
{
DAL obj = new DAL();
DataTable dt = new DataTable();
public SearchAll()
{
InitializeComponent();
}
private void SearchAll_Load(object sender, EventArgs e)
{
}
private void btnsearch_Click(object sender, EventArgs e)
{
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string selectval = Cmboselectitem.SelectedItem.ToString();
if (selectval == "Staff Details")
{
//string qry = "";
SqlCommand cmd = new SqlCommand();
string sqlqry = "Select * from crtstaff ";
if (txtname.Text != "")
{
sqlqry += "where stfname = '" + txtname.Text + "' ";
}
else if (txtpost.Text != "")
{
sqlqry += "where post = '" + txtpost.Text + "' ";
}
else if (txtsalary.Text != "")
{
sqlqry += "where salary='" + txtsalary.Text + "'";
}
else if (txtmobileno.Text != "")
{
sqlqry += "where mobile_no='" + txtmobileno.Text + "'";
}
else if (dateTimePicker1.Value.ToShortDateString() != "")
{
sqlqry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
}
Searchgrid.DataSource = "";
cmd.CommandText = sqlqry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "crtstaff");
Searchgrid.DataSource = ds.Tables["crtstaff"].DefaultView;
}
if (selectval == "Salary Details")
{
string sqlry = "Select * from salarystatus ";
if (txtname.Text != "")
{
sqlry += "where stfname = '" + txtname.Text + "' ";
}
else if (txtworkdays.Text != "")
{
sqlry += "where workdays ='" + txtworkdays.Text + "' ";
}
else if (chkdueamount.Checked == true)
{
sqlry += "where dueamt != '' and dueamt != '0'";
}
else if (chkpaidamount.Checked == true)
{
sqlry += "where paidamt !='' and paidamt != '0'";
}
else if (chkabsent.Checked == true)
{
sqlry += "where absent !='' and absent != '0'";
}
else if (chkdayshift.Checked == true)
{
sqlry += "where dayshift !='' and dayshift != '0'";
}
else if (chknight.Checked == true)
{
sqlry += "where nightshift !='' and nightshift != '0'";
}
else if (dateTimePicker1.Value.ToShortDateString() != "")
{
sqlry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
}
SqlCommand cmd = new SqlCommand();
Searchgrid.DataSource = "";
cmd.CommandText = sqlry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "salarystatus");
Searchgrid.DataSource = ds.Tables["salarystatus"].DefaultView;
}
}
private void Cmboselectitem_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Thursday, August 26, 2010
Wednesday, August 25, 2010
Friday, August 20, 2010
Thursday, August 19, 2010
Crystal Report
public void FillCrystalReports(string strStoredProc, string CRPPath, CrystalReportViewer CRPViewer)
{
CRPPath=System.Web.HttpContext.Current.Server.MapPath(CRPPath);
try
{
SqlDataAdr = new SqlDataAdapter(strStoredProc, SqlConn);
SqlDataAdr.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlDataAdr.SelectCommand.CommandTimeout = 0;
ds = new DataSet();
ds.Locale = CultureInfo.InvariantCulture;
SqlDataAdr.Fill(ds);
ReportDocument Rep = new ReportDocument();
//Rep.SetDatabaseLogon("sa", "sa", ".", "SchoolDB");
Rep.Load(CRPPath);
Rep.SetDataSource(ds.Tables[0]);
CRPViewer.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
CRPViewer.ReportSource = Rep;
if (ds.Tables[0].Rows.Count == 0)
{
CRPViewer.Visible = false;
msgboxcs.MessageBox.Show("No Records Available");
}
}
catch (Exception ex)
{
msgboxcs.MessageBox.Show(ex.Message);
}
}
}
Print Crystal Reports
{
CRPPath=System.Web.HttpContext.Current.Server.MapPath(CRPPath);
try
{
SqlDataAdr = new SqlDataAdapter(strStoredProc, SqlConn);
SqlDataAdr.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlDataAdr.SelectCommand.CommandTimeout = 0;
ds = new DataSet();
ds.Locale = CultureInfo.InvariantCulture;
SqlDataAdr.Fill(ds);
ReportDocument Rep = new ReportDocument();
//Rep.SetDatabaseLogon("sa", "sa", ".", "SchoolDB");
Rep.Load(CRPPath);
Rep.SetDataSource(ds.Tables[0]);
CRPViewer.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
CRPViewer.ReportSource = Rep;
if (ds.Tables[0].Rows.Count == 0)
{
CRPViewer.Visible = false;
msgboxcs.MessageBox.Show("No Records Available");
}
}
catch (Exception ex)
{
msgboxcs.MessageBox.Show(ex.Message);
}
}
}
Print Crystal Reports
using System; using System.Windows.Forms; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ReportDocument cryRpt = new ReportDocument(); cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt"); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); Tables CrTables; crConnectionInfo.ServerName = "YOUR SERVERNAME"; crConnectionInfo.DatabaseName = "DATABASE NAME"; crConnectionInfo.UserID = "USERID"; crConnectionInfo.Password = "PASSWORD"; CrTables = cryRpt.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } cryRpt.Refresh(); cryRpt.PrintToPrinter(2, true, 1, 2); } } }
C# Crystal Report Print
crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage);private void button2_Click(object sender, System.EventArgs e) { //Open the PrintDialog this.printDialog1.Document = this.printDocument1; DialogResult dr = this.printDialog1.ShowDialog(); if(dr == DialogResult.OK) { //Get the Copy times int nCopy = this.printDocument1.PrinterSettings.Copies; //Get the number of Start Page int sPage = this.printDocument1.PrinterSettings.FromPage; //Get the number of End Page int ePage = this.printDocument1.PrinterSettings.ToPage; //Get the printer name string PrinterName = this.printDocument1.PrinterSettings.PrinterName; crReportDocument = new ReportDocument(); //Create an instance of a report crReportDocument = new Chart(); try { //Set the printer name to print the report to. By default the sample //report does not have a defult printer specified. This will tell the //engine to use the specified printer to print the report. Print out //a test page (from Printer properties) to get the correct value. crReportDocument.PrintOptions.PrinterName = PrinterName; //Start the printing process. Provide details of the print job //using the arguments. crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage); //Let the user know that the print job is completed MessageBox.Show("Report finished printing!"); } catch(Exception err) { MessageBox.Show(err.ToString()); } } }
Crystal Report Show to Date
DS1 dts = new DS1(); SqlConnection con = new SqlConnection("Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True"); try { DateTime dt = new DateTime(); dt = Convert.ToDateTime(dateTimePicker1.Value.ToShortDateString()); // SqlCommand cmd = new SqlCommand("SELECT * From JKL where Date='1/1/1900 12:00:00 AM' ", con); SqlCommand cmd = new SqlCommand("SELECT * From crtstaff where Date='" + dt + "'", con); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(dts.Tables["crtstaff"]); // DataTable dt = new DataTable("JKL"); // sda.Fill(dt); StaffDetails cr = new StaffDetails(); cr.SetDataSource(dts); crystalReportViewer1.ReportSource = cr; // cr.SetDataSource(dt); } catch (Exception ex) { } }
Wednesday, August 18, 2010
C#Program
Login Master
public partial class Login___Master : Form
{
Dbclass db = new Dbclass();
string common;
public Login___Master()
{
InitializeComponent();
}
private void btnlogin_in_Click(object sender, EventArgs e)
{
DataTable dt2 = new DataTable();
MDI objmdi = new MDI();
if (cmblogin_type.Text == "")
{
MessageBox.Show("Error 9001303991 : FillUp the Login Type", "Blank..........", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
if (btnlogin_in.Text == "Login")
{
//try
{
string str = "login,'" + cmblogin_type.Text + "','" + cmbuser_name.Text + "','" + txtpassword.Text + "'";
dt2=db.FindFun(str);
if (dt2.Rows.Count > 0)
{
objmdi.Show();
}
else
{
MessageBox.Show("invalid user", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
}
}
}
private void btnlogin_out_Click(object sender, EventArgs e)
{
MDI md = new MDI();
md.Close();
}
private void Login___Master_Load(object sender, EventArgs e)
{
Dbclass obj = new Dbclass();
// grpfind.Visible = true;
string str = "Select * from user_master";
obj.Fillcombo(cmblogin_type , "user_type", "unq_id", str);
obj.Fillcombo(cmbuser_name , "user_name", "unq_id", str);
}
}
}
----------------------------------------------------------------------
Message Show
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
if (!bClosing)
{
bClosing = true;
if (MessageBox.Show("Are sure You want to exit?", "Exit?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
{
e.Cancel = true;
}
else
{
e.Cancel = false;
}
}
else
{
bClosing = false;
}
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void searchAllToolStripMenuItem_Click(object sender, EventArgs e)
{
Search srch = new Search();
srch.Show();
}
private void searchReportToolStripMenuItem_Click(object sender, EventArgs e)
{
SearchStatus srchst = new SearchStatus();
srchst.Show();
}
}
}
------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Bar_nd_Hotel
{
public partial class crtVeg : Form
{
public crtVeg()
{
InitializeComponent();
}
AutoCompleteStringCollection codeCollection = new AutoCompleteStringCollection();
List<string> arraylistitm = new List<string>();
List<string> arraylistqty = new List<string>();
private void crtVeg_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'bar_dbDataSet3.category' table. You can move, or remove it, as needed.
this.categoryTableAdapter.Fill(this.bar_dbDataSet3.category);
// TODO: This line of code loads data into the 'bar_dbDataSet1.veg_category' table. You can move, or remove it, as needed.
//this.veg_categoryTableAdapter.Fill(this.bar_dbDataSet1.veg_category);
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string cmdstring = "select crt_categ from category where main_cat = 'Veg. Items'";
SqlCommand cmd = new SqlCommand(cmdstring, con);
con.Open();
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
vegcatcmb.Items.Add(dr["crt_categ"].ToString());
}
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "select distinct itm_code from crt_veg order by itm_code";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
con1.Open();
SqlDataReader dr1;
dr1 = cmd1.ExecuteReader();
if (dr1.HasRows == true)
{
while (dr1.Read())
{
codeCollection.Add(dr1["itm_code"].ToString());
}
}
dr1.Close();
vegcode.AutoCompleteMode = AutoCompleteMode.Suggest;
vegcode.AutoCompleteSource = AutoCompleteSource.CustomSource;
vegcode.AutoCompleteCustomSource = codeCollection;
}
private void button1_Click(object sender, EventArgs e)
{
arraylistitm.Add(itm1.Text);
arraylistitm.Add(itm2.Text);
arraylistitm.Add(itm3.Text);
arraylistitm.Add(itm4.Text);
arraylistitm.Add(itm5.Text);
arraylistitm.Add(itm6.Text);
arraylistitm.Add(itm7.Text);
arraylistitm.Add(itm8.Text);
arraylistitm.Add(itm9.Text);
arraylistitm.Add(itm10.Text);
arraylistqty.Add(qty1.Text);
arraylistqty.Add(qty2.Text);
arraylistqty.Add(qty3.Text);
arraylistqty.Add(qty4.Text);
arraylistqty.Add(qty5.Text);
arraylistqty.Add(qty6.Text);
arraylistqty.Add(qty7.Text);
arraylistqty.Add(qty8.Text);
arraylistqty.Add(qty9.Text);
arraylistqty.Add(qty10.Text);
int n = 0;
for (int j = 0; j < 10; j++)
{
if (arraylistitm[j].Length > 1)
{
n++;
}
}
for (int i = 0; i < n; i++)
{
if (i == 0)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm1.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm1.Text + "', '" +Convert.ToDateTime( DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name,date) values( '" + itm1.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "' ) ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 1)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm2.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm2.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "' ) ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name,date) values( '" + itm2.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 2)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm3.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm3.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm3.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 3)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm4.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm4.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm4.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 4)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm5.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm5.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm5.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 5)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm6.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm6.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm6.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 6)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm7.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm7.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm7.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 7)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm8.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm8.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm8.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 8)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm9.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm9.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm9.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 9)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm10.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm10.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm10.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
}
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string cmdstring = "insert into crt_veg (itm_categ,itm_name,itm_code,itm_amt,itm1,qty1,itm2,qty2,itm3,qty3,itm4,qty4,itm5,qty5,itm6,qty6,itm7,qty7,itm8,qty8,itm9,qty9,itm10,qty10) values( '" + vegcatcmb.Text + "','" + vegname.Text + "', '" + Convert.ToInt32(vegcode.Text) + "', '" + vegamt.Text + "', '" + itm1.Text + "', '" + qty1.Text + "','" + itm2.Text + "', '" + qty2.Text + "','" + itm3.Text + "', '" + qty3.Text + "','" + itm4.Text + "', '" + qty4.Text + "','" + itm5.Text + "', '" + qty5.Text + "','" + itm6.Text + "', '" + qty6.Text + "','" + itm7.Text + "', '" + qty7.Text + "','" + itm8.Text + "', '" + qty8.Text + "','" + itm9.Text + "', '" + qty9.Text + "','" + itm10.Text + "', '" + qty10.Text + "') ";
SqlCommand cmd = new SqlCommand(cmdstring, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
//for (int i = 0; i < n; i++)
//{
// string cmdstring1 = "insert into VegCntItems (itm_code,itm_name,itm_cnt_name,itm_cnt_qty,itm_amt) values( '" + vegcode.Text + "','" + vegname.Text + "' , '" + arraylistitm[i].ToString() + "', '" + arraylistqty[i].ToString() + "', '" + vegamt.Text + "') ";
// SqlCommand cmd1 = new SqlCommand(cmdstring1, con);
// con.Open();
// cmd1.ExecuteNonQuery();
// con.Close();
//}
MessageBox.Show("New Veg Items has Been Added Successfully ");
con.Close();
//vegcatcmb.Text = "";
//vegname.Text = "";
//vegcode.Text = "";
//vegamt.Text = "";
con.Close();
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string cmdstring = "update crt_veg set itm_name = '" + vegname.Text + "',itm_amt = '" + vegamt.Text + "', itm1 = '" + itm1.Text + "',qty1 = '" + qty1.Text + "', itm2 = '" + itm2.Text + "',qty2 = '" + qty2.Text + "', itm3 = '" + itm3.Text + "',qty3 = '" + qty3.Text + "', itm4 = '" + itm4.Text + "',qty4 = '" + qty4.Text + "', itm5 = '" + itm5.Text + "',qty5 = '" + qty5.Text + "', itm6 = '" + itm6.Text + "',qty6 = '" + qty6.Text + "', itm7 = '" + itm7.Text + "',qty7 = '" + qty7.Text + "', itm8 = '" + itm8.Text + "',qty8 = '" + qty8.Text + "', itm9 = '" + itm9.Text + "',qty9 = '" + qty9.Text + "' , itm10 = '" + itm10.Text + "',qty10 = '" + qty10.Text + "' where itm_categ = '" + vegcatcmb.Text + "' and itm_code = '" + vegcode.Text + "' ";
SqlCommand cmd = new SqlCommand(cmdstring, con);
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Item details has been Updated Successfully ");
con.Close();
//vegcatcmb.Text = "";
//vegname.Text = "";
//vegcode.Text = "";
//vegamt.Text = "";
con.Close();
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void qty6_TextChanged(object sender, EventArgs e)
{
}
private void vegcode_TextChanged(object sender, EventArgs e)
{
//int n = 0;
//string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
//SqlConnection con = new SqlConnection(constring);
//string cmdstring = "select itm_code from VegCntItems where itm_code = '" + vegcode.Text + "'";
//SqlCommand cmd = new SqlCommand(cmdstring, con);
//con.Open();
//SqlDataReader dr;
//dr = cmd.ExecuteReader();
//while (dr.Read())
//{
// n++;
//}
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "select * from crt_veg where itm_code = '" + vegcode.Text + "'";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
con1.Open();
SqlDataReader dr1;
dr1 = cmd1.ExecuteReader();
if (dr1.Read())
{
vegname.Text = dr1["itm_name"].ToString();
vegamt.Text = dr1["itm_amt"].ToString();
vegcatcmb.Text = dr1["itm_categ"].ToString();
itm1.Text = dr1["itm1"].ToString();
qty1.Text = dr1["qty1"].ToString();
itm2.Text = dr1["itm2"].ToString();
qty2.Text = dr1["qty2"].ToString();
itm3.Text = dr1["itm3"].ToString();
qty3.Text = dr1["qty3"].ToString();
itm4.Text = dr1["itm4"].ToString();
qty4.Text = dr1["qty4"].ToString();
itm5.Text = dr1["itm5"].ToString();
qty5.Text = dr1["qty5"].ToString();
itm6.Text = dr1["itm6"].ToString();
qty6.Text = dr1["qty6"].ToString();
itm7.Text = dr1["itm7"].ToString();
qty7.Text = dr1["qty7"].ToString();
itm8.Text = dr1["itm8"].ToString();
qty8.Text = dr1["qty8"].ToString();
itm9.Text = dr1["itm9"].ToString();
qty9.Text = dr1["qty9"].ToString();
itm10.Text = dr1["itm10"].ToString();
qty10.Text = dr1["qty10"].ToString();
}
else
{
vegname.Text = "";
vegamt.Text = "";
itm1.Text = "";
qty1.Text = "";
itm2.Text = "";
qty2.Text = "";
itm3.Text = "";
qty3.Text = "";
itm4.Text = "";
qty4.Text = "";
itm5.Text = "";
qty5.Text = "";
itm6.Text = "";
qty6.Text = "";
itm7.Text = "";
qty7.Text = "";
itm8.Text = "";
qty8.Text = "";
itm9.Text = "";
qty9.Text = "";
itm10.Text = "";
qty10.Text = "";
}
}
private void vegcatcmb_SelectedIndexChanged(object sender, EventArgs e)
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "select itm_code from crt_veg where itm_categ = '" + vegcatcmb.Text + "' ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
con1.Open();
SqlDataReader dr1;
dr1 = cmd1.ExecuteReader();
if (dr1.HasRows == true)
{
while (dr1.Read())
{
codeCollection.Add(dr1["itm_code"].ToString());
}
}
else
{
codeCollection.Clear();
}
dr1.Close();
vegcode.AutoCompleteMode = AutoCompleteMode.Suggest;
vegcode.AutoCompleteSource = AutoCompleteSource.CustomSource;
vegcode.AutoCompleteCustomSource = codeCollection;
}
}
}
public partial class Login___Master : Form
{
Dbclass db = new Dbclass();
string common;
public Login___Master()
{
InitializeComponent();
}
private void btnlogin_in_Click(object sender, EventArgs e)
{
DataTable dt2 = new DataTable();
MDI objmdi = new MDI();
if (cmblogin_type.Text == "")
{
MessageBox.Show("Error 9001303991 : FillUp the Login Type", "Blank..........", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
if (btnlogin_in.Text == "Login")
{
//try
{
string str = "login,'" + cmblogin_type.Text + "','" + cmbuser_name.Text + "','" + txtpassword.Text + "'";
dt2=db.FindFun(str);
if (dt2.Rows.Count > 0)
{
objmdi.Show();
}
else
{
MessageBox.Show("invalid user", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
}
}
}
private void btnlogin_out_Click(object sender, EventArgs e)
{
MDI md = new MDI();
md.Close();
}
private void Login___Master_Load(object sender, EventArgs e)
{
Dbclass obj = new Dbclass();
// grpfind.Visible = true;
string str = "Select * from user_master";
obj.Fillcombo(cmblogin_type , "user_type", "unq_id", str);
obj.Fillcombo(cmbuser_name , "user_name", "unq_id", str);
}
}
}
----------------------------------------------------------------------
Message Show
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
if (!bClosing)
{
bClosing = true;
if (MessageBox.Show("Are sure You want to exit?", "Exit?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
{
e.Cancel = true;
}
else
{
e.Cancel = false;
}
}
else
{
bClosing = false;
}
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void searchAllToolStripMenuItem_Click(object sender, EventArgs e)
{
Search srch = new Search();
srch.Show();
}
private void searchReportToolStripMenuItem_Click(object sender, EventArgs e)
{
SearchStatus srchst = new SearchStatus();
srchst.Show();
}
}
}
------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Bar_nd_Hotel
{
public partial class crtVeg : Form
{
public crtVeg()
{
InitializeComponent();
}
AutoCompleteStringCollection codeCollection = new AutoCompleteStringCollection();
List<string> arraylistitm = new List<string>();
List<string> arraylistqty = new List<string>();
private void crtVeg_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'bar_dbDataSet3.category' table. You can move, or remove it, as needed.
this.categoryTableAdapter.Fill(this.bar_dbDataSet3.category);
// TODO: This line of code loads data into the 'bar_dbDataSet1.veg_category' table. You can move, or remove it, as needed.
//this.veg_categoryTableAdapter.Fill(this.bar_dbDataSet1.veg_category);
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string cmdstring = "select crt_categ from category where main_cat = 'Veg. Items'";
SqlCommand cmd = new SqlCommand(cmdstring, con);
con.Open();
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
vegcatcmb.Items.Add(dr["crt_categ"].ToString());
}
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "select distinct itm_code from crt_veg order by itm_code";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
con1.Open();
SqlDataReader dr1;
dr1 = cmd1.ExecuteReader();
if (dr1.HasRows == true)
{
while (dr1.Read())
{
codeCollection.Add(dr1["itm_code"].ToString());
}
}
dr1.Close();
vegcode.AutoCompleteMode = AutoCompleteMode.Suggest;
vegcode.AutoCompleteSource = AutoCompleteSource.CustomSource;
vegcode.AutoCompleteCustomSource = codeCollection;
}
private void button1_Click(object sender, EventArgs e)
{
arraylistitm.Add(itm1.Text);
arraylistitm.Add(itm2.Text);
arraylistitm.Add(itm3.Text);
arraylistitm.Add(itm4.Text);
arraylistitm.Add(itm5.Text);
arraylistitm.Add(itm6.Text);
arraylistitm.Add(itm7.Text);
arraylistitm.Add(itm8.Text);
arraylistitm.Add(itm9.Text);
arraylistitm.Add(itm10.Text);
arraylistqty.Add(qty1.Text);
arraylistqty.Add(qty2.Text);
arraylistqty.Add(qty3.Text);
arraylistqty.Add(qty4.Text);
arraylistqty.Add(qty5.Text);
arraylistqty.Add(qty6.Text);
arraylistqty.Add(qty7.Text);
arraylistqty.Add(qty8.Text);
arraylistqty.Add(qty9.Text);
arraylistqty.Add(qty10.Text);
int n = 0;
for (int j = 0; j < 10; j++)
{
if (arraylistitm[j].Length > 1)
{
n++;
}
}
for (int i = 0; i < n; i++)
{
if (i == 0)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm1.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm1.Text + "', '" +Convert.ToDateTime( DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name,date) values( '" + itm1.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "' ) ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 1)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm2.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm2.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "' ) ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name,date) values( '" + itm2.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 2)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm3.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm3.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm3.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 3)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm4.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm4.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm4.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 4)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm5.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm5.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm5.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 5)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm6.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm6.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm6.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 6)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm7.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm7.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm7.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 7)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm8.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm8.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm8.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 8)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm9.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm9.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm9.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
if (i == 9)
{
string constring2 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con2 = new SqlConnection(constring2);
string cmdstring2 = "select cnt_name from itm_invntry where cnt_name = '" + itm10.Text + "' ";
SqlCommand cmd2 = new SqlCommand(cmdstring2, con2);
con2.Open();
SqlDataReader dr2;
dr2=cmd2.ExecuteReader();
if (dr2.Read())
{
}
else
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "insert into itm_invntry (cnt_name,date) values( '" + itm10.Text + "','" + Convert.ToDateTime(DateTime.Now.ToShortDateString()) + "') ";
//string cmdstring3 = "insert into daily_itm_invntry (cnt_name) values( '" + itm10.Text + "') ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
//SqlCommand cmd3 = new SqlCommand(cmdstring3, con1);
con1.Open();
cmd1.ExecuteNonQuery();
//cmd3.ExecuteNonQuery();
con1.Close();
}
}
}
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string cmdstring = "insert into crt_veg (itm_categ,itm_name,itm_code,itm_amt,itm1,qty1,itm2,qty2,itm3,qty3,itm4,qty4,itm5,qty5,itm6,qty6,itm7,qty7,itm8,qty8,itm9,qty9,itm10,qty10) values( '" + vegcatcmb.Text + "','" + vegname.Text + "', '" + Convert.ToInt32(vegcode.Text) + "', '" + vegamt.Text + "', '" + itm1.Text + "', '" + qty1.Text + "','" + itm2.Text + "', '" + qty2.Text + "','" + itm3.Text + "', '" + qty3.Text + "','" + itm4.Text + "', '" + qty4.Text + "','" + itm5.Text + "', '" + qty5.Text + "','" + itm6.Text + "', '" + qty6.Text + "','" + itm7.Text + "', '" + qty7.Text + "','" + itm8.Text + "', '" + qty8.Text + "','" + itm9.Text + "', '" + qty9.Text + "','" + itm10.Text + "', '" + qty10.Text + "') ";
SqlCommand cmd = new SqlCommand(cmdstring, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
//for (int i = 0; i < n; i++)
//{
// string cmdstring1 = "insert into VegCntItems (itm_code,itm_name,itm_cnt_name,itm_cnt_qty,itm_amt) values( '" + vegcode.Text + "','" + vegname.Text + "' , '" + arraylistitm[i].ToString() + "', '" + arraylistqty[i].ToString() + "', '" + vegamt.Text + "') ";
// SqlCommand cmd1 = new SqlCommand(cmdstring1, con);
// con.Open();
// cmd1.ExecuteNonQuery();
// con.Close();
//}
MessageBox.Show("New Veg Items has Been Added Successfully ");
con.Close();
//vegcatcmb.Text = "";
//vegname.Text = "";
//vegcode.Text = "";
//vegamt.Text = "";
con.Close();
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string cmdstring = "update crt_veg set itm_name = '" + vegname.Text + "',itm_amt = '" + vegamt.Text + "', itm1 = '" + itm1.Text + "',qty1 = '" + qty1.Text + "', itm2 = '" + itm2.Text + "',qty2 = '" + qty2.Text + "', itm3 = '" + itm3.Text + "',qty3 = '" + qty3.Text + "', itm4 = '" + itm4.Text + "',qty4 = '" + qty4.Text + "', itm5 = '" + itm5.Text + "',qty5 = '" + qty5.Text + "', itm6 = '" + itm6.Text + "',qty6 = '" + qty6.Text + "', itm7 = '" + itm7.Text + "',qty7 = '" + qty7.Text + "', itm8 = '" + itm8.Text + "',qty8 = '" + qty8.Text + "', itm9 = '" + itm9.Text + "',qty9 = '" + qty9.Text + "' , itm10 = '" + itm10.Text + "',qty10 = '" + qty10.Text + "' where itm_categ = '" + vegcatcmb.Text + "' and itm_code = '" + vegcode.Text + "' ";
SqlCommand cmd = new SqlCommand(cmdstring, con);
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Item details has been Updated Successfully ");
con.Close();
//vegcatcmb.Text = "";
//vegname.Text = "";
//vegcode.Text = "";
//vegamt.Text = "";
con.Close();
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void qty6_TextChanged(object sender, EventArgs e)
{
}
private void vegcode_TextChanged(object sender, EventArgs e)
{
//int n = 0;
//string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
//SqlConnection con = new SqlConnection(constring);
//string cmdstring = "select itm_code from VegCntItems where itm_code = '" + vegcode.Text + "'";
//SqlCommand cmd = new SqlCommand(cmdstring, con);
//con.Open();
//SqlDataReader dr;
//dr = cmd.ExecuteReader();
//while (dr.Read())
//{
// n++;
//}
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "select * from crt_veg where itm_code = '" + vegcode.Text + "'";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
con1.Open();
SqlDataReader dr1;
dr1 = cmd1.ExecuteReader();
if (dr1.Read())
{
vegname.Text = dr1["itm_name"].ToString();
vegamt.Text = dr1["itm_amt"].ToString();
vegcatcmb.Text = dr1["itm_categ"].ToString();
itm1.Text = dr1["itm1"].ToString();
qty1.Text = dr1["qty1"].ToString();
itm2.Text = dr1["itm2"].ToString();
qty2.Text = dr1["qty2"].ToString();
itm3.Text = dr1["itm3"].ToString();
qty3.Text = dr1["qty3"].ToString();
itm4.Text = dr1["itm4"].ToString();
qty4.Text = dr1["qty4"].ToString();
itm5.Text = dr1["itm5"].ToString();
qty5.Text = dr1["qty5"].ToString();
itm6.Text = dr1["itm6"].ToString();
qty6.Text = dr1["qty6"].ToString();
itm7.Text = dr1["itm7"].ToString();
qty7.Text = dr1["qty7"].ToString();
itm8.Text = dr1["itm8"].ToString();
qty8.Text = dr1["qty8"].ToString();
itm9.Text = dr1["itm9"].ToString();
qty9.Text = dr1["qty9"].ToString();
itm10.Text = dr1["itm10"].ToString();
qty10.Text = dr1["qty10"].ToString();
}
else
{
vegname.Text = "";
vegamt.Text = "";
itm1.Text = "";
qty1.Text = "";
itm2.Text = "";
qty2.Text = "";
itm3.Text = "";
qty3.Text = "";
itm4.Text = "";
qty4.Text = "";
itm5.Text = "";
qty5.Text = "";
itm6.Text = "";
qty6.Text = "";
itm7.Text = "";
qty7.Text = "";
itm8.Text = "";
qty8.Text = "";
itm9.Text = "";
qty9.Text = "";
itm10.Text = "";
qty10.Text = "";
}
}
private void vegcatcmb_SelectedIndexChanged(object sender, EventArgs e)
{
string constring1 = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con1 = new SqlConnection(constring1);
string cmdstring1 = "select itm_code from crt_veg where itm_categ = '" + vegcatcmb.Text + "' ";
SqlCommand cmd1 = new SqlCommand(cmdstring1, con1);
con1.Open();
SqlDataReader dr1;
dr1 = cmd1.ExecuteReader();
if (dr1.HasRows == true)
{
while (dr1.Read())
{
codeCollection.Add(dr1["itm_code"].ToString());
}
}
else
{
codeCollection.Clear();
}
dr1.Close();
vegcode.AutoCompleteMode = AutoCompleteMode.Suggest;
vegcode.AutoCompleteSource = AutoCompleteSource.CustomSource;
vegcode.AutoCompleteCustomSource = codeCollection;
}
}
}
Subscribe to:
Posts (Atom)