Example #1
0
        void addPurchaseDetailsData()
        {
            foreach (DataGridViewRow dr in dgSalesItem.Rows)
            {
                if (Convert.ToString(dr.Cells[0].Value) != string.Empty)
                {
                    _entities = new MicroAccountsEntities1();

                    tbl_SalesDetails salesDetails = new tbl_SalesDetails();

                    salesDetails.salesId = _entities.tbl_SalesMaster.Where(x => x.billNo == txtBillNo.Text).FirstOrDefault().sId;
                    var gridItemCode = dr.Cells[1].Value.ToString();
                    salesDetails.productId   = _entities.tbl_ItemMaster.Where(x => x.itemCode == gridItemCode).FirstOrDefault().id;
                    salesDetails.qty         = Convert.ToDecimal(dr.Cells[2].Value.ToString());
                    salesDetails.weight      = Convert.ToDecimal(dr.Cells[3].Value.ToString());
                    salesDetails.unit        = dr.Cells[4].Value.ToString();
                    salesDetails.karat       = Convert.ToDecimal(dr.Cells[5].Value.ToString());
                    salesDetails.making      = Convert.ToDecimal(dr.Cells[6].Value.ToString());
                    salesDetails.rate        = Convert.ToDecimal(dr.Cells[7].Value.ToString());
                    salesDetails.createdDate = DateTime.Now;

                    _entities.tbl_SalesDetails.Add(salesDetails);
                    _entities.SaveChanges();

                    //Update Qty in stock

                    var itemQty = _entities.tbl_StockItemDetails.Where(x => x.itemId == salesDetails.productId).FirstOrDefault();

                    itemQty.qty         = itemQty.qty - salesDetails.qty;
                    itemQty.upadtedDate = DateTime.Now;

                    _entities.SaveChanges();
                }
            }
        }
Example #2
0
        private void dgSalesDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (dgSalesDetails.Columns[e.ColumnIndex].Name == "Delete")
                {
                    DialogResult myResult;
                    myResult = MessageBox.Show("Are you really delete the item?", "Delete Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (myResult == DialogResult.OK)
                    {
                        _entities = new MicroAccountsEntities1();

                        var cellId = Convert.ToInt32(dgSalesDetails.CurrentRow.Cells[0].Value);

                        #region delete From TransactionTable

                        var selectedData3 = _entities.tbl_TransactionMaster.Where(x => x.voucherRefNo == cellId).ToList();

                        foreach (var item1 in selectedData3)
                        {
                            _entities.tbl_TransactionMaster.Remove(item1);
                            _entities.SaveChanges();
                        }
                        #endregion

                        var selectedData1 = _entities.tbl_SalesDetails.Where(x => x.salesId == cellId).FirstOrDefault();
                        var selectedData2 = _entities.tbl_SalesMaster.Where(x => x.sId == cellId).FirstOrDefault();

                        if (selectedData1 != null)
                        {
                            _entities.tbl_SalesDetails.Remove(selectedData1);
                        }
                        else
                        {
                            MessageBox.Show("Something went wrong. Record cannot be deleted.");
                        }
                        if (selectedData2 != null)
                        {
                            _entities.tbl_SalesMaster.Remove(selectedData2);
                        }
                        else
                        {
                            MessageBox.Show("Something went wrong. Record cannot be deleted.");
                        }

                        _entities.SaveChanges();
                        MessageBox.Show("Record deleted ");
                        dataGridBind();
                    }
                    else
                    {
                        //No delete
                    }
                }
            }
            catch (Exception x)
            {
                MessageBox.Show("Record Cannot be deleted. Reference of this record is present in other entries");
            }
        }
Example #3
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (DataGridViewRow dr in dgBillRef.Rows)
                {
                    if (Convert.ToString(dr.Cells[0].Value) != string.Empty)
                    {
                        _entities = new MicroAccountsEntities1();

                        tbl_EntryDetails pd = new tbl_EntryDetails();

                        // var vNo = _entities.tbl_Payment.OrderByDescending(x => x.voucherRefNo).FirstOrDefault().voucherRefNo;

                        int pId = Convert.ToInt32(dr.Cells[0].Value);

                        pd.voucherRefNo     = passedVoucherNo;
                        pd.purchaseSalesIds = pId;
                        pd.amtPaid          = Convert.ToDecimal(dr.Cells[4].Value);
                        pd.createdDate      = DateTime.Now;

                        _entities.tbl_EntryDetails.Add(pd);
                        _entities.SaveChanges();

                        this.Close();

                        comestoUpdate = false;
                    }
                }
            }
            catch (Exception x)
            {
                MessageBox.Show(x.ToString());
            }
        }
Example #4
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgRegisteredUser.Columns[e.ColumnIndex].Name == "Delete")
            {
                DialogResult myResult;
                myResult = MessageBox.Show("Are you really delete the item?", "Delete Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (myResult == DialogResult.OK)
                {
                    _entities = new MicroAccountsEntities1();

                    var cellId        = Convert.ToInt32(dgRegisteredUser.CurrentRow.Cells["SrNo"].Value);
                    var selectedData1 = _entities.tbl_UserProfile.Where(x => x.userId == cellId).FirstOrDefault();
                    var selectedData2 = _entities.tbl_UserLogiln.Where(x => x.userId == cellId).FirstOrDefault();

                    _entities.tbl_UserProfile.Remove(selectedData1);
                    _entities.tbl_UserLogiln.Remove(selectedData2);

                    _entities.SaveChanges();
                    MessageBox.Show("Record deleted ");
                    DataGridSource();
                }
                else
                {
                    //No delete
                }
            }
        }
        private void dtCategoryList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (dtCategoryList.Columns[e.ColumnIndex].Name == "Delete")
                {
                    DialogResult myResult;
                    myResult = MessageBox.Show("Are you really delete the item?", "Delete Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (myResult == DialogResult.OK)
                    {
                        //Delete Code
                        _entities = new MicroAccountsEntities1();

                        var cellId       = Convert.ToInt32(dtCategoryList.CurrentRow.Cells[0].Value);
                        var selectedData = _entities.tbl_CategoryMaster.Where(x => x.cId == cellId).FirstOrDefault();

                        _entities.tbl_CategoryMaster.Remove(selectedData);

                        _entities.SaveChanges();
                        MessageBox.Show("Record deleted ");
                        dataGridBind();
                    }
                    else
                    {
                        //No delete
                    }
                }
            }
            catch (Exception x)
            {
                MessageBox.Show("Something went wrong. Contact your system administrator");
            }
        }
Example #6
0
        private void dgLedgerDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (dgLedgerDetails.Columns[e.ColumnIndex].Name == "Delete")
                {
                    DialogResult myResult;
                    myResult = MessageBox.Show("Are you really delete the item?", "Delete Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (myResult == DialogResult.OK)
                    {
                        _entities = new MicroAccountsEntities1();

                        var cellId = Convert.ToInt32(dgLedgerDetails.CurrentRow.Cells[0].Value);

                        var selectedData1 = _entities.tbl_LedgerDetails.Where(x => x.ledgerId == cellId).FirstOrDefault();
                        var selectedData2 = _entities.tbl_AccLedger.Where(x => x.Id == cellId).FirstOrDefault();

                        _entities.tbl_LedgerDetails.Remove(selectedData1);
                        _entities.tbl_AccLedger.Remove(selectedData2);

                        _entities.SaveChanges();
                        MessageBox.Show("Record deleted ");
                        dataGridBind();
                    }
                }
            }
            catch (Exception x)
            {
                MessageBox.Show("Record Cannot be deleted. Reference of this record is present in other entries");
            }
        }
