Пример #1
0
        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            gridView1.PostEditor();
            var bl = new BusinessLogic.BLSales();
            var dr = gridView1.GetDataRow(gridView1.FocusedRowHandle);
            int oldvalue = 0;
            int newval1 = 0;
            if (dr == null) return;
            if (_validateoff) return;
            if (e.Column.FieldName.ToUpper() == "QTY" || e.Column.FieldName.ToUpper() == "INVRATE" || e.Column.FieldName.ToUpper() == "EXPDATE1")
            {
                if (e.Column.FieldName.ToUpper() == "QTY" && dr["ISRETURN"].ToString() == bool.FalseString)
                {
                    if (int.Parse(dr["STOCKID"].ToString()) == 0)
                        return;
                    if (((GridView) sender).ActiveEditor != null)
                        oldvalue = ((GridView) sender).ActiveEditor.EditValue == null
                                       ? oldvalue
                                       : int.Parse(((GridView) sender).ActiveEditor.OldEditValue.ToString());
                    if (string.IsNullOrEmpty(dr["QTY"].ToString()))
                        dr["QTY"] = oldvalue;
                    if (((GridView) sender).ActiveEditor != null)
                        newval1 = ((GridView) sender).ActiveEditor.EditValue == null
                                      ? oldvalue
                                      : int.Parse(((GridView) sender).ActiveEditor.EditValue.ToString());
                    if (int.Parse(dr["QTY"].ToString()) < 0)
                        dr["QTY"] = -1 * int.Parse(dr["QTY"].ToString());
                    var tot = Math.Round(int.Parse(dr["QTY"].ToString()) * decimal.Parse(dr["INVRATE"].ToString()), 2);
                    var linestock = int.Parse(dr["ASTOCK"].ToString());
                    var totalstock = int.Parse(dr["STOCK"].ToString());
                    if(totalstock < 0)
                    {
                        gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "LINETOTAL", tot);
                        if (oldvalue != newval1)
                        {
                            var qt = oldvalue - newval1;
                            UpdateCurrentRow(dr["TID"].ToString(), newval1, oldvalue);
                        }
                    }
                    else if (newval1 <= linestock)
                    {
                        gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "LINETOTAL", tot);
                        if (oldvalue != newval1)
                        {
                            var qt = oldvalue - newval1;
                            new BLSales().UpdateQty(int.Parse(dr["STOCKID"].ToString()), qt);
                        }
                    }
                    else if (newval1 > linestock)
                    {
                        bool showstockwindow = false;
                        var itm = dr["itemname"].ToString();
                        string noti = "";
                        if(NotifyItems!=null)
                         noti = NotifyItems.Find(item => item == itm);
                        if (noti!=null)
                        {
                            showstockwindow = true;
                        }
                        else
                        {
                            NotifyItems.Add(itm);
                        }
                        _validateoff = true;
                        UpdateCurrentRow(dr["TID"].ToString(), linestock, oldvalue);

                        if (newval1 - totalstock > 0)
                        {
                           LoadMultiLineItems(dr["itemno"].ToString(),  itm, totalstock - linestock);
                           CreateNegativeNewRow(dr, newval1 - totalstock,showstockwindow);
                        }
                        _validateoff = false;
                    }
                }
                if (e.Column.FieldName.ToUpper() == "QTY" && dr["ISRETURN"].ToString() == bool.TrueString)
                {
                    if (string.IsNullOrEmpty(dr["QTY"].ToString()))
                        dr["QTY"] = -1;
                    else
                    {
                        dr["QTY"] = int.Parse(dr["QTY"].ToString());
                    }
                    if (int.Parse(dr["QTY"].ToString()) > 0)
                        dr["QTY"] = -1*int.Parse(dr["QTY"].ToString());

                    if (string.IsNullOrEmpty(dr["INVRATE"].ToString()))
                        dr["INVRATE"] = 0;
                    var tot = Math.Round(int.Parse(dr["QTY"].ToString())*decimal.Parse(dr["INVRATE"].ToString()), 2);
                    if (!string.IsNullOrEmpty(dr["DISC"].ToString()))
                    {
                        if (decimal.Parse(dr["DISC"].ToString()) > 0)
                            tot = tot - tot * decimal.Parse(dr["DISC"].ToString()) / 100;
                    }
                    gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "LINETOTAL", tot);
                }
                if (e.Column.FieldName == "INVRATE" && dr["ISRETURN"].ToString() == bool.TrueString)
                {
                    if (string.IsNullOrEmpty(dr["INVRATE"].ToString()))
                        dr["INVRATE"] = 0;
                    if (string.IsNullOrEmpty(dr["QTY"].ToString()))
                        dr["QTY"] = -1;
                    else
                    {
                        dr["QTY"] = int.Parse(dr["QTY"].ToString());
                    }
                    if (int.Parse(dr["QTY"].ToString()) > 0)
                        dr["QTY"] = -1*int.Parse(dr["QTY"].ToString());
                  //purdiscout
                    var tot = Math.Round(int.Parse(dr["QTY"].ToString())*decimal.Parse(dr["INVRATE"].ToString()), 2);
                    if (!string.IsNullOrEmpty(dr["DISC"].ToString()))
                    {
                        if (decimal.Parse(dr["DISC"].ToString()) > 0)
                            tot = tot - tot * decimal.Parse(dr["DISC"].ToString()) / 100;
                    }
                    gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "LINETOTAL", tot);
                }
                if (e.Column.FieldName == "EXPDATE1" && dr["ISRETURN"].ToString() == bool.TrueString)
                 {
                        if (!Functions.CheckDate(dr["EXPDATE1"].ToString()))
                        {
                            dr["EXPDATE1"]= null;
                        }
                        else
                        {
                            var split = dr["EXPDATE1"].ToString().Split(new[] { '-' });
                            var dtn = Functions.CreateFirstDayOfMonth(int.Parse(split[1]), int.Parse(split[0]));
                            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "EXPDATE", dtn);
                        }
                 }
                 if (e.Column.FieldName == "DISC" && dr["ISRETURN"].ToString() == bool.TrueString)
                 {
                     var tot = Math.Round(int.Parse(dr["QTY"].ToString()) * decimal.Parse(dr["INVRATE"].ToString()), 2);
                     if (!string.IsNullOrEmpty(dr["DISC"].ToString()))
                     {
                          if(decimal.Parse(dr["DISC"].ToString()) > 0)
                               tot  = tot -  tot * decimal.Parse(dr["DISC"].ToString()) / 100;
                     }
                     gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "LINETOTAL", tot);
                 }
            }
            gridView1.UpdateCurrentRow();

            if (bl.UpdateDetails(dsInventory1.SALESINVDETAIL) != "1")
            {
                XtraMessageBox.Show("Some problem in updating the data", "POS", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
            }
            UpdateTotal();
        }
