Пример #1
0
        public void Show()
        {
            try
            {
                suplierTableBody.InnerHtml = "";
                string htmlContent = "";
                List<Supplier> departmentList = new List<Supplier>();
                Supplier aDepartment = new Supplier();
                departmentList = aDepartment.GetAllSupplier(_company.CompanyId);
                foreach (Supplier aDepo in departmentList)
                {

                    htmlContent += "<tr>";

                    htmlContent += String.Format(@"<th>{0}</th><th>{1}</th><th>{2}</th><th>{3}</th><th>{4}</th></tr>", aDepo.SupplierName, aDepo.IsActive, aDepo.UpdateDate, aDepo.TotalDebit, aDepo.TotalCredit);
                    htmlContent += "</tr>";
                }
                suplierTableBody.InnerHtml += htmlContent;

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }
Пример #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool chk = false;
                Supplier aSupply = new Supplier();
                List<Supplier> aSuppierList = aSupply.GetAllSupplier(_company.CompanyId);
                long id;
                if (aSuppierList.Count > 0)
                {
                    aSupply = aSuppierList[aSuppierList.Count - 1];
                    id = aSupply.SupplierId + 1;
                }

                else
                    id = 1;

                Supplier newSupply = new Supplier();
                newSupply.SupplierId = id;
                newSupply.SupplierName = txtSupplierName.Value;
                newSupply.IsActive = true;
                newSupply.CompanyId = _company.CompanyId;
                newSupply.UpdateBy = user.UserId;
                newSupply.UpdateDate = DateTime.Now;
                newSupply.TotalDebit = int.Parse(txtTotalDebit.Value);
                newSupply.TotalCredit = int.Parse(txtTotalCredit.Value);
                newSupply.Balance = newSupply.TotalCredit - newSupply.TotalDebit;
                Addresses aAddresses = new Addresses();
                aAddresses.SourceType = "Supplier";
                aAddresses.SourceId = id;
                aAddresses.AddressType = "Main Address";
                aAddresses.AddressLine1 = txtAddressLine1.Value;
                aAddresses.AddressLine2 = txtAddressLine2.Value;
                aAddresses.CountryId = int.Parse(countryDropDownList.SelectedIndex.ToString());
                aAddresses.City = txtCity.Value;
                aAddresses.ZipCode = txtZipCode.Value;

                aAddresses.CompanyId = _company.CompanyId;
                int chk1 = newSupply.InsertSupplier();
                int chk2 = aAddresses.InsertAddresses();
                if (chk1 > 0 && chk2 > 0)
                {
                    Session["savedSupplicerMessage"] = "Saved Successfully";
                    Response.Redirect(Request.RawUrl);

                }
                else
                {
                    Alert.Show("Error occured while inserting supplier information,please check the input data again. Don't use special character in Debit or Credit Section . Use the amount number there.");
                }

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }
        protected void RadGrid1_OnItemCommand(object sender, GridCommandEventArgs e)
        {
            try
            {
                GridDataItem item = (GridDataItem) e.Item;
                string id = item["colId"].Text;
                switch (e.CommandName)
                {
                    case "btnSelect":
                    {
                        Response.Redirect("SupplierInfo.aspx?id="+id);
                        break;
                    }
                    case "btnDelete":
                    {
                        int del = new Supplier().DeleteSupplierBySupplierId(int.Parse(id));
                        long addId = GetAddressID(int.Parse(id));
                        int del2 = new Addresses().DeleteAddressesByAddressId(addId);
                        if (del2 == 0 && del == 0)
                        {
                            Alert.Show("Data is not deleted");
                        }
                        else
                        {
                            this.LoadSupplierTable();
                        }
                        break;
                    }
                }

            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        private void LoadSupplierTable()
        {
            try
            {
                Supplier newSupplier= new Supplier();
                objSupplierList = newSupplier.GetAllSupplier(_company.CompanyId);
                List<string> countryList = Country.CountryList();
                List<Addresses> addresses=new Addresses().GetAllAddresses(_company.CompanyId);
                foreach (Supplier supplier in objSupplierList)
                {

                    foreach (Addresses aAddress in addresses)
                    {
                        if (aAddress.SourceType == "Supplier" && aAddress.SourceId == supplier.SupplierId)
                        {
                            supplier.AddressLine1 = aAddress.AddressLine1;
                            supplier.AddressLine2 = aAddress.AddressLine2;
                            supplier.City = aAddress.City;
                            supplier.ZipCode = aAddress.ZipCode;
                            supplier.Phone = aAddress.Phone;
                            supplier.Email = aAddress.Email;
                            supplier.Web = aAddress.Web;
                            supplier.Mobile = aAddress.Mobile;
                            supplier.CountryName = countryList[aAddress.CountryId];
                        }
                    }
                }
                RadGrid1.DataSource = objSupplierList;
                RadGrid1.Rebind();

            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool chk = false;
                Supplier aSupply = new Supplier();
                List<Supplier> aSuppierList = aSupply.GetAllSupplier(_company.CompanyId);
                long id;

                Supplier newSupply = new Supplier();

                newSupply.SupplierName = txtSupplierName.Value;
                newSupply.IsActive = true;
                newSupply.CompanyId = _company.CompanyId;
                newSupply.UpdateBy = user.UserId;
                newSupply.UpdateDate = DateTime.Now;
                newSupply.TotalDebit = decimal.Parse(txtTotalDebit.Value);
                newSupply.TotalCredit = decimal.Parse(txtTotalCredit.Value);

                Addresses address = new Addresses();
                address.SourceType = "Supplier";

                address.AddressType = "Main Address";
                address.AddressLine1 = txtAddressLine1.Value;
                address.AddressLine2 = txtAddressLine2.Value;
                address.CountryId = int.Parse(countryDropDownList.SelectedIndex.ToString());
                address.City = txtCity.Value;
                address.Email = txtEmail.Value;
                address.Phone = txtPhone.Value;
                address.Web = txtWeb.Value;
                address.Mobile = txtMobile.Value;

                address.ZipCode = txtZipCode.Value;

                address.CompanyId = _company.CompanyId;
                if (lblId.Text == "" || lblId.Text == "0")
                {
                    newSupply.SupplierId = new Supplier().GetMaxSupplierID() + 1;
                    address.SourceId = newSupply.SupplierId;
                    address.AddressId = new Addresses().GetMaxAddressId() + 1;
                    int chk1 = newSupply.InsertSupplier();
                    int chk2 = address.InsertAddresses();
                    if (chk1 > 0 && chk2 > 0)
                    {
                        Session["savedSupplicerMessage"] = "Saved Successfully";
                        Response.Redirect(Request.RawUrl);

                    }
                    else
                    {
                        Alert.Show("Error occured while inserting supplier information,please check the input data again. Don't use special character in Debit or Credit Section . Use the amount number there.");
                    }
                }
                else
                {
                    address.AddressId = long.Parse(addlblId.Text);
                    newSupply.SupplierId = int.Parse(lblId.Text);
                    address.SourceId = newSupply.SupplierId;
                    int chk1 = newSupply.UpdateSupplier();
                    int chk2 = address.UpdateAddresses();
                    if(chk1>0&&chk2>0)
                        Response.Redirect("SupplierList.aspx");

                }

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _company = (Company)Session["Company"];
            user = (Users)Session["user"];
            this.LoadCountryDropDownList();
            if (Session["savedSupplicerMessage"] != null)
            {
                string msg = Session["savedSupplicerMessage"].ToString();
                Alert.Show(msg);
                Session["savedSupplicerMessage"] = null;
            }
            if (!isValidSession())
            {
                string str = Request.QueryString.ToString();
                if (str == string.Empty)
                {
                    Response.Redirect("LogIn.aspx?refPage=index.aspx");
                }
                else
                {
                    Response.Redirect("LogIn.aspx?refPage=index.aspx?"+str);
                }
            }
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    string id = Request.QueryString["id"].ToString();
                    Supplier tempSupplier= new Supplier().GetSupplierBySupplierId(int.Parse(id),_company.CompanyId);
                    if (tempSupplier != null || tempSupplier.SupplierId != 0)
                    {
                        List<Addresses> addressList = new Addresses().GetAllAddresses(_company.CompanyId);
                        Addresses tempAddress = new Addresses();
                        foreach (Addresses address in addressList)
                        {
                            if (address.SourceType == "Supplier" && address.SourceId == int.Parse(id))
                            {
                                tempAddress = address;
                                break;
                            }
                        }
                        lblId.Text = id;
                        addlblId.Text = tempAddress.AddressId.ToString();
                        txtSupplierName.Value = tempSupplier.SupplierName;
                        txtAddressLine1.Value = tempAddress.AddressLine1;
                        txtAddressLine2.Value = tempAddress.AddressLine2;
                        txtCity.Value = tempAddress.City;
                        txtZipCode.Value = tempAddress.ZipCode;
                        txtEmail.Value = tempAddress.Email;
                        txtPhone.Value = tempAddress.Phone;
                        txtMobile.Value = tempAddress.Mobile;
                        txtWeb.Value = tempAddress.Web;
                        txtTotalCredit.Value = tempSupplier.TotalCredit.ToString();
                        txtTotalDebit.Value = tempSupplier.TotalDebit.ToString();
                        chkIsActive.Checked = tempSupplier.IsActive;
                        countryDropDownList.SelectedIndex = tempAddress.CountryId;
                    }

                }
            }
        }