You must Sign In to post a response.
  • Category: ASP.NET

    After end of the month i need to start the count from 1 in asp.net using c#

    in a textbox1 i show the data like this 13-1

    13 is date and 1 is 1st bill 13 is constant number and i use for loop for like (13-2) after the end of august i need 31-01 bill number i does know the last bill no after 31 august i need to start the 1-01 (september 1-((billno is)01).


    for example if the billno end at 450 i show it in textbox as (31-450)(31 is date ,450 is billno)

    my need is after 450 for loop show 451 .in september it show like this (1-451)...but my need is (1-01) in september
  • #761541
    Hello Selvi,

    Then you just have to do small work.

    Check current month's date and compare it to your date which is in textbox if it is not same means month has changed to make 0 to your bill number.

    Hope you understand.

    Let me know if your still not understood.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761542
    Hi Selvi,

    can you please share your piece of code.

    As per my understand the thread whenever date is "01" then change the bill no to "1" in coding side.

    Please share your code to provide some what better solution.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #761543
    Hi


    Create Table head
    (
    Id int primary key identity (1,1),
    BillNo varchar(50),
    EntryDate date
    )

    Select ID,BillNo,count(*) from head where CONVERT(varchar(12),Entrydate,101)=CONVERT(varchar(12),GetDate(),101) group by BillNo,id Order by ID Desc



    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebApplication2
    {
    public partial class WebForm11 : System.Web.UI.Page
    {

    string s = ConfigurationManager.AppSettings["s"].ToString();
    double m = 0;
    decimal RunningTotal = 0;
    int txtcount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    txtBarcode.Focus();
    txtSalesDate.Text = System.DateTime.Now.ToString("dd/MM/yyyy");
    txtBarcode.Attributes.Add("onkeypress", "return controlEnter('" + txtqty.ClientID + "', event)");
    cusname();
    countrname();
    SalesPersnname();
    txtbdate.Text = System.DateTime.Now.ToString();
    txtsalestime.Text = System.DateTime.Now.ToString("hh:MM");
    }
    }
    private void BindListView()
    {
    string constr = ConfigurationManager.AppSettings["s"].ToString();
    DataTable products = new DataTable();
    using (SqlConnection con = new SqlConnection(constr))
    {
    using (SqlCommand cmd = new SqlCommand())
    {
    using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
    {
    cmd.CommandText = "SELECT distinct sectionname,lotno,Productname,mrp,supplierename,sizee from purchasedummy where lotno='" + txtBarcode.Text +

    "'";
    cmd.Connection = con;
    //Old Code
    DataTable dt = new DataTable();
    sda.Fill(dt);
    //Old Code
    //DataTable products = new DataTable();
    //sda.Fill(products);

    if (ViewState["Products"] == null)
    {
    ViewState["Products"] = dt;
    products.Merge(dt, true);
    ddsales.DataSource = products;
    ddsales.DataBind();

    }
    else
    {
    //products = (DataTable)ViewState["Products"];
    products = (DataTable)ViewState["Products"];
    products.Merge(dt, true);
    }
    ddsales.DataSource = products;
    ddsales.DataBind();
    if (dt.Rows.Count == 0) { Response.Write("<script>alert('Stock is Zero Please Enter Correct Barcode No !')</script>"); } else { Calc(); }
    }
    }
    txtBarcode.Text = "";

    }
    }
    protected void txtBarcode_TextChanged(object sender, EventArgs e)
    {
    ddsales.Visible = true;
    BindListView();
    //if (e.KeyCode ==13)
    //{
    //txtbillamountcash.Focus();
    //}

    //Old Calc
    //DataTable dt1;
    //dt1 = (DataTable)ViewState["Products"];
    //if (dt1.Rows.Count != 0)
    //{
    // float sum = 0;
    // for (int i = 0; i < dt1.Rows.Count; i++)
    // {
    // sum += float.Parse(dt1.Rows[i]["mrp"].ToString());
    // txtbillamountcash.Text = Convert.ToString(sum);
    // }
    //}
    }
    protected void txtqty_TextChanged(object sender, EventArgs e)
    {
    //foreach (GridViewRow rowz in ddsales.Rows)
    //{
    // GridViewRow row = ddsales.Rows[ddsales.Rows.Count - 1];
    // double mr, wt, totlrp;
    // mr = Convert.ToDouble((rowz.FindControl("lblmrp") as Label).Text);
    // wt = double.Parse(txtqty.Text);
    // totlrp = mr * wt;
    // (rowz.FindControl("lblmrp") as Label).Text = Convert.ToString(totlrp);
    //}
    //txtqty.Text = "1";

    }

    protected void ddsales_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    //Old Calc
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(ddsales, "Select$" + e.Row.RowIndex);
    // e.Row.ToolTip = "Click to select this row.";
    // DataTable dtst1;
    // dtst1 = (DataTable)ViewState["Products"];
    // if (dtst1.Rows.Count != 0)
    // {
    // float bilamnt = 0;
    // for (int i = 0; i < dtst1.Rows.Count; i++)
    // {
    // bilamnt += float.Parse(dtst1.Rows[i]["mrp"].ToString());
    // txtbillamountcash.Text = Convert.ToString(bilamnt);
    // }
    // }
    }
    }
    protected void ddsales_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    }
    protected void ddsales_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    DataTable dt = (DataTable)ViewState["Products"];
    dt.Rows.RemoveAt(e.RowIndex);
    ViewState["Products"] = dt;
    ddsales.DataSource = dt;
    ddsales.DataBind();
    if (dt.Rows.Count == 0)
    {
    txtbillamountcash.Text = "";
    }
    Calc();
    //DataTable dtt1;
    //dtt1 = (DataTable)ViewState["Products"];
    //if (dtt1.Rows.Count != 0)
    //{
    // float bilamt = 0;
    // for (int i = 0; i < dtt1.Rows.Count; i++)
    // {
    // bilamt += float.Parse(dtt1.Rows[i]["mrp"].ToString());
    // txtbillamountcash.Text = Convert.ToString(bilamt);
    // }

    //}
    }

    protected void btRemove_Click(object sender, EventArgs e)
    {
    // DataTable dt = (DataTable)ViewState["Products"];
    // ViewState["Products"] = dt;
    // ddsales.DataSource = null;
    // ddsales.DataBind();
    // dt.Clear();
    Calc();
    }

    protected void chkSelect_CheckedChanged(object sender, EventArgs e)
    {
    DataTable dtProd = new DataTable();
    foreach (GridViewRow gvr in this.ddsales.Rows)
    {
    if (((CheckBox)gvr.FindControl("chkSelect")).Checked == true)
    {
    string bqno = (gvr.FindControl("lblmrp") as Label).Text;
    // Session.Remove("bqno");
    dtProd = ViewState["Products"] as DataTable;
    dtProd.Rows.Remove(dtProd.Rows[gvr.RowIndex]);
    //dt.Rows.Remove(dt.Rows[2]);
    Session["Products"] = dtProd;
    }
    }
    ddsales.DataSource = dtProd;
    ddsales.DataBind();
    Calc();
    }

    protected void ddsales_PreRender(object sender, EventArgs e)
    {
    }
    protected void txtdispr_TextChanged(object sender, EventArgs e)
    {
    if (txtdispr.Text != "")
    {
    foreach (GridViewRow gvr in this.ddsales.Rows)
    {
    if (((CheckBox)gvr.FindControl("chkSelect")).Checked == true)
    {
    string bqno = (gvr.FindControl("lblmrp") as Label).Text;
    double dis, mmr, pmr, totdis, nowdis;
    dis = int.Parse(txtdispr.Text);
    mmr = int.Parse(bqno);
    pmr = dis * mmr;
    totdis = pmr / 100;
    nowdis = mmr - totdis;
    (gvr.FindControl("lblmrp") as Label).Text = Convert.ToString(nowdis);
    }
    txtdispr.Text = "";
    break;
    }
    BindListView();
    }
    else
    {
    txtdispr.Focus();
    }
    }
    protected void ddsales_RowCreated(object sender, GridViewRowEventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    Session.Remove("Products");
    ddsales.Visible = false;
    }
    public void SalesPersnname()
    {
    ListItem lk1 = new ListItem();
    lk1.Value = "--Select--";
    ddSalesPerson.Items.Add(lk1.ToString());
    ddSalesPerson.Items.Add("Saranya");
    ddSalesPerson.Items.Add("Ponni");
    ddSalesPerson.Items.Add("Haffiz");
    }
    public void countrname()
    {
    ListItem lissi1 = new ListItem();
    lissi1.Value = "--Select--";
    ddCounterName.Items.Add(lissi1.ToString());
    ddCounterName.Items.Add("Counter1");
    ddCounterName.Items.Add("Counter2");
    ddCounterName.Items.Add("Counter3");
    }
    public void cusname()
    {
    ListItem lsi1 = new ListItem();
    lsi1.Value = "--Select--";
    ddCustomerName.Items.Add(lsi1.ToString());
    ddCustomerName.Items.Add("New Customer");
    ddCustomerName.Items.Add("Riyaz");
    ddCustomerName.Items.Add("Queens");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
    SqlConnection conn = new SqlConnection(GetConnectionString());
    SqlCommand sqlcmd1 = null;
    DataTable dt = new DataTable();
    //SqlDataAdapter sqladp = new SqlDataAdapter("Select ID,BillNo,count(*) from head where CONVERT(varchar(12),Entrydate,101)=CONVERT(varchar(12),GetDate

    (),101) group by BillNo,id Order by ID Desc", conn);
    SqlDataAdapter sqladp = new SqlDataAdapter("Select ID,BillNo,count(*) from head where Month(EntryDate)=month(Getdate()) group by BillNo,id Order by ID

    Desc", conn);
    sqladp.Fill(dt);
    int BillNo = 0;
    if (dt.Rows.Count == 0)
    {
    BillNo = 1;
    sqlcmd1 = new SqlCommand("Insert into head values('" + BillNo.ToString() + "','" + DateTime.Now.ToString("MM/dd/yyyy") + "')", conn);
    }
    else
    {
    BillNo = Convert.ToInt32(dt.Rows[0][1]) + 1;
    sqlcmd1 = new SqlCommand("Insert into head values('" + BillNo.ToString() + "', '" + DateTime.Now.ToString("MM/dd/yyyy") + "')", conn);
    }
    conn.Open();
    sqlcmd1.ExecuteNonQuery();
    conn.Close();


    int rowIndex = 0;
    StringCollection sc = new StringCollection();
    if (ViewState["Products"] != null)
    {
    int saleno = int.Parse(txtsalesno.Text);
    string saldate = Convert.ToDateTime(txtSalesDate.Text).ToString("MM/dd/yyyy");
    string ddcnt = ddCounterName.Text;
    int prvsbil = int.Parse(txtPreviosBillamount.Text);
    string salprs = ddSalesPerson.Text;
    int txqty = int.Parse(txtqty.Text);
    float txrate = float.Parse(txtrate.Text);
    float disct = float.Parse(txtdispr.Text);
    float dsprs = float.Parse(txtdisrs.Text);
    float txtldis = float.Parse(txttotaldisct.Text);
    float ttldisrupe = float.Parse(txtdisrupes.Text);
    float custrles = float.Parse(txtcustrless.Text);
    float cashrecd = float.Parse(txtcashreceved.Text);
    float txbiamnt = float.Parse(txtbillamountcash.Text);
    float cbalance = float.Parse(txtbalnce.Text);
    //DateTime bdte = DateTime.ParseExact(txtbdate.Text, "dd/MM/yyyy HH:mm tt", null); //Convert.ToDateTime(txtbdate.Text);
    string bdte = Convert.ToDateTime(txtbdate.Text).ToString("MM/dd/yyyy");
    string cdte = System.DateTime.Now.ToString("MM/dd/yyyy");
    string saletme = txtsalestime.Text;
    DataTable dtCurrentTable = (DataTable)ViewState["Products"];
    DataRow drCurrentRow = null;
    if (dtCurrentTable.Rows.Count > 0)
    {
    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
    {
    Label box1 = (Label)ddsales.Rows[rowIndex].Cells[1].FindControl("lblsectn");
    Label box2 = (Label)ddsales.Rows[rowIndex].Cells[2].FindControl("lblproductname");
    Label box3 = (Label)ddsales.Rows[rowIndex].Cells[3].FindControl("lbllotno");
    Label box4 = (Label)ddsales.Rows[rowIndex].Cells[3].FindControl("lblmrp");
    Label box5 = (Label)ddsales.Rows[rowIndex].Cells[3].FindControl("lblsupliername");
    Label box6 = (Label)ddsales.Rows[rowIndex].Cells[3].FindControl("lblsizee");
    sc.Add(BillNo.ToString() + "," + saleno + "," + saldate + "," + ddcnt + "," + prvsbil + "," + salprs + "," + txqty + "," + txrate + "," + disct

    + "," + dsprs + "," + txtldis + "," + ttldisrupe + "," + custrles + "," + cbalance + "," + cashrecd + "," + bdte + "," + saletme + "," + box1.Text + "," + box2.Text +

    "," + box3.Text + "," + box4.Text + "," + txqty + "," + box5.Text + "," + box6.Text + "," + cdte);
    rowIndex++;
    }
    InsertRecords(sc);
    }
    }
    }
    private void InsertRecords(StringCollection sc)
    {
    SqlConnection conn = new SqlConnection(GetConnectionString());
    StringBuilder sb = new StringBuilder(string.Empty);
    string[] splitItems = null;


    foreach (string item in sc)
    {
    const string sqlStatement = "insert into sales

    (BillNo,salesno,salesdate,counername,previousbillamount,salesperson,qty,rate,singledisount,singlerupes,totaldiscount,totalrupes,customerless,balance,cashreceved,bdate,

    salestime,sectionname,productname,lotno,mrp,quantity,supplername,sizee,currentdate) VALUES";
    if (item.Contains(","))
    {
    splitItems = item.Split(",".ToCharArray());
    sb.AppendFormat("{0}

    ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}')

    ;", sqlStatement, splitItems[0], splitItems[1], splitItems[2], splitItems[3], splitItems[4], splitItems[5], splitItems[6], splitItems[7], splitItems[8], splitItems[9],

    splitItems[10], splitItems[11], splitItems[12], splitItems[13], splitItems[14], splitItems[15], splitItems[16], splitItems[17], splitItems[18], splitItems[19],

    splitItems[20], splitItems[21], splitItems[22], splitItems[23], splitItems[24]);
    }
    }
    try
    {
    conn.Open();
    SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
    cmd.CommandType = CommandType.Text;
    cmd.ExecuteNonQuery();
    Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Script", "alert('Records Successfuly Saved!');", true);
    }
    catch (System.Data.SqlClient.SqlException ex)
    {
    string msg = "Insert Error:";
    msg += ex.Message;
    throw new Exception(msg);
    }
    finally
    {
    conn.Close();
    }
    }
    private string GetConnectionString()
    {
    return System.Configuration.ConfigurationManager.AppSettings["s"].ToString();
    }



    private void Calc()
    {
    double foottotal = 0;
    foreach (GridViewRow dr in ddsales.Rows)
    {
    double price = Convert.ToDouble(((Label)dr.FindControl("lblmrp")).Text);
    //int Qty = int.Parse(((TextBox)dr.FindControl("txtQty")).Text);
    //double total = price * Qty;
    //((TextBox)dr.FindControl("lbltotal")).Text = Convert.ToString(total);
    foottotal = foottotal + price;
    }
    GridViewRow row = ddsales.FooterRow;
    ((Label)row.FindControl("Salary")).Text = Convert.ToString(foottotal);
    txtbillamountcash.Text = foottotal.ToString();
    }

    protected void ddsales_SelectedIndexChanged(object sender, EventArgs e)
    {
    foreach (GridViewRow row in ddsales.Rows)
    {
    if (row.RowIndex == ddsales.SelectedIndex)
    {
    row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
    row.ToolTip = string.Empty;
    float bilamt = 0;
    double mr, wt, totlrp, mpr, totl;
    mr = Convert.ToDouble((row.FindControl("lblmrp") as Label).Text);
    mpr = Convert.ToDouble((row.FindControl("lblmrp") as Label).Text);
    DataTable dtt1;
    dtt1 = (DataTable)ViewState["Products"];






    //Old Code
    //if (dtt1.Rows.Count != 0)
    //{

    // for (int i = 0; i < dtt1.Rows.Count; i++)
    // {
    // bilamt += float.Parse(dtt1.Rows[i]["mrp"].ToString());
    // // txtbillamountcash.Text = Convert.ToString(bilamt);

    // bilamt += float.Parse(dtt1.Rows[i]["mrp"].ToString());
    // if (txtqty.Text != "")
    // {
    // wt = double.Parse(txtqty.Text);
    // totlrp = mr * wt;
    // //totl = mr + totlrp ;
    // //(row.FindControl("lblmrp") as Label).Text = Convert.ToString(totl);
    // // txtbillamountcash.Text = Convert.ToString(totl);

    // txtbillamountcash.Text = Convert.ToString(totlrp);
    // }
    // else
    // {
    // }
    // }
    //}
    //Old Code
    }
    else
    {
    row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
    row.ToolTip = "Click to select this row.";
    }
    }
    }
    }
    }




    -- After Enter the Record Press Save Button Insert to Db header table Id=1,BillNo=01 etc till month end
    -- then every Insert function check the month and date then process generate new one.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761544
    Hi
    You can follow this steps you can achieve your output

    I assuming your issue this

    Insert for Bill Entry

    for this code checking the db current record is have or not because billno Render
    depends on date so here i checking current date record have means total record
    take count and plus 1 otherwise initial value 1

    Create table this

    CREATE TABLE [dbo].[head](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [BillNo] [varchar](50) NULL,
    [EntryDate] [date] NULL,
    PRIMARY KEY CLUSTERED
    (
    [Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]


    Step1
    in your Button2_Click

    add below lines


    SqlConnection conn = new SqlConnection(GetConnectionString());
    SqlCommand sqlcmd1 = null;
    DataTable dt = new DataTable();
    SqlDataAdapter sqladp = new SqlDataAdapter("Select ID,BillNo,count(*) from head where Month(EntryDate)=month(Getdate()) group by BillNo,id Order by ID Desc", conn);
    sqladp.Fill(dt);
    int BillNo = 0;
    if (dt.Rows.Count == 0)
    {
    BillNo = 1;
    sqlcmd1 = new SqlCommand("Insert into head values('" + BillNo.ToString() + "','" + DateTime.Now.ToString("MM/dd/yyyy") + "')", conn);
    }
    else
    {
    BillNo = Convert.ToInt32(dt.Rows[0][1]) + 1;
    sqlcmd1 = new SqlCommand("Insert into head values('" + BillNo.ToString() + "', '" + DateTime.Now.ToString("MM/dd/yyyy") + "')", conn);
    }
    conn.Open();
    sqlcmd1.ExecuteNonQuery();
    conn.Close();



    Step2


    sc.Add(BillNo.ToString() +


    Step3:

    Add Index for BillNo your


    ex: sb.AppendFormat("{0}('{1}',




    I have added Snapshot given below

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment

  • #761545
    I hope the following will help you

    string Test = "1-451";
    string Result = Test.Split('-')[0] == "1" ? Test.Split('-')[0]+"-01" : Test;

    By Nathan
    Direction is important than speed

  • #761596
    hi

    try this update code


    Create Table head
    (
    Id int primary key identity (1,1),
    BillNo varchar(50),
    EntryDate date
    )

    Select ID,BillNo,count(*) from head where CONVERT(varchar(12),Entrydate,101)=CONVERT(varchar(12),GetDate(),101) group by BillNo,id Order by ID Desc



    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebApplication2
    {
    public partial class WebForm11 : System.Web.UI.Page
    {

    string s = ConfigurationManager.AppSettings["s"].ToString();
    double m = 0;
    decimal RunningTotal = 0;
    int txtcount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    txtBarcode.Focus();
    txtSalesDate.Text = System.DateTime.Now.ToString("dd/MM/yyyy");
    txtBarcode.Attributes.Add("onkeypress", "return controlEnter('" + txtqty.ClientID + "', event)");
    cusname();
    countrname();
    SalesPersnname();
    txtbdate.Text = System.DateTime.Now.ToString();
    txtsalestime.Text = System.DateTime.Now.ToString("hh:MM");
    }
    }
    private void BindListView()
    {
    string constr = ConfigurationManager.AppSettings["s"].ToString();
    DataTable products = new DataTable();
    using (SqlConnection con = new SqlConnection(constr))
    {
    using (SqlCommand cmd = new SqlCommand())
    {
    using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
    {
    cmd.CommandText = "SELECT distinct sectionname,lotno,Productname,mrp,supplierename,sizee from purchasedummy where lotno='" + txtBarcode.Text +

    "'";
    cmd.Connection = con;
    //Old Code
    DataTable dt = new DataTable();
    sda.Fill(dt);
    //Old Code
    //DataTable products = new DataTable();
    //sda.Fill(products);

    if (ViewState["Products"] == null)
    {
    ViewState["Products"] = dt;
    products.Merge(dt, true);
    ddsales.DataSource = products;
    ddsales.DataBind();

    }
    else
    {
    //products = (DataTable)ViewState["Products"];
    products = (DataTable)ViewState["Products"];
    products.Merge(dt, true);
    }
    ddsales.DataSource = products;
    ddsales.DataBind();
    if (dt.Rows.Count == 0) { Response.Write("<script>alert('Stock is Zero Please Enter Correct Barcode No !')</script>"); } else { Calc(); }
    }
    }
    txtBarcode.Text = "";

    }
    }
    protected void txtBarcode_TextChanged(object sender, EventArgs e)
    {
    ddsales.Visible = true;
    BindListView();
    //if (e.KeyCode ==13)
    //{
    //txtbillamountcash.Focus();
    //}

    //Old Calc
    //DataTable dt1;
    //dt1 = (DataTable)ViewState["Products"];
    //if (dt1.Rows.Count != 0)
    //{
    // float sum = 0;
    // for (int i = 0; i < dt1.Rows.Count; i++)
    // {
    // sum += float.Parse(dt1.Rows[i]["mrp"].ToString());
    // txtbillamountcash.Text = Convert.ToString(sum);
    // }
    //}
    }
    protected void txtqty_TextChanged(object sender, EventArgs e)
    {
    //foreach (GridViewRow rowz in ddsales.Rows)
    //{
    // GridViewRow row = ddsales.Rows[ddsales.Rows.Count - 1];
    // double mr, wt, totlrp;
    // mr = Convert.ToDouble((rowz.FindControl("lblmrp") as Label).Text);
    // wt = double.Parse(txtqty.Text);
    // totlrp = mr * wt;
    // (rowz.FindControl("lblmrp") as Label).Text = Convert.ToString(totlrp);
    //}
    //txtqty.Text = "1";

    }

    protected void ddsales_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    //Old Calc
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(ddsales, "Select$" + e.Row.RowIndex);
    // e.Row.ToolTip = "Click to select this row.";
    // DataTable dtst1;
    // dtst1 = (DataTable)ViewState["Products"];
    // if (dtst1.Rows.Count != 0)
    // {
    // float bilamnt = 0;
    // for (int i = 0; i < dtst1.Rows.Count; i++)
    // {
    // bilamnt += float.Parse(dtst1.Rows[i]["mrp"].ToString());
    // txtbillamountcash.Text = Convert.ToString(bilamnt);
    // }
    // }
    }
    }
    protected void ddsales_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    }
    protected void ddsales_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    DataTable dt = (DataTable)ViewState["Products"];
    dt.Rows.RemoveAt(e.RowIndex);
    ViewState["Products"] = dt;
    ddsales.DataSource = dt;
    ddsales.DataBind();
    if (dt.Rows.Count == 0)
    {
    txtbillamountcash.Text = "";
    }
    Calc();
    //DataTable dtt1;
    //dtt1 = (DataTable)ViewState["Products"];
    //if (dtt1.Rows.Count != 0)
    //{
    // float bilamt = 0;
    // for (int i = 0; i < dtt1.Rows.Count; i++)
    // {
    // bilamt += float.Parse(dtt1.Rows[i]["mrp"].ToString());
    // txtbillamountcash.Text = Convert.ToString(bilamt);
    // }

    //}
    }

    protected void btRemove_Click(object sender, EventArgs e)
    {
    // DataTable dt = (DataTable)ViewState["Products"];
    // ViewState["Products"] = dt;
    // ddsales.DataSource = null;
    // ddsales.DataBind();
    // dt.Clear();
    Calc();
    }

    protected void chkSelect_CheckedChanged(object sender, EventArgs e)
    {
    DataTable dtProd = new DataTable();
    foreach (GridViewRow gvr in this.ddsales.Rows)
    {
    if (((CheckBox)gvr.FindControl("chkSelect")).Checked == true)
    {
    string bqno = (gvr.FindControl("lblmrp") as Label).Text;
    // Session.Remove("bqno");
    dtProd = ViewState["Products"] as DataTable;
    dtProd.Rows.Remove(dtProd.Rows[gvr.RowIndex]);
    //dt.Rows.Remove(dt.Rows[2]);
    Session["Products"] = dtProd;
    }
    }
    ddsales.DataSource = dtProd;
    ddsales.DataBind();
    Calc();
    }

    protected void ddsales_PreRender(object sender, EventArgs e)
    {
    }
    protected void txtdispr_TextChanged(object sender, EventArgs e)
    {
    if (txtdispr.Text != "")
    {
    foreach (GridViewRow gvr in this.ddsales.Rows)
    {
    if (((CheckBox)gvr.FindControl("chkSelect")).Checked == true)
    {
    string bqno = (gvr.FindControl("lblmrp") as Label).Text;
    double dis, mmr, pmr, totdis, nowdis;
    dis = int.Parse(txtdispr.Text);
    mmr = int.Parse(bqno);
    pmr = dis * mmr;
    totdis = pmr / 100;
    nowdis = mmr - totdis;
    (gvr.FindControl("lblmrp") as Label).Text = Convert.ToString(nowdis);
    }
    txtdispr.Text = "";
    break;
    }
    BindListView();
    }
    else
    {
    txtdispr.Focus();
    }
    }
    protected void ddsales_RowCreated(object sender, GridViewRowEventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    Session.Remove("Products");
    ddsales.Visible = false;
    }
    public void SalesPersnname()
    {
    ListItem lk1 = new ListItem();
    lk1.Value = "--Select--";
    ddSalesPerson.Items.Add(lk1.ToString());
    ddSalesPerson.Items.Add("Saranya");
    ddSalesPerson.Items.Add("Ponni");
    ddSalesPerson.Items.Add("Haffiz");
    }
    public void countrname()
    {
    ListItem lissi1 = new ListItem();
    lissi1.Value = "--Select--";
    ddCounterName.Items.Add(lissi1.ToString());
    ddCounterName.Items.Add("Counter1");
    ddCounterName.Items.Add("Counter2");
    ddCounterName.Items.Add("Counter3");
    }
    public void cusname()
    {
    ListItem lsi1 = new ListItem();
    lsi1.Value = "--Select--";
    ddCustomerName.Items.Add(lsi1.ToString());
    ddCustomerName.Items.Add("New Customer");
    ddCustomerName.Items.Add("Riyaz");
    ddCustomerName.Items.Add("Queens");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
    SqlConnection conn = new SqlConnection(GetConnectionString());
    SqlCommand sqlcmd1 = null;
    DataTable dt = new DataTable();
    //SqlDataAdapter sqladp = new SqlDataAdapter("Select ID,BillNo,count(*) from head where CONVERT(varchar(12),Entrydate,101)=CONVERT(varchar(12),GetDate

    (),101) group by BillNo,id Order by ID Desc", conn);
    SqlDataAdapter sqladp = new SqlDataAdapter("Select ID,BillNo,count(*) from head where Month(EntryDate)=month(Getdate()) group by BillNo,id Order by ID

    Desc", conn);
    sqladp.Fill(dt);
    int BillNo = 0;
    if (dt.Rows.Count == 0)
    {
    BillNo = 1;
    sqlcmd1 = new SqlCommand("Insert into head values('" + BillNo.ToString() + "','" + DateTime.Now.ToString("MM/dd/yyyy") + "')", conn);
    }
    else
    {
    BillNo = Convert.ToInt32(dt.Rows[0][1]) + 1;
    sqlcmd1 = new SqlCommand("Insert into head values('" + BillNo.ToString() + "', '" + DateTime.Now.ToString("MM/dd/yyyy") + "')", conn);
    }
    conn.Open();
    sqlcmd1.ExecuteNonQuery();
    conn.Close();


    int rowIndex = 0;
    StringCollection sc = new StringCollection();
    if (ViewState["Products"] != null)
    {
    int saleno = int.Parse(txtsalesno.Text);
    string saldate = Convert.ToDateTime(txtSalesDate.Text).ToString("MM/dd/yyyy");
    string ddcnt = ddCounterName.Text;
    int prvsbil = int.Parse(txtPreviosBillamount.Text);
    string salprs = ddSalesPerson.Text;
    int txqty = int.Parse(txtqty.Text);
    float txrate = float.Parse(txtrate.Text);
    float disct = float.Parse(txtdispr.Text);
    float dsprs = float.Parse(txtdisrs.Text);
    float txtldis = float.Parse(txttotaldisct.Text);
    float ttldisrupe = float.Parse(txtdisrupes.Text);
    float custrles = float.Parse(txtcustrless.Text);
    float cashrecd = float.Parse(txtcashreceved.Text);
    float txbiamnt = float.Parse(txtbillamountcash.Text);
    float cbalance = float.Parse(txtbalnce.Text);
    //DateTime bdte = DateTime.ParseExact(txtbdate.Text, "dd/MM/yyyy HH:mm tt", null); //Convert.ToDateTime(txtbdate.Text);
    string bdte = Convert.ToDateTime(txtbdate.Text).ToString("MM/dd/yyyy");
    string cdte = System.DateTime.Now.ToString("MM/dd/yyyy");
    string saletme = txtsalestime.Text;
    DataTable dtCurrentTable = (DataTable)ViewState["Products"];
    DataRow drCurrentRow = null;
    if (dtCurrentTable.Rows.Count > 0)
    {
    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
    {
    Label box1 = (Label)ddsales.Rows[rowIndex].Cells[1].FindControl("lblsectn");
    Label box2 = (Label)ddsales.Rows[rowIndex].Cells[2].FindControl("lblproductname");
    Label box3 = (Label)ddsales.Rows[rowIndex].Cells[3].FindControl("lbllotno");
    Label box4 = (Label)ddsales.Rows[rowIndex].Cells[3].FindControl("lblmrp");
    Label box5 = (Label)ddsales.Rows[rowIndex].Cells[3].FindControl("lblsupliername");
    Label box6 = (Label)ddsales.Rows[rowIndex].Cells[3].FindControl("lblsizee");
    sc.Add(BillNo.ToString() + "," + saleno + "," + saldate + "," + ddcnt + "," + prvsbil + "," + salprs + "," + txqty + "," + txrate + "," + disct

    + "," + dsprs + "," + txtldis + "," + ttldisrupe + "," + custrles + "," + cbalance + "," + cashrecd + "," + bdte + "," + saletme + "," + box1.Text + "," + box2.Text +

    "," + box3.Text + "," + box4.Text + "," + txqty + "," + box5.Text + "," + box6.Text + "," + cdte);
    rowIndex++;
    }
    InsertRecords(sc);
    }
    }
    }
    private void InsertRecords(StringCollection sc)
    {
    SqlConnection conn = new SqlConnection(GetConnectionString());
    StringBuilder sb = new StringBuilder(string.Empty);
    string[] splitItems = null;


    foreach (string item in sc)
    {
    const string sqlStatement = "insert into sales

    (BillNo,salesno,salesdate,counername,previousbillamount,salesperson,qty,rate,singledisount,singlerupes,totaldiscount,totalrupes,customerless,balance,cashreceved,bdate,

    salestime,sectionname,productname,lotno,mrp,quantity,supplername,sizee,currentdate) VALUES";
    if (item.Contains(","))
    {
    splitItems = item.Split(",".ToCharArray());
    sb.AppendFormat("{0}

    ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}')

    ;", sqlStatement, splitItems[0], splitItems[1], splitItems[2], splitItems[3], splitItems[4], splitItems[5], splitItems[6], splitItems[7], splitItems[8], splitItems[9],

    splitItems[10], splitItems[11], splitItems[12], splitItems[13], splitItems[14], splitItems[15], splitItems[16], splitItems[17], splitItems[18], splitItems[19],

    splitItems[20], splitItems[21], splitItems[22], splitItems[23], splitItems[24]);
    }
    }
    try
    {
    conn.Open();
    SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
    cmd.CommandType = CommandType.Text;
    cmd.ExecuteNonQuery();
    Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Script", "alert('Records Successfuly Saved!');", true);
    }
    catch (System.Data.SqlClient.SqlException ex)
    {
    string msg = "Insert Error:";
    msg += ex.Message;
    throw new Exception(msg);
    }
    finally
    {
    conn.Close();
    }
    }
    private string GetConnectionString()
    {
    return System.Configuration.ConfigurationManager.AppSettings["s"].ToString();
    }



    private void Calc()
    {
    double foottotal = 0;
    foreach (GridViewRow dr in ddsales.Rows)
    {
    double price = Convert.ToDouble(((Label)dr.FindControl("lblmrp")).Text);
    //int Qty = int.Parse(((TextBox)dr.FindControl("txtQty")).Text);
    //double total = price * Qty;
    //((TextBox)dr.FindControl("lbltotal")).Text = Convert.ToString(total);
    foottotal = foottotal + price;
    }
    GridViewRow row = ddsales.FooterRow;
    ((Label)row.FindControl("Salary")).Text = Convert.ToString(foottotal);
    txtbillamountcash.Text = foottotal.ToString();
    }

    protected void ddsales_SelectedIndexChanged(object sender, EventArgs e)
    {
    foreach (GridViewRow row in ddsales.Rows)
    {
    if (row.RowIndex == ddsales.SelectedIndex)
    {
    row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
    row.ToolTip = string.Empty;
    float bilamt = 0;
    double mr, wt, totlrp, mpr, totl;
    mr = Convert.ToDouble((row.FindControl("lblmrp") as Label).Text);
    mpr = Convert.ToDouble((row.FindControl("lblmrp") as Label).Text);
    DataTable dtt1;
    dtt1 = (DataTable)ViewState["Products"];






    //Old Code
    //if (dtt1.Rows.Count != 0)
    //{

    // for (int i = 0; i < dtt1.Rows.Count; i++)
    // {
    // bilamt += float.Parse(dtt1.Rows[i]["mrp"].ToString());
    // // txtbillamountcash.Text = Convert.ToString(bilamt);

    // bilamt += float.Parse(dtt1.Rows[i]["mrp"].ToString());
    // if (txtqty.Text != "")
    // {
    // wt = double.Parse(txtqty.Text);
    // totlrp = mr * wt;
    // //totl = mr + totlrp ;
    // //(row.FindControl("lblmrp") as Label).Text = Convert.ToString(totl);
    // // txtbillamountcash.Text = Convert.ToString(totl);

    // txtbillamountcash.Text = Convert.ToString(totlrp);
    // }
    // else
    // {
    // }
    // }
    //}
    //Old Code
    }
    else
    {
    row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
    row.ToolTip = "Click to select this row.";
    }
    }
    }
    }
    }


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761690
    Hi Nirav and Jayakumar.

    What is this posting of entire code?
    The people will get habituated for spoon feed, instead of giving the total code as it is make him find his error.
    Solving the error part would be good according to me.

    Hope you will understand.

    Regards

    Sridhar Thota.
    If you learn't from defeat..
    You haven't really lost..

    Sridhar Thota.
    Editor: DNS Forum.

  • #761691
    Hi
    sridhar

    good one
    spoon feed not good for developer. Good information.

    But Question asker mention issue means we need to code for debugging where is issue comes so I have post share the code then we canot say directly this line issue came without see the code so.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761730
    hi
    a small info.
    get the count of the bills generated on a month. if it is zero, then make the counter points to 1 else the default value that u r getting.

    select the count value when u r doing login and keep it in session or static variable in some way to avoid db calls to db on the page loads

    if u feel this is good, u can use it.

    Do Good... Enjoy your life.....


Sign In to post your comments