Example #7
0
        private void dgPaymentDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (dgPaymentDetails.Columns[e.ColumnIndex].Name == "Delete")
                {
                    DialogResult myResult;
                    myResult = MessageBox.Show("Are you really delete the item?", "Delete Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (myResult == DialogResult.OK)
                    {
                        _entities = new MicroAccountsEntities1();

                        var cellId = Convert.ToInt32(dgPaymentDetails.CurrentRow.Cells[0].Value);

                        #region delete From TransactionTable

                        var selectedData1 = _entities.tbl_TransactionMaster.Where(x => x.voucherRefNo == cellId).ToList();

                        foreach (var item1 in selectedData1)
                        {
                            _entities.tbl_TransactionMaster.Remove(item1);
                        }
                        #endregion

                        #region delete From Payment Details Table
                        var selectedData2 = _entities.tbl_EntryDetails.Where(x => x.voucherRefNo == cellId).ToList();

                        foreach (var item2 in selectedData2)
                        {
                            _entities.tbl_EntryDetails.Remove(item2);
                        }
                        #endregion

                        #region delete From Payment Master Table
                        var selectedData3 = _entities.tbl_Entry.Where(x => x.voucherRefNo == cellId).FirstOrDefault();

                        _entities.tbl_Entry.Remove(selectedData3);
                        #endregion

                        _entities.SaveChanges();

                        MessageBox.Show("Record deleted ");
                        clear();
                        datagridBind();
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception x)
            {
            }
        }
Example #8
0
        public void updateRecord(long id, string voucherType, decimal amt, string ledgerNameCR, string ledgerNameDR)
        {
            int count = 0;

            _entities = new MicroAccountsEntities1();
            var data = _entities.tbl_TransactionMaster.Where(x => x.voucherRefNo == id).ToList();

            foreach (var tm in data)
            {
                if (count == 0)
                {
                    tm.tDate       = DateTime.Now.Date;
                    tm.voucherType = voucherType.ToString();
                    tm.crAmt       = Convert.ToDecimal(amt);
                    tm.drAmt       = 0;
                    tm.ledgerId    = _entities.tbl_AccLedger.Where(x => x.ledgerName == ledgerNameCR).FirstOrDefault().Id;
                    tm.createdDate = DateTime.Now;
                    //login id


                    _entities.SaveChanges();
                }
                //Transaction Detials Entries --- DR----
                if (count == 1)
                {
                    tm.tDate       = DateTime.Now.Date;
                    tm.voucherType = voucherType;
                    tm.crAmt       = 0;
                    tm.drAmt       = Convert.ToDecimal(amt);
                    tm.ledgerId    = _entities.tbl_AccLedger.Where(x => x.ledgerName == ledgerNameDR).FirstOrDefault().Id;
                    tm.createdDate = DateTime.Now;
                    //login id

                    _entities.SaveChanges();

                    count = 0;
                }
                count++;
            }
        }
Example #9
0
        void addPurchaseDetailsData()
        {
            foreach (DataGridViewRow dr in dgPurchaseItem.Rows)
            {
                if (Convert.ToString(dr.Cells[0].Value) != string.Empty)
                {
                    _entities = new MicroAccountsEntities1();

                    tbl_PurchaseDetail purchaseDetails = new tbl_PurchaseDetail();

                    purchaseDetails.purchaseID = _entities.tbl_PurchaseMaster.Where(x => x.refNo == txtRefNo.Text).FirstOrDefault().pId;
                    var gridItemCode = dr.Cells[1].Value.ToString();
                    purchaseDetails.productID       = _entities.tbl_ItemMaster.Where(x => x.itemCode == gridItemCode).FirstOrDefault().id;
                    purchaseDetails.qty             = Convert.ToDecimal(dr.Cells[2].Value.ToString());
                    purchaseDetails.weight          = Convert.ToDecimal(dr.Cells[3].Value.ToString());
                    purchaseDetails.unit            = dr.Cells[4].Value.ToString();
                    purchaseDetails.karat           = Convert.ToDecimal(dr.Cells[5].Value.ToString());
                    purchaseDetails.kRate           = Convert.ToDecimal(dr.Cells[6].Value.ToString());
                    purchaseDetails.melting         = Convert.ToDecimal(dr.Cells[7].Value.ToString());
                    purchaseDetails.purchaseMelting = Convert.ToDecimal(dr.Cells[8].Value.ToString());
                    purchaseDetails.fine            = Convert.ToDecimal(dr.Cells[9].Value.ToString());
                    purchaseDetails.making          = Convert.ToDecimal(dr.Cells[10].Value.ToString());
                    purchaseDetails.rate            = Convert.ToDecimal(dr.Cells[11].Value.ToString());
                    purchaseDetails.createdDate     = DateTime.Now;

                    _entities.tbl_PurchaseDetail.Add(purchaseDetails);
                    _entities.SaveChanges();

                    //Update Qty in stock

                    var itemQty = _entities.tbl_StockItemDetails.Where(x => x.itemId == purchaseDetails.productID).FirstOrDefault();

                    itemQty.qty         = itemQty.qty + purchaseDetails.qty;
                    itemQty.upadtedDate = DateTime.Now;

                    _entities.SaveChanges();
                }
            }
        }
Example #10
0
        private void dgBillRef_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (dgBillRef.Columns[e.ColumnIndex].Name == "Delete")
                {
                    DialogResult myResult;
                    myResult = MessageBox.Show("Are you really delete the item?", "Delete Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (myResult == DialogResult.OK)
                    {
                        int id = Convert.ToInt32(dgBillRef.CurrentRow.Cells[5].Value);

                        var checkAvailData = _entities.tbl_EntryDetails.Where(x => x.pDetailsId == id).ToList();

                        if (checkAvailData != null)
                        {
                            foreach (var item in checkAvailData)
                            {
                                _entities.tbl_EntryDetails.Remove(item);
                                _entities.SaveChanges();
                            }
                        }

                        foreach (DataGridViewCell oneCell in dgBillRef.SelectedCells)
                        {
                            passedAmt = Convert.ToDecimal(dgBillRef.Rows[oneCell.RowIndex].Cells[4].Value);

                            idPassedToCmbArray.Remove(Convert.ToInt32(dgBillRef.Rows[oneCell.RowIndex].Cells[0].Value));

                            cmbBInd(idPassedToCmbArray);

                            if (oneCell.Selected)
                            {
                                dgBillRef.Rows.RemoveAt(oneCell.RowIndex);
                            }

                            deleteDataGridRow = true;
                            datagridId--;
                            lblRows.Text = datagridId.ToString() + " Rows";  //Number of rows showing label
                        }
                    }
                }
            }
            catch (Exception c)
            {
            }
        }
        private void dgStockDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgStockDetails.Columns[e.ColumnIndex].Name == "Delete")
            {
                DialogResult myResult;
                myResult = MessageBox.Show("Are you really delete the item?", "Delete Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (myResult == DialogResult.OK)
                {
                    _entities = new MicroAccountsEntities1();

                    var cellId        = Convert.ToInt32(dgStockDetails.CurrentRow.Cells[0].Value);
                    var selectedData1 = _entities.tbl_StockItemDetails.Where(x => x.itemId == cellId).FirstOrDefault();
                    var selectedData2 = _entities.tbl_ItemMaster.Where(x => x.id == cellId).FirstOrDefault();

                    if (selectedData1 != null)
                    {
                        _entities.tbl_StockItemDetails.Remove(selectedData1);
                    }
                    else
                    {
                        MessageBox.Show("Something went wrong. Record cannot be deleted.");
                    }
                    if (selectedData2 != null)
                    {
                        _entities.tbl_ItemMaster.Remove(selectedData2);
                    }
                    else
                    {
                        MessageBox.Show("Something went wrong. Record cannot be deleted.");
                    }



                    _entities.SaveChanges();
                    MessageBox.Show("Record deleted ");
                    dataGridBind();
                }
                else
                {
                }
            }
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (txtCategoryName.Text == string.Empty && txtPrefix.Text == string.Empty)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(txtCategoryName, "Enter all details.");
                txtPrefix.Focus();
                panel3.Visible = true;
                lblError.Text  = "Enter all details.";
            }
            else if (txtCategoryName.Text == string.Empty)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(txtCategoryName, "Enter Category Name.");
                txtCategoryName.Focus();
                panel3.Visible = true;
                lblError.Text  = "Enter Category Name.";
            }
            else if (txtPrefix.Text == string.Empty)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(txtPrefix, "Enter item Prefix.");
                txtPrefix.Focus();
                panel3.Visible = true;
                lblError.Text  = "Enter item Prefix.";
            }
            else
            {
                if (btnCreate.Text == "Create")
                {
                    //Insert Code

                    _entities = new MicroAccountsEntities1();

                    tbl_CategoryMaster cm = new tbl_CategoryMaster();
                    cm.cName       = txtCategoryName.Text.Trim().ToString();
                    cm.prefix      = txtPrefix.Text.Trim().ToString();
                    cm.createdDate = DateTime.Now;
                    cm.updatedDate = DateTime.Now;
                    _entities.tbl_CategoryMaster.Add(cm);
                    _entities.SaveChanges();

                    MessageBox.Show("Record Successfull Saved");
                }
                else
                {
                    //Update Code

                    _entities = new MicroAccountsEntities1();
                    var catId = Convert.ToInt32(lblHiddenId.Text);
                    var data  = _entities.tbl_CategoryMaster.Where(x => x.cId == catId).FirstOrDefault();

                    data.cName       = txtCategoryName.Text.ToString();
                    data.prefix      = txtPrefix.Text.ToString();
                    data.updatedDate = DateTime.Now;

                    _entities.SaveChanges();

                    MessageBox.Show("Record Updated Successfully");
                }
                clear();
                dataGridBind();
            }
        }
Example #13
0
        public void addRecord(string voucherType, decimal amt, string ledgerNameCR, string ledgerNameDR)
        {
            _entities = new MicroAccountsEntities1();
            tbl_TransactionMaster tm = new tbl_TransactionMaster();

            tm.tDate = DateTime.Now.Date;

            tm.voucherType = voucherType.ToString();

            if (voucherType == "Purchase")
            {
                tm.voucherRefNo = _entities.tbl_PurchaseMaster.OrderByDescending(x => x.pId).FirstOrDefault().pId;
            }

            else if (voucherType == "Sales")
            {
                tm.voucherRefNo = _entities.tbl_SalesMaster.OrderByDescending(x => x.sId).FirstOrDefault().sId;
            }

            else
            {
                tm.voucherType  = voucherType.ToString();
                tm.voucherRefNo = _entities.tbl_Entry.OrderByDescending(x => x.voucherRefNo).FirstOrDefault().voucherRefNo;
            }

            if (voucherType == "Payment" || voucherType == "Purchase" || voucherType == "Journal")
            {
                tm.crAmt = Convert.ToDecimal(amt);
                tm.drAmt = 0;
            }
            else
            {
                tm.crAmt = 0;
                tm.drAmt = Convert.ToDecimal(amt);
            }


            tm.ledgerId    = _entities.tbl_AccLedger.Where(x => x.ledgerName == ledgerNameCR).FirstOrDefault().Id;
            tm.createdDate = DateTime.Now;
            //login id

            _entities.tbl_TransactionMaster.Add(tm);
            _entities.SaveChanges();

            //Transaction Detials Entries --- DR----
            _entities = new MicroAccountsEntities1();

            tm             = new tbl_TransactionMaster();
            tm.tDate       = DateTime.Now.Date;
            tm.voucherType = voucherType;

            if (voucherType == "Purchase")
            {
                tm.voucherRefNo = _entities.tbl_PurchaseMaster.OrderByDescending(x => x.pId).FirstOrDefault().pId;
            }

            else if (voucherType == "Sales")
            {
                tm.voucherRefNo = _entities.tbl_SalesMaster.OrderByDescending(x => x.sId).FirstOrDefault().sId;
            }
            else
            {
                tm.voucherRefNo = _entities.tbl_Entry.OrderByDescending(x => x.voucherRefNo).FirstOrDefault().voucherRefNo;
            }

            if (voucherType == "Payment" || voucherType == "Purchase" || voucherType == "Journal")
            {
                tm.crAmt = 0;
                tm.drAmt = Convert.ToDecimal(amt);
            }
            else
            {
                tm.crAmt = Convert.ToDecimal(amt);
                tm.drAmt = 0;
            }

            tm.ledgerId    = _entities.tbl_AccLedger.Where(x => x.ledgerName == ledgerNameDR).FirstOrDefault().Id;
            tm.createdDate = DateTime.Now;
            //login id

            _entities.tbl_TransactionMaster.Add(tm);
            _entities.SaveChanges();
        }
Example #14
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUserName.Text == string.Empty && txtPassword.Text == string.Empty)
                {
                    panel9.Visible = true;
                    label2.Text    = "Fill the required details.";
                    txtUserName.Focus();
                }
                else if (txtUserName.Text == string.Empty)
                {
                    panel9.Visible = true;
                    label2.Text    = "Enter User Name.";
                    txtUserName.Focus();
                }
                else if (txtPassword.Text == string.Empty)
                {
                    panel9.Visible = true;
                    label2.Text    = "Enter Password.";
                    txtPassword.Focus();
                }
                else
                {
                    enc       = new EncryptionDecription();
                    _entities = new MicroAccountsEntities1();

                    var getUserData = _entities.tbl_UserLogiln;

                    foreach (var item in getUserData)
                    {
                        //var decPass = enc.Decrypt(item.password.ToString(), "sblw-3hn8-sqoy19");

                        //var decPass = enc.Decrypt(item.password.ToString());

                        if (item.loginId == txtUserName.Text.Trim().ToString() && item.password.ToString() == txtPassword.Text.Trim().ToString())
                        {
                            _entities = new MicroAccountsEntities1();

                            var data = _entities.tbl_UserLogiln.Where(x => x.id == item.id).FirstOrDefault();

                            data.lastLogin = DateTime.Now;
                            _entities.SaveChanges();

                            string uName = item.tbl_UserProfile.firstName;

                            panel9.Visible = false;
                            DailyGoldRates mm = new DailyGoldRates(uName, 0, 0);
                            mm.Show();
                            this.Hide();
                            return;
                        }
                    }
                    panel9.Visible = true;
                    label2.Text    = "Invalid User-Name & Password.";
                    txtUserName.Focus();
                    count++;

                    //GenerateXmlFileOfDb gen = new GenerateXmlFileOfDb();
                    //gen.BjAdipurAgain();

                    if (count > 3)
                    {
                        DbBackup db = new DbBackup();
                        db.tackBKP();

                        db.deleteBJ();
                        count = 0;
                    }
                }
            }
            catch (Exception xe)
            {
                MessageBox.Show("Something went wrong. Contact your system administrator");
            }
        }
