Example #1
0
 int CountInvoiceNo()
 {
     var t = 0;
     if (invno.EditValue != null)
     {
         var ta = new DataSet1TableAdapters.PURINVMAINTableAdapter();
         if (!string.IsNullOrEmpty(_purid))
         {
             var invoiceCountWithHold = ta.GetInvoiceCountWithHold(supplier.EditValue.ToString(), invno.EditValue.ToString(), _purid);
             if (invoiceCountWithHold != null)
                 t = (int)invoiceCountWithHold;
         }
         else
         {
             var invoiceCount = ta.GetInvoiceCount(supplier.EditValue.ToString(), invno.EditValue.ToString());
             if (invoiceCount != null)
                 t = (int)invoiceCount;
         }
         
     }
     return t;
 }
Example #2
0
        void DoSave()
        {
            var Errorlist = new ArrayList();

            c1TrueDBGrid1.UpdateData();
            
            if (supplier.EditValue==null)
            {
                _ishold = false;
                XtraMessageBox.Show("Please select the supplier","P.O.S",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            if (warehouse.EditValue == null)
            {
                _ishold = false;
                XtraMessageBox.Show("Please select  the warehouse name", "P.O.S", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            DateTime? dtinv = null;
            if (invdate.EditValue == null || invdate.EditValue.ToString()==string.Empty)
                dtinv = null;
            else
                dtinv = (DateTime?)invdate.EditValue;
            

            string Inv="";
            if (invno.EditValue == null) 
                 Inv=string.Empty;
             else
                Inv = (string)invno.EditValue;

            if (!_ishold)
            {
                if (invno.EditValue==null)
                {
                    XtraMessageBox.Show("Please enter the invoice no", "P.O.S", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (invdate.EditValue == null) 
                {
                    XtraMessageBox.Show("Please enter the invoice date", "P.O.S", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            
                foreach (var d in this.dataSet1.PURINVDETAIL)
                {
                    string t = "";
                    if (int.Parse(d["qty"].ToString()) == 0)
                    {
                        t = "Quantity not found for item :" + GetItemname(d["ITEMID"].ToString());
                        Errorlist.Add(t);
                    }
                    if (decimal.Parse(d["invrate"].ToString()) == 0)
                    {
                        t = "Inv.Rate not found for item :" + GetItemname(d["ITEMID"].ToString());
                        Errorlist.Add(t);
                    }
                    if (decimal.Parse(d["sprice"].ToString()) == 0)
                    {
                        t = "Sales price not found for item : " + GetItemname(d["ITEMID"].ToString());
                        Errorlist.Add(t);
                    }
                    if (bool.Parse(d["expr"].ToString()) == true && string.IsNullOrEmpty(d["expdate"].ToString()))
                    {
                        t = "Expiry date not found for item :" + GetItemname(d["ITEMID"].ToString());
                        Errorlist.Add(t);
                    }
                }
            }
             if (CountInvoiceNo() > 0)
             {
                    XtraMessageBox.Show("Duplicate invoice no found..!,please check the invoice no", "P.O.S", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
             }
            if (Errorlist.Count > 0)
            {
                
                var f = new Testing(Errorlist);
                f.ShowDialog();
                return;
            }
            Whid = warehouse.EditValue==null ? 0 : int.Parse(warehouse.EditValue.ToString());
            try
            {
                if (!string.IsNullOrEmpty(_purid))
                {
                    _issaved = true;
                    var dr = this.dataSet1.PURINVMAIN.FindByPURINVID(_purid);
                    if (dr != null)
                    {
                        dr.BeginEdit();
                        dr.SUPID = supplier.EditValue.ToString();
                        dr.SUPNAME = supplier.Text;
                        dr.INVNO = Inv;
                        if(dtinv==null)
                            dr["INVDATE"] = DBNull.Value;
                        else
                            dr["INVDATE"] = dtinv;
                        dr.DUEDAYS = int.Parse(duedays.EditValue.ToString());
                        dr.SPDISCOUNT = decimal.Parse(spdisc.EditValue.ToString());
                        dr.ADJVALUE = decimal.Parse(adjustval.EditValue.ToString());
                        dr.HOLD = _ishold;
                        dr.WHID = Whid;
                        dr.EUSERID = COMMON.Utils.Userid;
                        dr.EDATE = DateTime.Now;
                        dr.NETVALUE = decimal.Parse(netamt.EditValue.ToString());
                        
                        dr.EndEdit();
                        this.purinvmainTableAdapter1.Update(dr);
                    }
                }
                else
                {
                    var InsertQ = new DataSet1TableAdapters.PURINVMAINTableAdapter();
                    //_purid = Convert.ToInt32(InsertQ.InsertQuery(DateTime.Today.Date,
                    //    supplier.EditValue.ToString(),
                    //    supplier.Text,
                    //    Inv,
                    //    dtinv,
                    //    int.Parse(duedays.EditValue.ToString()),
                    //    decimal.Parse(spdisc.EditValue.ToString()),
                    //    decimal.Parse(adjustval.EditValue.ToString()),
                    //    _ishold,
                    //    Whid,
                    //    0,
                    //    COMMON.Utils.Userid,
                    //    DateTime.Now,
                    //    0,
                    //    null,decimal.Parse(netamt.EditValue.ToString())).ToString());
                }
                if (!string.IsNullOrEmpty(_purid))
                {
                    purno.EditValue = _purid;
                    _issaved = true;
                    foreach (DataRow d in this.dataSet1.PURINVDETAIL.Rows)
                    {
                        d["PURINVID"] = _purid;
                    }
                    pURINVDETAILTableAdapter1.Update(this.dataSet1.PURINVDETAIL);
                    if (_ishold)
                    {
                        XtraMessageBox.Show("Invoice holded sucessfully", "P.O.S", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        UpdateStock();
                        XtraMessageBox.Show("Invoice recorded sucessfully", "P.O.S", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else 
                {
                   XtraMessageBox.Show("Error while saving please try again", "P.O.S", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString(), "P.O.S", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }