private void btndelete_Click(object sender, EventArgs e)
        {
            cc = new itemdetailcontroller();

            dt = new DataTable("SearchRecords");

            dt.Columns.Add("Customer_ID", System.Type.GetType("System.String"));
            dt.Columns.Add("Fname", System.Type.GetType("System.String"));
            dt.Columns.Add("Lname", System.Type.GetType("System.String"));
            dt.Columns.Add("email", System.Type.GetType("System.String"));
            dt.Columns.Add("phone", System.Type.GetType("System.String"));
            dataGridView2.DataSource = dt;
            btndelete.Visible        = false;
            DialogResult dr = MessageBox.Show("You want to delete the record ?", "Confirm", MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                if (id != -1)
                {
                    cc.DeleteRecord(id);

                    dt.Rows.Clear();
                    MessageBox.Show("Record Deleted");
                    btndelete.Visible = false;
                }
            }
            searchType = 0;
            bool       flag = false;
            itemdetail cd   = null;

            flag = int.TryParse(txtcustid.Text, out id);
            cd   = cc.Searchcustomer(id);
            if (cd == null)
            {
                flag = false;
            }
            else
            {
                id         = cd.Customer_ID;
                searchType = 1;
                flag       = true;
            }
            if (flag)
            {
                dt.Rows.Clear();
                dt.Rows.Add(new object[] {
                    cd.Customer_ID, cd.Fname, cd.Lname, cd.email, cd.phone
                });
                btndelete.Visible = true;
            }
            else
            {
                dt.Rows.Clear();
                MessageBox.Show("Record Not Found");
                id = -1;
                btndelete.Visible = false;
            }
        }
        private void btnsearch_Click(object sender, EventArgs e)
        {
            int id;

            bool flag = int.TryParse(txtcustid.Text, out id);

            if (!flag)
            {
                MessageBox.Show("Invalid ID");
                return;
            }


            itemdetailcontroller std = new itemdetailcontroller();
            itemdetail           i   = std.Searchcustomer(id);

            if (i != null)
            {
                a = true;
                txtcustid.Text = i.Customer_ID.ToString();
            }
            else
            {
                a = false;
                MessageBox.Show("Record Not Found");
            }
            itemdetailcontroller sc = new itemdetailcontroller();

            dt = new DataTable();
            if (a == true)
            {
                dt.Columns.Add("Customer_ID", System.Type.GetType("System.String"));
                dt.Columns.Add("Fname", System.Type.GetType("System.String"));
                dt.Columns.Add("Lname", System.Type.GetType("System.String"));
                dt.Columns.Add("email", System.Type.GetType("System.String"));
                dt.Columns.Add("phone", System.Type.GetType("System.String"));
                List <itemdetail> d = sc.GetAllitem();

                foreach (var s in d)
                {
                    if (id == s.Customer_ID)
                    {
                        dt.Rows.Add(new object[] { s.Customer_ID, s.Fname, s.Lname, s.email, s.phone });
                    }
                }
                dataGridView2.DataSource = dt;
            }
        }
Пример #3
0
        public itemdetail Searchcustomer(int Boid)
        {
            itemdetail cd  = null;
            int        pos = GetPosition(Boid);

            if (pos != -1)
            {
                using (FileStream LoginReader = new FileStream("CustomerDetails.txt", FileMode.Open))
                {
                    cd = new itemdetail();
                    string line = "";
                    int    chr;
                    LoginReader.Seek(pos, SeekOrigin.Begin);
                    while ((chr = LoginReader.ReadByte()) > 0)
                    {
                        char c;
                        c = Convert.ToChar(chr);
                        if (c == '$')
                        {
                            break;
                        }
                        line += c;
                    }
                    string[] subStr = line.Split('|');
                    try
                    {
                        cd.Customer_ID = int.Parse(subStr[0]);
                        cd.Fname       = subStr[1];
                        cd.Lname       = subStr[2];
                        cd.email       = subStr[3];
                        cd.phone       = subStr[4];
                    }
                    catch (Exception e)
                    {
                        Console.Out.WriteLine(e.StackTrace);
                        Console.Out.WriteLine("inside search customer error ---------------------");
                    }
                }
                return(cd);
            }
            return(cd);
        }
Пример #4
0
        public itemdetail SearchCustomer(string cuName)
        {
            itemdetail cd = null;

            SortByName();
            int pos = GetPosition(cuName);


            if (pos != -1)
            {
                using (FileStream LoginReader = new FileStream("CustomerDetails.txt", FileMode.Open))
                {
                    cd = new itemdetail();
                    string line = "";
                    int    chr;
                    LoginReader.Seek(pos, SeekOrigin.Begin);
                    while ((chr = LoginReader.ReadByte()) > 0)
                    {
                        char c;
                        c = Convert.ToChar(chr);
                        if (c == '$')
                        {
                            break;
                        }
                        line += c;
                    }
                    string[] subStr = line.Split('|');
                    cd.Customer_ID = int.Parse(subStr[0]);
                    cd.Fname       = subStr[1];
                    cd.Lname       = subStr[2];
                    cd.email       = subStr[3];
                    cd.phone       = subStr[4];
                }
                return(cd);
            }
            return(cd);
        }