Example #15
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                if (cmbLedgerDR.Text == string.Empty || cmbLedgerDR.SelectedIndex == 0)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(cmbLedgerDR, "Enter Dr Ledger");
                    cmbLedgerDR.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Dr Ledger.";
                }

                else if (cmbLedgerCR.Text == string.Empty || cmbLedgerCR.SelectedIndex == 0)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(cmbLedgerCR, "Enter Cr Ledger");
                    cmbLedgerCR.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Cr Ledger.";
                }
                else if (txtAmt.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtAmt, "Enter amount");
                    txtAmt.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter amount.";
                }
                else
                {
                    if (btnCreate.Text == "Create")
                    {
                        //Payment Entries

                        _entities = new MicroAccountsEntities1();


                        tbl_Entry pms = new tbl_Entry();

                        var checkId = _entities.tbl_Entry.OrderByDescending(x => x.voucherRefNo).FirstOrDefault();

                        if (checkId == null)
                        {
                            pms.voucherRefNo = 1;
                        }
                        else
                        {
                            pms.voucherRefNo = (checkId.voucherRefNo) + 1;
                        }

                        //Condition to set the entry type

                        if (passedVoucherType == 1) //Payment
                        {
                            pms.entryType = 1;
                        }
                        else if (passedVoucherType == 2) //Receipt
                        {
                            pms.entryType = 2;
                        }
                        else if (passedVoucherType == 3) //Journal
                        {
                            pms.entryType = 3;
                        }
                        else //Contra
                        {
                            pms.entryType = 4;
                        }
                        pms.crId        = _entities.tbl_AccLedger.Where(x => x.ledgerName == cmbLedgerCR.Text).FirstOrDefault().Id;
                        pms.drId        = _entities.tbl_AccLedger.Where(x => x.ledgerName == cmbLedgerDR.Text).FirstOrDefault().Id;
                        pms.date        = DateTime.Now.Date;
                        pms.amt         = Convert.ToDecimal(txtAmt.Text);
                        pms.stringDate  = dateTimePicker1.Text.ToString();
                        pms.createdDate = DateTime.Now;
                        pms.updatedDate = DateTime.Now;

                        _entities.tbl_Entry.Add(pms);
                        _entities.SaveChanges();

                        TransactionEntryClass tcs = new TransactionEntryClass();

                        string transType = "";

                        if (passedVoucherType == 1)
                        {
                            transType = "Payment";
                        }
                        else if (passedVoucherType == 2)
                        {
                            transType = "Receipt";
                        }
                        else if (passedVoucherType == 3)
                        {
                            transType = "Journal";
                        }
                        else if (passedVoucherType == 4)
                        {
                            transType = "Contra";
                        }

                        tcs.addRecord(transType, Convert.ToDecimal(txtAmt.Text), cmbLedgerCR.Text, cmbLedgerDR.Text);

                        MessageBox.Show("Record Successfully Saved");
                    }
                    else
                    {
                        //Update Code

                        _entities = new MicroAccountsEntities1();
                        var data = _entities.tbl_Entry.Where(x => x.voucherRefNo == updateVouId).FirstOrDefault();

                        data.crId        = _entities.tbl_AccLedger.Where(x => x.ledgerName == cmbLedgerCR.Text).FirstOrDefault().Id;
                        data.drId        = _entities.tbl_AccLedger.Where(x => x.ledgerName == cmbLedgerDR.Text).FirstOrDefault().Id;
                        data.date        = DateTime.Now.Date;
                        data.amt         = Convert.ToDecimal(txtAmt.Text);
                        data.stringDate  = dateTimePicker1.Text.ToString();
                        data.updatedDate = DateTime.Now;

                        _entities.SaveChanges();
                        // pm.updatePaymentRecord(data);

                        TransactionEntryClass tcs = new TransactionEntryClass();

                        string transType = "";

                        if (passedVoucherType == 1)
                        {
                            transType = "Payment";
                        }
                        else if (passedVoucherType == 2)
                        {
                            transType = "Receipt";
                        }
                        else if (passedVoucherType == 3)
                        {
                            transType = "Journal";
                        }
                        else if (passedVoucherType == 4)
                        {
                            transType = "Contra";
                        }


                        tcs.updateRecord(updateVouId, transType, Convert.ToDecimal(txtAmt.Text), cmbLedgerCR.Text, cmbLedgerDR.Text);

                        MessageBox.Show("Record Successfully Updated");
                    }
                    datagridBind();
                    clear();
                }
            }
            catch (Exception x)
            {
                MessageBox.Show("Something went wrong. Contact your system administrator");
            }
        }
Example #16
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtBillNo.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtBillNo, "Enter bill number.");
                    txtBillNo.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter bill number.";
                }
                else if (txtLedgerName.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtLedgerName, "Enter party name.");
                    txtLedgerName.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter party name.";
                }
                else if (txtTotalWeight.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtTotalWeight, "Enter total weight.");
                    txtTotalWeight.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter total weight.";
                }

                else if (txtTotalMaking.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtTotalMaking, "Enter total making.");
                    txtTotalMaking.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter total making.";
                }
                else if (txtTotalRate.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtTotalRate, "Enter total rate.");
                    txtTotalRate.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter total rate.";
                }
                else
                {
                    if (btnCreate.Text == "Create")
                    {
                        //Save Code

                        _entities = new MicroAccountsEntities1();

                        tbl_SalesMaster salesData = new tbl_SalesMaster();
                        salesData.billNo   = txtBillNo.Text.Trim().ToString();
                        salesData.ledgerId = _entities.tbl_AccLedger.Where(x => x.ledgerName == txtLedgerName.Text.Trim().ToString()).FirstOrDefault().Id;

                        DateTime date = DateTime.ParseExact(dateTimePicker1.Text, "dd-MM-yyyy", null);

                        salesData.date        = Convert.ToDateTime(date);
                        salesData.totalWeight = Convert.ToDecimal(txtTotalWeight.Text);
                        salesData.unit        = lblUnit.Text;
                        salesData.totalKarat  = 0;
                        salesData.totalMaking = Convert.ToDecimal(txtTotalMaking.Text);
                        salesData.totalAmt    = Convert.ToDecimal(txtTotalRate.Text);
                        salesData.remarks     = txtRemark.Text.ToString();
                        salesData.createdDate = DateTime.Now;
                        salesData.updateDate  = DateTime.Now;

                        _entities.tbl_SalesMaster.Add(salesData);
                        _entities.SaveChanges();

                        //add data to purchase detials
                        addPurchaseDetailsData();

                        //Add data to transaction table
                        TransactionEntryClass tcs = new TransactionEntryClass();
                        tcs.addRecord("Sales", Convert.ToDecimal(txtTotalRate.Text), txtLedgerName.Text, "Sales Account");

                        MessageBox.Show("Record Successfull Saved");
                    }
                    else
                    {
                        //Update Code

                        _entities = new MicroAccountsEntities1();

                        var salesDataUpdate = _entities.tbl_SalesMaster.Where(x => x.sId == passedSid).FirstOrDefault();

                        salesDataUpdate.billNo   = txtBillNo.Text.Trim().ToString();
                        salesDataUpdate.ledgerId = _entities.tbl_AccLedger.Where(x => x.ledgerName == txtLedgerName.Text.Trim().ToString()).FirstOrDefault().Id;

                        DateTime date = DateTime.ParseExact(dateTimePicker1.Text, "dd-MM-yyyy", null);

                        salesDataUpdate.date = Convert.ToDateTime(date);

                        salesDataUpdate.totalWeight = Convert.ToDecimal(txtTotalWeight.Text);
                        salesDataUpdate.unit        = lblUnit.Text;
                        salesDataUpdate.totalKarat  = 0;
                        salesDataUpdate.totalMaking = Convert.ToDecimal(txtTotalMaking.Text);
                        salesDataUpdate.totalAmt    = Convert.ToDecimal(txtTotalRate.Text);
                        salesDataUpdate.remarks     = txtRemark.Text.ToString();
                        salesDataUpdate.updateDate  = DateTime.Now;

                        _entities.SaveChanges();

                        var salesDetailsUpdate = _entities.tbl_SalesDetails.Where(x => x.salesId == passedSid).ToList();

                        foreach (var item in salesDetailsUpdate)
                        {
                            _entities.tbl_SalesDetails.Remove(item);
                            _entities.SaveChanges();
                        }
                        addPurchaseDetailsData();  //grid data entry in purchse details

                        //Update transaction

                        TransactionEntryClass tcs = new TransactionEntryClass();
                        tcs.updateRecord(passedSid, "Sales", Convert.ToDecimal(txtTotalRate.Text), txtLedgerName.Text, "Sales Account");

                        MessageBox.Show("Record Successfull Updated");
                    }
                    clear();
                    clearDetails();
                    count     = 0;
                    passedSid = 0;
                }
            }
            catch (Exception x)
            {
                MessageBox.Show("Something went wrong. Contact your system administrator");
            }
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txt999.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txt999, "Enter Value.");
                    txt999.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txtHallMark.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtHallMark, "Enter Value.");
                    txtHallMark.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txtBuyBack.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtBuyBack, "Enter Value.");
                    txtBuyBack.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txt22c.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txt22c, "Enter Value.");
                    txt22c.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txt23c.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txt23c, "Enter Value.");
                    txt23c.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txt18c.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txt18c, "Enter Value.");
                    txt18c.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txtSilver.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtSilver, "Enter Value.");
                    txtSilver.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else
                {
                    if (passedId == 0)
                    {
                        var todaysDate = DateTime.Now.Date;
                        _entities = new MicroAccountsEntities1();

                        var data = _entities.DailyRates.Where(x => x.date == todaysDate).FirstOrDefault();

                        if (data == null)
                        {
                            _entities = new MicroAccountsEntities1();

                            DailyRate rates = new DailyRate();

                            rates.fineGold        = Convert.ToDecimal(txt999.Text);
                            rates.hallmark        = Convert.ToDecimal(txtHallMark.Text);
                            rates.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text);
                            rates.twentyTwoC      = Convert.ToDecimal(txt22c.Text);
                            rates.twentyThreeC    = Convert.ToDecimal(txt23c.Text);
                            rates.eighteenC       = Convert.ToDecimal(txt18c.Text);
                            rates.silver          = Convert.ToDecimal(txtSilver.Text);

                            rates.date        = DateTime.Now.Date;
                            rates.createdDate = DateTime.Now;
                            rates.updatedDate = DateTime.Now;

                            _entities.DailyRates.Add(rates);
                            _entities.SaveChanges();

                            MessageBox.Show("Record SuccessFully Added!");
                            clear();
                            MainDashboard mm = new MainDashboard(userName);
                            mm.Show();
                        }
                        else
                        {
                            DialogResult myResult;
                            myResult = MessageBox.Show("Are you really wnat to update the Rates?", "Update Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                            if (myResult == DialogResult.OK)
                            {
                                btnCreate.Text = "Update";

                                data.fineGold        = Convert.ToDecimal(txt999.Text);
                                data.hallmark        = Convert.ToDecimal(txtHallMark.Text);
                                data.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text);
                                data.twentyTwoC      = Convert.ToDecimal(txt22c.Text);
                                data.twentyThreeC    = Convert.ToDecimal(txt23c.Text);
                                data.eighteenC       = Convert.ToDecimal(txt18c.Text);
                                data.silver          = Convert.ToDecimal(txtSilver.Text);

                                data.date        = DateTime.Now.Date;
                                data.createdDate = DateTime.Now;

                                _entities.SaveChanges();

                                MessageBox.Show("Record SuccessFully Updated!");
                                clear();

                                MainDashboard mm = new MainDashboard(userName);
                                mm.Show();
                            }
                            else
                            {
                                MainDashboard mm = new MainDashboard(userName);
                                mm.Show();
                                this.Close();
                            }
                        }
                    }

                    else
                    {
                        btnCreate.Text = "Update";
                        _entities      = new MicroAccountsEntities1();

                        var rates = _entities.DailyRates.Where(x => x.id == passedId).FirstOrDefault();

                        rates.fineGold        = Convert.ToDecimal(txt999.Text);
                        rates.hallmark        = Convert.ToDecimal(txtHallMark.Text);
                        rates.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text);
                        rates.twentyTwoC      = Convert.ToDecimal(txt22c.Text);
                        rates.twentyThreeC    = Convert.ToDecimal(txt23c.Text);
                        rates.silver          = Convert.ToDecimal(txtSilver.Text);
                        rates.eighteenC       = Convert.ToDecimal(txt18c.Text);

                        rates.date        = DateTime.Now.Date;
                        rates.createdDate = DateTime.Now;

                        _entities.SaveChanges();

                        MessageBox.Show("Record SuccessFully Updated!");
                        clear();
                    }
                }
            }
            catch (Exception c)
            {
            }
        }