Пример #2
0
        void AddMultipleItems(DsInventory.STOCKMASTERDataTable ds, string itemname, bool isblankrow = false)
        {
            validateoff = true;
             var dt = dsInventory1.SALESINVDETAIL;
            foreach (DsInventory.STOCKMASTERRow d in ds.Rows)
            {
                var qty = 1;
                var newrow = (DsInventory.SALESINVDETAILRow)dt.NewRow();
                if (!d.IsDQNTYNull())
                    if (d.DQNTY > 0)
                    {
                        if (isreturn)
                        {
                            qty = -d.DQNTY;
                        }
                        else
                        {
                            qty = d.DQNTY;
                        }
                        newrow.QTY = qty;
                        var tot = Math.Round((qty * d.SPRICE), 2);
                        newrow.ITEMNAME = itemname;
                        newrow.STOCKID = d.STOCKID;
                        newrow.ITEMNO = d.ITEMNO;
                        newrow.SINVNO = txtinvoiceno.Caption.Trim();
                        newrow.BARCODE = d.BARCODE;
                        var aQty = new BLSales().GetAvailableQty(d["ITEMNO"].ToString());
                        newrow.STOCK = aQty;
                        newrow.ASTOCK = d.IsSQTYNull() ? 0: d.SQTY;
                        newrow.INVRATE = d.SPRICE;
                        newrow.SPRICE = d.SPRICE;

                        newrow.CPRICE = d.CPRICE;
                        newrow.ISRETURN = isreturn;
                        if (!isreturn)
                            newrow.DISCONSALE = _DISCONSALE;

                        if (!d.IsEXPDATENull())
                        {
                            newrow.EXPDATE = d.EXPDATE;
                            newrow.EXPDATE1 = d.EXPDATE.ToString("MM-yy");
                        }
                        else
                        {
                            newrow["EXPDATE"] = DBNull.Value;
                            newrow.EXPDATE1 = string.Empty;
                        }
                        newrow.BONUS = 0;
                        newrow.LINETOTAL = tot;




                        if (!d.IsDISCNull())
                        {
                            if (d.DISC > 0)
                            {
                                newrow.LINETOTAL = tot - (tot * d.DISC) / 100;
                            }
                        }
                       
                        newrow.DOCTORID = _doctorid;
                        newrow.EXTDISC = 0;
                        dt.Rows.Add(newrow);
                        // customer display(

                      //  
                        CustomerDisplay(
                            newrow.ITEMNAME.Length > 20 ? newrow.ITEMNAME.Substring(1, 20) : newrow.ITEMNAME,
                            newrow.LINETOTAL);
                        //end customer display

                      //var bl = new BLSales().UpdateDetails(dsInventory1.SALESINVDETAIL);
                        var ret = "0";
                        var bl = new BLSales();
                        if (!isblankrow)
                        {
                            if (!isreturn)
                            {
                                ret = bl.UpdateQtyAndSalesTable(d.STOCKID, -d.DQNTY, dsInventory1.SALESINVDETAIL);
                                    // new BLSales().UpdateQty(d.STOCKID, -d.DQNTY);
                            }
                            else if (isreturn)
                            {
                                if (d.STOCKID > 0)
                                {
                                    ret = bl.UpdateQtyAndSalesTable(d.STOCKID, d.DQNTY, dsInventory1.SALESINVDETAIL);
                                        // new BLSales().UpdateQty(d.STOCKID, d.DQNTY);
                                }
                                else
                                {
                                    ret = bl.UpdateDetails(dsInventory1.SALESINVDETAIL); //ret = "1";
                                }
                            }
                        }
                        else
                        {
                            ret = bl.UpdateDetails(dsInventory1.SALESINVDETAIL);
                        }
                        if (ret != "1")
                             {
                               XtraMessageBox.Show(ret, "POS", MessageBoxButtons.OK, MessageBoxIcon.Error);
                             }
                dsInventory1.SALESINVDETAIL.AcceptChanges();
                 
            
               
              } 
            }
            sALESINVDETAILBindingSource.EndEdit();
            if (isreturn)
            {  
                UpdateTotal();
                gridControl1.Focus();
                gridView1.FocusedColumn = colINVRATE;
                colDISC.OptionsColumn.ReadOnly = false;
                colDISC.OptionsColumn.AllowEdit = true;
                gridView1.ShowEditor();
            }
            else
            {
                colDISC.OptionsColumn.AllowEdit = false;
            }
            validateoff = false;

        }