private static void InsertData(Purchase obj, List <Purchaseitems> items, string newDB)
        {
            DAL dalsession;

            try
            {
                dalsession = new DAL();
                dalsession.BeginTransaction();

                List <Purchaseitems> list_new = new List <Purchaseitems>();
                if (obj != null)
                {
                    if (CheckData(obj, newDB) != true)
                    {
                        Purchase obj_new = new Purchase
                        {
                            Uniqueno             = obj.Uniqueno,
                            Company_id           = obj.Company_id,
                            Acy_id               = obj.Acy_id,
                            Order_id             = "1",
                            Purchase_no          = obj.Purchase_no,
                            Entry_no             = obj.Entry_no,
                            Purchase_date        = obj.Purchase_date,
                            Party_id             = CParty_exten.GetId_Name(obj.Party_id),
                            Taxtype_id           = CTaxtype_exten.GetId_Name(obj.Taxtype_id),
                            Salestype_id         = "1",
                            Total_qty            = obj.Total_qty,
                            Total_taxable_amount = obj.Total_taxable_amount,
                            Total_cgst           = obj.Total_cgst,
                            Total_sgst           = obj.Total_sgst,
                            Total_igst           = obj.Total_igst,
                            Gsttotal             = obj.Gsttotal,
                            Ledger_id            = CLedger_exten.GetName_Id(obj.Ledger_id),
                            Additional           = obj.Additional,
                            Rounds               = obj.Rounds,
                            Grandtotal           = obj.Grandtotal,
                            Refered_amt          = obj.Refered_amt,
                            Locked               = obj.Locked,
                            Notes     = obj.Notes,
                            Active_id = obj.Active_id,
                            User_id   = "1"
                        };

                        //switch (obj.Company_id)
                        //{
                        //    case "1":
                        //        obj_new.Company_id = "1";
                        //        obj_new.Acy_id = "1";
                        //        break;

                        //    case "3":
                        //        obj_new.Company_id = "1";
                        //        obj_new.Acy_id = "2";
                        //        break;

                        //    case "4":
                        //        obj_new.Company_id = "1";
                        //        obj_new.Acy_id = "3";
                        //        break;

                        //}

                        obj_new.Uniqueno = obj_new.Acy_id + "~" + obj_new.Company_id + "~" + obj_new.Purchase_no;


                        CPurchase.Insert(obj_new, dalsession);
                        var vId = DAL.GetIdentity(dalsession);

                        for (int k = 0; k < items.Count; k++)
                        {
                            Purchaseitems v = new Purchaseitems()
                            {
                                Purchase_id  = vId,
                                Product_id   = CProduct_exten.GetId_Name(items[k].Product_id),
                                Sizes_id     = CSizes_exten.GetId_Name(items[k].Sizes_id),
                                Colours_id   = "1",
                                Qty          = items[k].Qty,
                                Price        = items[k].Price,
                                Cgst_percent = items[k].Cgst_percent,
                                Sgst_percent = items[k].Sgst_percent,
                                Igst_percent = items[k].Igst_percent,
                                Refered_id   = items[k].Refered_id,
                                Locked       = items[k].Locked
                            };
                            list_new.Add(v);
                        }

                        CPurchaseitems.Insert(list_new, dalsession);
                        dalsession.Commit();
                    }
                }
            }
            catch (Exception ex)

            {
                MessageBox.Show("error : " + ex);
            }
        }
示例#2
0
        private void Save_Event(string info)
        {
            if (Validation() != false)
            {
                switch (fAction)
                {
                case BtnEvent.Open:

                    if (info != Core.saveprint)
                    {
                        this.Hide();
                        Form_NeedToRefresh();
                    }
                    else
                    {
                        Print_copies();
                        this.Hide();
                        Form_NeedToRefresh();
                    }

                    break;

                case BtnEvent.New:
                    try
                    {
                        var vData = CollectData();

                        dalsession = new DAL();
                        dalsession.BeginTransaction();
                        CPurchase.Insert(vData, dalsession);
                        vId = DAL.GetIdentity(dalsession);
                        var itemsList = Collectitems(vId);
                        CPurchaseitems.Insert(itemsList, dalsession);

                        //if (Customise.Purchase_poid_dcid == true)
                        //{
                        //    CDc_refered.Refered(itemsList, itemsList, dalsession);
                        //}

                        dalsession.Commit();

                        if (info != Core.saveprint)
                        {
                            MessageBox.Show(this.FindForm(), "Record Saved Successfully.", "Save...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else
                        {
                            Print_copies();
                            this.Hide();
                            Form_NeedToRefresh();
                        }
                        //this.Hide();
                        //Form_NeedToRefresh();

                        SetAction(BtnEvent.New, null);
                        txt_order_id.Focus();
                    }
                    catch (Exception ex)
                    {
                        if (dalsession != null)
                        {
                            dalsession.Rollback();
                        }
                        MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Save...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SetFocus();
                        return;
                    }
                    break;

                case BtnEvent.Edit:
                    try
                    {
                        var vData = CollectData();

                        dalsession = new DAL();
                        dalsession.BeginTransaction();

                        var olditemslist = CPurchaseitems_exten.FK_withoutJoin(vId, new DAL());

                        CPurchaseitems.Delete(vId, dalsession);
                        CPurchase.Update(vData, dalsession);
                        var itemsList = Collectitems(vId);
                        CPurchaseitems.Insert(itemsList, dalsession);


                        //if (Customise.Purchase_poid_dcid == true)
                        //{
                        //    CDc_refered.Refered(itemsList, olditemslist, dalsession);
                        //}

                        dalsession.Commit();

                        if (info != Core.saveprint)
                        {
                            MessageBox.Show(this.FindForm(), "Record Updated Successfully.", "Update...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else
                        {
                            Print_copies();
                        }
                        this.Hide();
                        Form_NeedToRefresh();
                    }
                    catch (Exception ex)
                    {
                        if (dalsession != null)
                        {
                            dalsession.Rollback();
                        }
                        MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Update...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SetFocus();
                        return;
                    }
                    break;

                case BtnEvent.Delete:
                    try
                    {
                        dalsession = new DAL();
                        dalsession.BeginTransaction();
                        CPurchaseitems.Delete(vId, dalsession);
                        CPurchase.Delete(vId, dalsession);
                        var olditemslist = CPurchaseitems_exten.FK_withoutJoin(vId, new DAL());

                        //if (Customise.Purchase_poid_dcid == true)
                        //{
                        //    CDc_refered.Refered(olditemslist, olditemslist, dalsession);
                        //}

                        dalsession.Commit();

                        MessageBox.Show(this.FindForm(), "Record Deleted Successfully.", "Delete...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.Hide();
                        Form_NeedToRefresh();
                    }
                    catch (Exception ex)
                    {
                        if (dalsession != null)
                        {
                            dalsession.Rollback();
                        }
                        MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Update...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SetFocus();
                        return;
                    }
                    break;

                case BtnEvent.Print:
                    Print_copies();
                    this.Hide();
                    Form_NeedToRefresh();
                    break;
                }
            }
        }