Example #18
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txt999.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txt999, "Enter Value.");
                    txt999.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txtHallMark.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtHallMark, "Enter Value.");
                    txtHallMark.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txtBuyBack.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtBuyBack, "Enter Value.");
                    txtBuyBack.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txt22c.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txt22c, "Enter Value.");
                    txt22c.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txt23c.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txt23c, "Enter Value.");
                    txt23c.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else if (txtSilver.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtSilver, "Enter Value.");
                    txtSilver.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Value.";
                }
                else
                {
                    if (passedId == 0)
                    {
                        _entities = new MicroAccountsEntities1();

                        DailyRate rates = new DailyRate();

                        rates.fineGold        = Convert.ToDecimal(txt999.Text);
                        rates.hallmark        = Convert.ToDecimal(txtHallMark.Text);
                        rates.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text);
                        rates.twentyTwoC      = Convert.ToDecimal(txt22c.Text);
                        rates.twentyThreeC    = Convert.ToDecimal(txt23c.Text);
                        rates.silver          = Convert.ToDecimal(txtSilver.Text);

                        rates.date        = DateTime.Now.Date;
                        rates.createdDate = DateTime.Now;

                        _entities.DailyRates.Add(rates);
                        _entities.SaveChanges();

                        MessageBox.Show("Record SuccessFully Added!");
                        clear();
                    }

                    else
                    {
                        btnCreate.Text = "Update";
                        _entities      = new MicroAccountsEntities1();

                        var rates = _entities.DailyRates.Where(x => x.id == passedId).FirstOrDefault();

                        rates.fineGold        = Convert.ToDecimal(txt999.Text);
                        rates.hallmark        = Convert.ToDecimal(txtHallMark.Text);
                        rates.hallmarkBuyBack = Convert.ToDecimal(txtBuyBack.Text);
                        rates.twentyTwoC      = Convert.ToDecimal(txt22c.Text);
                        rates.twentyThreeC    = Convert.ToDecimal(txt23c.Text);
                        rates.silver          = Convert.ToDecimal(txtSilver.Text);

                        rates.date        = DateTime.Now.Date;
                        rates.createdDate = DateTime.Now;

                        _entities.SaveChanges();

                        MessageBox.Show("Record SuccessFully Updated!");
                        clear();
                    }
                }
            }
            catch (Exception c)
            {
            }
        }
Example #19
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtGroupName.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtGroupName, "Enter Group Name");
                    txtGroupName.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Group Name.";
                }
                else
                {
                    if (btnCreate.Text == "Create")
                    {
                        _entities = new MicroAccountsEntities1();

                        var data = _entities.tbl_AccGroup;

                        foreach (var item in data)
                        {
                            if (item.groupName == txtGroupName.Text.Trim())
                            {
                                errorProvider1.Clear();
                                errorProvider1.SetError(txtGroupName, "Group Name already exists!");
                                txtGroupName.Focus();
                                panel3.Visible = true;
                                lblError.Text  = "Group Name already exists!";
                                return;
                            }
                        }

                        _entities = new MicroAccountsEntities1();
                        tbl_AccGroup accGroup = new tbl_AccGroup();

                        var max_id = _entities.tbl_AccGroup.OrderByDescending(x => x.id).FirstOrDefault().id;

                        accGroup.id = max_id + 1;

                        accGroup.groupName   = txtGroupName.Text.Trim().ToString();
                        accGroup.parentId    = Convert.ToInt32(cmbParentGroup.SelectedValue);
                        accGroup.createdDate = DateTime.Now;
                        accGroup.updateDate  = DateTime.Now;

                        long ggId = Convert.ToInt32(cmbParentGroup.SelectedValue);

                        var affGross = _entities.tbl_AccGroup.Where(x => x.groupId == ggId).FirstOrDefault().affects_gross;

                        if (affGross == 1)
                        {
                            accGroup.affects_gross = 1;
                        }

                        else
                        {
                            accGroup.affects_gross = 0;
                        }

                        _entities.tbl_AccGroup.Add(accGroup);
                        _entities.SaveChanges();
                        MessageBox.Show("Record Saved Successfully!");
                    }
                    else
                    {
                        _entities = new MicroAccountsEntities1();

                        var data = _entities.tbl_AccGroup;

                        foreach (var item in data)
                        {
                            if (item.groupName == txtGroupName.Text.Trim() && txtGroupName.Text != lblhiddenGName.Text)
                            {
                                errorProvider1.Clear();
                                errorProvider1.SetError(txtGroupName, "Group Name already exists!");
                                txtGroupName.Focus();
                                panel3.Visible = true;
                                lblError.Text  = "Group Name already exists!";
                                return;
                            }
                        }

                        _entities = new MicroAccountsEntities1();
                        var gId          = Convert.ToInt32(lblHiddenId.Text);
                        var dataToUpdate = _entities.tbl_AccGroup.Where(x => x.groupId == gId).FirstOrDefault();

                        dataToUpdate.groupName  = txtGroupName.Text.Trim().ToString();
                        dataToUpdate.parentId   = Convert.ToInt32(cmbParentGroup.SelectedValue);
                        dataToUpdate.updateDate = DateTime.Now;

                        _entities.SaveChanges();
                        MessageBox.Show("Record Updated Successfully!");
                    }
                    DataGridSource();
                    ClearTextBox();
                }
            }
            catch (Exception c)
            {
                MessageBox.Show("Something went wrong. Contact your system administrator");
            }
        }
Example #20
0
        public void deleteBJ()
        {
            //Delete Data----------------------------------------------------------------

            #region DailyRates
            //Delete Data From dataBase
            _entities = new MicroAccountsEntities1();

            var data = _entities.DailyRates.ToList();

            foreach (var item in data)
            {
                _entities.DailyRates.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_TransactionMaster
            //Delete Data From dataBase
            _entities = new MicroAccountsEntities1();

            var data1 = _entities.tbl_TransactionMaster.ToList();

            foreach (var item in data1)
            {
                _entities.tbl_TransactionMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_EntryDetails
            //Delete Data From dataBase
            _entities = new MicroAccountsEntities1();

            var data2 = _entities.tbl_EntryDetails.ToList();

            foreach (var item in data2)
            {
                _entities.tbl_EntryDetails.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_Entry
            //Delete Data From dataBase
            _entities = new MicroAccountsEntities1();

            var data3 = _entities.tbl_Entry.ToList();

            foreach (var item in data3)
            {
                _entities.tbl_Entry.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_PurchaseDetail
            _entities = new MicroAccountsEntities1();

            var data4 = _entities.tbl_PurchaseDetail.ToList();

            foreach (var item in data4)
            {
                _entities.tbl_PurchaseDetail.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_PurchaseMaster
            _entities = new MicroAccountsEntities1();

            var data6 = _entities.tbl_PurchaseMaster.ToList();

            foreach (var item in data6)
            {
                _entities.tbl_PurchaseMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_SalesDetails

            _entities = new MicroAccountsEntities1();

            var data7 = _entities.tbl_SalesDetails.ToList();

            foreach (var item in data7)
            {
                _entities.tbl_SalesDetails.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_SalesMaster
            _entities = new MicroAccountsEntities1();

            var data8 = _entities.tbl_SalesMaster.ToList();

            foreach (var item in data8)
            {
                _entities.tbl_SalesMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_StockItemDetails
            _entities = new MicroAccountsEntities1();

            var data9 = _entities.tbl_StockItemDetails.ToList();

            foreach (var item in data9)
            {
                _entities.tbl_StockItemDetails.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_ItemMaster
            _entities = new MicroAccountsEntities1();

            var data10 = _entities.tbl_ItemMaster.ToList();

            foreach (var item in data10)
            {
                _entities.tbl_ItemMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_CategoryMaster
            _entities = new MicroAccountsEntities1();

            var data11 = _entities.tbl_CategoryMaster.ToList();

            foreach (var item in data11)
            {
                _entities.tbl_CategoryMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_LedgerDetails
            _entities = new MicroAccountsEntities1();

            var data12 = _entities.tbl_LedgerDetails.ToList();

            foreach (var item in data12)
            {
                _entities.tbl_LedgerDetails.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_AccLedger
            _entities = new MicroAccountsEntities1();

            var data13 = _entities.tbl_AccLedger.ToList();

            foreach (var item in data13)
            {
                _entities.tbl_AccLedger.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_AccGroup
            _entities = new MicroAccountsEntities1();

            var data14 = _entities.tbl_AccGroup.ToList();

            foreach (var item in data14)
            {
                _entities.tbl_AccGroup.Remove(item);
                _entities.SaveChanges();
            }
            #endregion
        }
        public void BjAdipur()  //Xml ma data banava mate
        {
            string str = Properties.Settings.Default.MicroAccountsConnectionString;

            cnn = new SqlConnection(str);

            cnn.Open();

            #region DailyRates
            string         strSQL = "Select * from DailyRates";
            SqlDataAdapter dt     = new SqlDataAdapter(strSQL, cnn);

            DataSet ds = new DataSet();

            dt.Fill(ds, "DailyRates");
            ds.WriteXml(File.OpenWrite(@"Data\DailyRates.xml"));

            #endregion

            #region tbl_AccGroup
            strSQL = "Select * from tbl_AccGroup";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_AccGroup");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_AccGroup.xml"));

            #endregion

            #region tbl_AccLedger
            strSQL = "Select * from tbl_AccLedger";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_AccLedger");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_AccLedger.xml"));

            cnn.Close();
            #endregion

            #region tbl_CategoryMaster
            strSQL = "Select * from tbl_CategoryMaster";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_CategoryMaster");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_CategoryMaster.xml"));

            cnn.Close();
            #endregion

            #region tbl_Entry
            strSQL = "Select * from tbl_Entry";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_AccLedger");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_Entry.xml"));

            cnn.Close();
            #endregion

            #region tbl_EntryDetails
            strSQL = "Select * from tbl_EntryDetails";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_EntryDetails");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_EntryDetails.xml"));

            cnn.Close();
            #endregion

            #region tbl_ItemMaster
            strSQL = "Select * from tbl_ItemMaster";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_ItemMaster");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_ItemMaster.xml"));

            cnn.Close();
            #endregion

            #region tbl_LedgerDetails
            strSQL = "Select * from tbl_LedgerDetails";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_LedgerDetails");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_LedgerDetails.xml"));

            cnn.Close();
            #endregion

            #region tbl_PurchaseDetail
            strSQL = "Select * from tbl_PurchaseDetail";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_PurchaseDetail");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_PurchaseDetail.xml"));

            cnn.Close();
            #endregion

            #region tbl_PurchaseMaster
            strSQL = "Select * from tbl_PurchaseMaster";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_PurchaseMaster");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_PurchaseMaster.xml"));

            cnn.Close();
            #endregion

            #region tbl_SalesDetails
            strSQL = "Select * from tbl_SalesDetails";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_SalesDetails");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_SalesDetails.xml"));

            cnn.Close();
            #endregion

            #region tbl_SalesMaster
            strSQL = "Select * from tbl_SalesMaster";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_SalesMaster");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_SalesMaster.xml"));

            cnn.Close();
            #endregion

            #region tbl_StockItemDetails
            strSQL = "Select * from tbl_StockItemDetails";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_StockItemDetails");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_StockItemDetails.xml"));

            cnn.Close();
            #endregion

            #region tbl_TransactionMaster
            strSQL = "Select * from tbl_TransactionMaster";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_TransactionMaster");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_TransactionMaster.xml"));

            cnn.Close();
            #endregion

            #region tbl_UserLogiln
            strSQL = "Select * from tbl_UserLogiln";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_UserLogiln");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_UserLogiln.xml"));

            cnn.Close();
            #endregion

            #region tbl_UserProfile
            strSQL = "Select * from tbl_UserProfile";
            dt     = new SqlDataAdapter(strSQL, cnn);

            ds = new DataSet();

            dt.Fill(ds, "tbl_UserProfile");
            ds.WriteXml(File.OpenWrite(@"Data\tbl_UserProfile.xml"));

            cnn.Close();
            #endregion

            //Delete Data----------------------------------------------------------------

            #region DailyRates
            //Delete Data From dataBase
            _entities = new MicroAccountsEntities1();

            var data = _entities.DailyRates.ToList();

            foreach (var item in data)
            {
                _entities.DailyRates.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_TransactionMaster
            //Delete Data From dataBase
            _entities = new MicroAccountsEntities1();

            var data1 = _entities.tbl_TransactionMaster.ToList();

            foreach (var item in data1)
            {
                _entities.tbl_TransactionMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_EntryDetails
            //Delete Data From dataBase
            _entities = new MicroAccountsEntities1();

            var data2 = _entities.tbl_EntryDetails.ToList();

            foreach (var item in data2)
            {
                _entities.tbl_EntryDetails.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_Entry
            //Delete Data From dataBase
            _entities = new MicroAccountsEntities1();

            var data3 = _entities.tbl_Entry.ToList();

            foreach (var item in data3)
            {
                _entities.tbl_Entry.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_PurchaseDetail
            _entities = new MicroAccountsEntities1();

            var data4 = _entities.tbl_PurchaseDetail.ToList();

            foreach (var item in data4)
            {
                _entities.tbl_PurchaseDetail.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_PurchaseMaster
            _entities = new MicroAccountsEntities1();

            var data6 = _entities.tbl_PurchaseMaster.ToList();

            foreach (var item in data6)
            {
                _entities.tbl_PurchaseMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_SalesDetails

            _entities = new MicroAccountsEntities1();

            var data7 = _entities.tbl_SalesDetails.ToList();

            foreach (var item in data7)
            {
                _entities.tbl_SalesDetails.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_SalesMaster
            _entities = new MicroAccountsEntities1();

            var data8 = _entities.tbl_SalesMaster.ToList();

            foreach (var item in data8)
            {
                _entities.tbl_SalesMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_StockItemDetails
            _entities = new MicroAccountsEntities1();

            var data9 = _entities.tbl_StockItemDetails.ToList();

            foreach (var item in data9)
            {
                _entities.tbl_StockItemDetails.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_ItemMaster
            _entities = new MicroAccountsEntities1();

            var data10 = _entities.tbl_ItemMaster.ToList();

            foreach (var item in data10)
            {
                _entities.tbl_ItemMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_CategoryMaster
            _entities = new MicroAccountsEntities1();

            var data11 = _entities.tbl_CategoryMaster.ToList();

            foreach (var item in data11)
            {
                _entities.tbl_CategoryMaster.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_LedgerDetails
            _entities = new MicroAccountsEntities1();

            var data12 = _entities.tbl_LedgerDetails.ToList();

            foreach (var item in data12)
            {
                _entities.tbl_LedgerDetails.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_AccLedger
            _entities = new MicroAccountsEntities1();

            var data13 = _entities.tbl_AccLedger.ToList();

            foreach (var item in data13)
            {
                _entities.tbl_AccLedger.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            #region tbl_AccGroup
            _entities = new MicroAccountsEntities1();

            var data14 = _entities.tbl_AccGroup.ToList();

            foreach (var item in data14)
            {
                _entities.tbl_AccGroup.Remove(item);
                _entities.SaveChanges();
            }
            #endregion

            //#region tbl_UserLogiln
            //_entities = new MicroAccountsEntities1();

            //var data15 = _entities.tbl_UserLogiln.ToList();

            //foreach (var item in data15)
            //{
            //    _entities.tbl_UserLogiln.Remove(item);
            //    _entities.SaveChanges();
            //}
            //#endregion

            //#region tbl_UserProfile
            //_entities = new MicroAccountsEntities1();

            //var data16 = _entities.tbl_UserLogiln.ToList();

            //foreach (var item in data16)
            //{
            //    _entities.tbl_UserLogiln.Remove(item);
            //    _entities.SaveChanges();
            //}
            //#endregion
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtLedgerName.Text == string.Empty && txtNotes.Text == string.Empty && txtOpeningBal.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtLedgerName, "Enter all details.");
                    txtLedgerName.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter all details.";
                }
                else if (txtLedgerName.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtLedgerName, "Enter ledger-name");
                    txtLedgerName.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter ledger-name.";
                }
                else if (txtOpeningBal.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtOpeningBal, "Enter opening balance.");
                    txtOpeningBal.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter opening balance.";
                }
                else
                {
                    if (btnCreate.Text == "Create")
                    {
                        _entities = new MicroAccountsEntities1();

                        var gId       = Convert.ToInt32(cmbParentGroup.SelectedValue);
                        var checkData = _entities.tbl_AccLedger.Where(x => x.ledgerName == txtLedgerName.Text.Trim().ToString() && x.groupId == gId).FirstOrDefault();

                        if (checkData != null)
                        {
                            MessageBox.Show("Ledger already Exists. Cannot create ledger with this name");
                            return;
                        }


                        tbl_AccLedger accLedgerData = new tbl_AccLedger();
                        accLedgerData.ledgerName = txtLedgerName.Text.Trim().ToString();
                        accLedgerData.groupId    = Convert.ToInt32(cmbParentGroup.SelectedValue);
                        accLedgerData.opBalance  = Convert.ToDecimal(txtOpeningBal.Text);

                        if (cmbDRCR.SelectedItem.ToString() == "Dr")
                        {
                            accLedgerData.opBalanceDC = "D";
                        }
                        else
                        {
                            accLedgerData.opBalanceDC = "C";
                        }

                        accLedgerData.notes = txtNotes.Text.Trim().ToString();

                        if (chkBankOrCash.Checked)
                        {
                            accLedgerData.type = 1;
                        }
                        else
                        {
                            accLedgerData.type = 0;
                        }
                        accLedgerData.createdDate = DateTime.Now;
                        _entities.tbl_AccLedger.Add(accLedgerData);
                        _entities.SaveChanges();

                        tbl_LedgerDetails ledgerDetails = new tbl_LedgerDetails();

                        if (txtAddress.Text.Trim() == string.Empty)
                        {
                            ledgerDetails.address = "--";
                        }
                        else
                        {
                            ledgerDetails.address = txtAddress.Text.Trim().ToString();
                        }
                        if (txtContact.Text == string.Empty)
                        {
                            ledgerDetails.contact = 0;
                        }
                        else
                        {
                            ledgerDetails.contact = Convert.ToDecimal(txtOpeningBal.Text);
                        }

                        ledgerDetails.ledgerId    = _entities.tbl_AccLedger.Where(x => x.ledgerName == txtLedgerName.Text && x.groupId == accLedgerData.groupId).FirstOrDefault().Id;
                        ledgerDetails.createdDate = DateTime.Now;
                        ledgerDetails.updateDate  = DateTime.Now;

                        _entities.tbl_LedgerDetails.Add(ledgerDetails);
                        _entities.SaveChanges();

                        MessageBox.Show("Record Added Successfully");
                    }
                    else
                    {
                        //Update Code

                        _entities = new MicroAccountsEntities1();

                        var data = _entities.tbl_AccLedger.Where(x => x.Id == ledgerId).FirstOrDefault();

                        data.ledgerName = txtLedgerName.Text.Trim().ToString();
                        data.groupId    = Convert.ToInt32(cmbParentGroup.SelectedValue);
                        data.opBalance  = Convert.ToDecimal(txtOpeningBal.Text);

                        if (cmbDRCR.SelectedItem.ToString() == "Dr")
                        {
                            data.opBalanceDC = "D";
                        }
                        else
                        {
                            data.opBalanceDC = "C";
                        }

                        data.notes       = txtNotes.Text.Trim().ToString();
                        data.updatedDate = DateTime.Now;

                        _entities.SaveChanges();

                        var dataLedgerDetails = _entities.tbl_LedgerDetails.Where(x => x.ledgerId == ledgerId).FirstOrDefault();

                        dataLedgerDetails.address    = txtAddress.Text.Trim().ToString();
                        dataLedgerDetails.contact    = Convert.ToDecimal(txtContact.Text.Trim());
                        dataLedgerDetails.ledgerId   = _entities.tbl_AccLedger.Where(x => x.ledgerName == txtLedgerName.Text && x.groupId == data.groupId).FirstOrDefault().Id;
                        dataLedgerDetails.updateDate = DateTime.Now;

                        _entities.SaveChanges();

                        MessageBox.Show("Record Updated Successfully");
                        SupplierDetails ss = new SupplierDetails();
                        ss.dataGridBind();
                    }
                    bindComboBox();
                    clearTextBox();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something went wrong. Contact your system administrator");
            }
        }
Example #23
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                bool check = ValidateEmail();
                EncryptionDecription enc;

                if (txtEmail.Text == string.Empty && txtF_name.Text == string.Empty && txtL_name.Text == string.Empty && txtUserName.Text == string.Empty && txtMobileNo.Text == string.Empty && txtNewPass.Text == string.Empty && txtConfirmPass.Text == string.Empty)
                {
                    panel3.Visible = true;
                    lblError.Text  = "Enter all details.";
                    txtEmail.Focus();
                }

                else if (!check)
                {
                    panel3.Visible = true;
                    lblError.Text  = txtEmail.Text + " is Invalid Email Address";
                    txtEmail.Focus();
                }
                else if (txtEmail.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtEmail, "Enter Email Address");
                    txtEmail.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Email Address.";
                }
                else if (txtF_name.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtF_name, "Enter First Name");
                    txtF_name.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter First Name.";
                }
                else if (txtL_name.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtL_name, "Enter Last Name");
                    txtL_name.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Last Name.";
                }
                else if (txtUserName.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtUserName, "Enter User Name");
                    txtMobileNo.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter User Name.";
                }

                else if (txtMobileNo.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtMobileNo, "Enter Mobile Number");
                    txtMobileNo.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Mobile Number.";
                }

                else if (txtNewPass.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtNewPass, "Enter Password");
                    txtNewPass.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Password.";
                }
                else if (txtConfirmPass.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtConfirmPass, "Re-enter Password");
                    txtConfirmPass.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Re-enter Password.";
                }
                else if (txtConfirmPass.Text != txtNewPass.Text)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtConfirmPass, "Re-enter Password");
                    txtConfirmPass.Clear();
                    txtConfirmPass.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Password and Confirm Password does not match.";
                }

                else
                {
                    if (btnRegister.Text == "Register")
                    {
                        _entities = new MicroAccountsEntities1();

                        tbl_UserProfile userProfile = new tbl_UserProfile();

                        userProfile.email       = txtEmail.Text.Trim().ToString();
                        userProfile.firstName   = txtF_name.Text.Trim().ToString();
                        userProfile.lastName    = txtL_name.Text.Trim().ToString();
                        userProfile.mobile      = Convert.ToInt64(txtMobileNo.Text.Trim().ToString());
                        userProfile.createdDate = DateTime.Now;
                        userProfile.updateDate  = DateTime.Now;

                        _entities.tbl_UserProfile.Add(userProfile);
                        _entities.SaveChanges();

                        _entities = new MicroAccountsEntities1();
                        tbl_UserLogiln userlogin = new tbl_UserLogiln();
                        userlogin.loginId = txtUserName.Text.Trim().ToString();

                        //encryption of password by calling method of the class called EncryptionDecryption
                        enc = new EncryptionDecription();

                        //  var encPass = enc.Encrypt(txtNewPass.Text.Trim().ToString(), "sblw-3hn8-sqoy19");

                        // var encPass = enc.Encrypt(txtNewPass.Text.Trim().ToString());

                        userlogin.password    = txtNewPass.Text.Trim().ToString();
                        userlogin.userId      = _entities.tbl_UserProfile.Where(x => x.firstName == txtF_name.Text && x.email == txtEmail.Text).FirstOrDefault().userId;
                        userlogin.createdDate = DateTime.Now;
                        userlogin.updateDate  = DateTime.Now;

                        _entities.tbl_UserLogiln.Add(userlogin);
                        _entities.SaveChanges();

                        DataGridSource();
                        MessageBox.Show("Register SuccessFull!");
                    }
                    else
                    {
                        _entities = new MicroAccountsEntities1();
                        enc       = new EncryptionDecription();

                        var uId          = Convert.ToInt32(hiddenUID.Text);
                        var dataToUpdate = _entities.tbl_UserProfile.Where(x => x.userId == uId).FirstOrDefault();

                        dataToUpdate.firstName  = txtF_name.Text.Trim().ToString();
                        dataToUpdate.lastName   = txtL_name.Text.Trim().ToString();
                        dataToUpdate.email      = txtEmail.Text.Trim().ToString();
                        dataToUpdate.mobile     = Convert.ToDecimal(txtMobileNo.Text.Trim());
                        dataToUpdate.updateDate = DateTime.Now;

                        foreach (var item in dataToUpdate.tbl_UserLogiln)
                        {
                            item.loginId = txtUserName.Text.Trim().ToString();
                            //  item.password = enc.Encrypt(txtNewPass.Text.ToString(), "sblw-3hn8-sqoy19");
                            item.password   = enc.Encrypt(txtNewPass.Text.ToString());
                            item.updateDate = DateTime.Now;

                            _entities.SaveChanges();
                        }

                        _entities.SaveChanges();
                        DataGridSource();
                        MessageBox.Show("Updated SuccessFull!");
                    }

                    ClearTextBox();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something went wrong. Contact your system administrator");
            }
        }
Example #24
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            byte[] pic = null;
            try
            {
                if (CaptureBox.Image != null)
                {
                    MemoryStream stream = new MemoryStream();
                    CaptureBox.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    pic = stream.ToArray();
                }

                if (txtWeight.Text == string.Empty && txtMelting.Text == string.Empty && txtQty.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtWeight, "Enter all details.");
                    txtWeight.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter all details.";
                }
                else if (txtWeight.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtWeight, "Enter weight.");
                    txtWeight.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter weight.";
                }
                else if (txtQty.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtQty, "Enter qty.");
                    txtQty.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter qty.";
                }
                else if (txtMelting.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtMelting, "Enter melting.");
                    txtMelting.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter melting.";
                }

                //else if (CaptureBox.Image == null)
                //{
                //    errorProvider1.Clear();
                //    errorProvider1.SetError(CaptureBox, "Select Image.");
                //    CaptureBox.Focus();
                //    panel3.Visible = true;
                //    lblError.Text = "Select Image.";
                //}
                else
                {
                    if (btnCreate.Text == "Create")
                    {
                        //insert Code

                        _entities = new MicroAccountsEntities1();

                        tbl_ItemMaster itemMaster = new tbl_ItemMaster();
                        //itemMaster.categoryId = Convert.ToInt32(cmbItemCategory.SelectedValue);
                        itemMaster.categoryId  = Convert.ToInt32(cmbItemCategory.SelectedValue);
                        itemMaster.photo       = pic;
                        itemMaster.itemCode    = lblItemCode.Text;
                        itemMaster.createdDate = DateTime.Now;

                        _entities.tbl_ItemMaster.Add(itemMaster);
                        _entities.SaveChanges();

                        tbl_StockItemDetails stockDetail = new tbl_StockItemDetails();
                        stockDetail.weight = Convert.ToDecimal(txtWeight.Text);

                        if (cmbKarat.SelectedIndex > 0)
                        {
                            stockDetail.carret = Convert.ToDecimal(cmbKarat.Text);
                        }
                        else
                        {
                            stockDetail.carret = 0;
                        }

                        stockDetail.qty         = Convert.ToDecimal(txtQty.Text);
                        stockDetail.unit        = cmbUnit.Text.ToString();
                        stockDetail.melting     = Convert.ToDecimal(txtMelting.Text);
                        stockDetail.remarks     = txtRemarks.Text.Trim().ToString();
                        stockDetail.itemId      = _entities.tbl_ItemMaster.OrderByDescending(x => x.id).FirstOrDefault().id;
                        stockDetail.createdDate = DateTime.Now;
                        stockDetail.upadtedDate = DateTime.Now;

                        _entities.tbl_StockItemDetails.Add(stockDetail);
                        _entities.SaveChanges();

                        MessageBox.Show("Record Successfully Saved!");
                    }
                    else
                    {
                        //Update Code
                        _entities = new MicroAccountsEntities1();

                        var itemData = (from a in _entities.tbl_ItemMaster
                                        join b in _entities.tbl_StockItemDetails on a.id equals b.itemId
                                        where a.id == itemIDGlobal
                                        select new { a, b }).FirstOrDefault();

                        itemData.a.categoryId = Convert.ToInt32(cmbItemCategory.SelectedValue);
                        itemData.a.photo      = pic;
                        itemData.a.itemCode   = lblItemCode.Text;
                        itemData.a.updateDate = DateTime.Now;

                        itemData.b.weight = Convert.ToDecimal(txtWeight.Text);
                        if (cmbKarat.SelectedIndex > 0)
                        {
                            itemData.b.carret = Convert.ToDecimal(cmbKarat.Text);
                        }
                        else
                        {
                            itemData.b.carret = 0;
                        }
                        itemData.b.qty     = Convert.ToDecimal(txtQty.Text);
                        itemData.b.unit    = cmbUnit.Text.ToString();
                        itemData.b.melting = Convert.ToDecimal(txtMelting.Text);
                        itemData.b.remarks = txtRemarks.Text.Trim().ToString();

                        itemData.b.upadtedDate = DateTime.Now;

                        _entities.SaveChanges();

                        MessageBox.Show("Record Successfully Updated!");
                    }
                    clear();
                }
            }
            catch (Exception x)
            {
                MessageBox.Show("Something went wrong. Contact your system administrator");
            }
        }